alpine 3.9
format weakness #12

4

Weakness Breakdown


Definition:

A format string exploit occurs when the data of an input string is evaluated as a command by the program. This class of attacks is very similar to buffer overflows since an attacker could execute code, read the stack or cause new behaviors that compromise security. Learn more about format string attacks on OWASP attack index.

Warning code(s):

If format strings can be influenced by an attacker, they can be exploited, and note that sprintf variations do not always 0-terminate.

File Name:

cpputest/src/cpputest-3.8/src/Platforms/Symbian/UtestPlatform.cpp

Context:

The highlighted line of code below is the trigger point of this particular Alpine 3.9 format weakness.

 }

static long TimeInMillisImplementation() {
    struct timeval tv;
    struct timezone tz;
    ::gettimeofday(&tv, &tz);
    return (tv.tv_sec * 1000) + (long)(tv.tv_usec * 0.001);
}

long (*GetPlatformSpecificTimeInMillis)() = TimeInMillisImplementation;

TestOutput::WorkingEnvironment PlatformSpecificGetWorkingEnvironment()
{
    return TestOutput::eclipse;
}

static SimpleString TimeStringImplementation() {
    time_t tm = time(NULL);
    return ctime(&tm);
}

SimpleString GetPlatformSpecificTimeString() = TimeStringImplementation;

int PlatformSpecificVSNprintf(char* str, size_t size, const char* format, va_list args) {
    return vsnprintf(str, size, format, args);
}

void PlatformSpecificFlush() {
    fflush(stdout);
}

int PlatformSpecificPutchar(int c) {
    return putchar(c);
}

double PlatformSpecificFabs(double d) {
    return fabs(d);
}

void* PlatformSpecificMalloc(size_t size) {
    return malloc(size);
}

void* PlatformSpecificRealloc (void* memory, size_t size) {
    return realloc(memory, size);
}

void PlatformSpecificFree(void* memory) {
    free(memory);
} 

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.