alpine 3.9
format weakness #14


Weakness Breakdown


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:



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

     /* The TI c2000 platform does not have Posix support and thus lacks struct timespec.
     * Also, clock() always returns 0 in the simulator. Hence we work with struct tm.tm_hour
     * This has two consequences:
     *   (1) We need to sum up the part in order to get an "elapsed since" time value,
     *       rather than just using tm_sec.
     *   (2) There is a possibility of overflow, since we stop at the hour
     *   (3) Resolution is 1 s, even though we return ms.
    time_t t        = time((time_t*)0);
    struct tm * ptm = gmtime(&t);
    long result = (long)
        ((ptm->tm_sec + ptm->tm_min * (time_t)60 + ptm->tm_hour * (time_t)3600) * (time_t)1000);
    return result;

static const char* TimeStringImplementation()
    time_t tm = time(NULL);
    return ctime(&tm);

long (*GetPlatformSpecificTimeInMillis)() = C2000TimeInMillis;
const char* (*GetPlatformSpecificTimeString)() = TimeStringImplementation;

extern int vsnprintf(char*, size_t, const char*, va_list); // not std::vsnprintf()

extern int (*PlatformSpecificVSNprintf)(char *, size_t, const char*, va_list) = vsnprintf;

PlatformSpecificFile C2000FOpen(const char* filename, const char* flag)
    return fopen(filename, flag);

static void C2000FPuts(const char* str, PlatformSpecificFile file)
   fputs(str, (FILE*)file);

static void C2000FClose(PlatformSpecificFile file)

PlatformSpecificFile (*PlatformSpecificFOpen)(const char* filename, const char* flag) = C2000FOpen;
void (*PlatformSpecificFPuts)(const char* str, PlatformSpecificFile file) = C2000FPuts;
void (*PlatformSpecificFClose)(PlatformSpecificFile file) = C2000FClose;

static int CL2000Putchar(int c)

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.