alpine 3.8
tmpfile weakness #7

4

Weakness Breakdown


Definition:

A temporary file weakness occurs when a temporary file that is created and used by a high-privilege process is accidentally shared with a low-privilege process, on account of it being temporary and generated after all security controls have been applied. This allows the low-privilege process to read data from the high-privilege process (information leakage), or worse, influence the high-privilege process by modifying the shared temporary file.

Warning code(s):

Temporary file race condition.

File Name:

cppcheck/src/cppcheck-1.83/test/cfg/generated-cfg-tests-posix.cpp

Context:

The highlighted line of code below is the trigger point of this particular Alpine 3.8 tmpfile weakness.

   // cppcheck-suppress uninitvar
  mkdtemp(x);
}

void test__mktemp__noreturn() {
  int x = 1;
  if (cond) { x=100; result = mktemp(arg1); }
  // cppcheck-suppress shiftTooManyBits
  x = 1 << x;
}

void test__mktemp__useretval() {
  // cppcheck-suppress ignoredReturnValue
  mktemp(arg1);
}

void test__mktemp__leakignore() {
  char *p = malloc(10); *p=0;
  result = mktemp(p);
  // cppcheck-suppress memleak
}

void test__mktemp__arg1__notnull() {
  // cppcheck-suppress nullPointer
  result = mktemp(NULL);
}

void test__mktemp__arg1__notuninit() {
  int x[10];
  // cppcheck-suppress uninitvar
  result = mktemp(x);
}

void test__getcwd__noreturn() {
  int x = 1;
  if (cond) { x=100; getcwd(arg1, arg2); }
  // cppcheck-suppress shiftTooManyBits
  x = 1 << x;
}

void test__getcwd__leakignore() {
  char *p = malloc(10); *p=0;
  getcwd(p, arg2);
  // cppcheck-suppress memleak
}

void test__getcwd__arg1__notuninit() {
  int x;
  // cppcheck-suppress uninitvar
  getcwd(x, arg2); 

The registered trademark Linux® is used pursuant to a sublicense from the Linux Foundation, the exclusive licensee of Linus Torvalds, owner of the mark on a world­wide basis.