alpine 3.9
format weakness #11

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/Keil/UtestPlatform.cpp

Context:

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

 
       t = t * 10;

        return t;
    }

    long (*GetPlatformSpecificTimeInMillis)() = TimeInMillisImplementation;

    static const char* TimeStringImplementation()
    {
        time_t tm = 0;//time(NULL); // todo
        return ctime(&tm);
    }

    const char* (*GetPlatformSpecificTimeString)() = TimeStringImplementation;

    int PlatformSpecificAtoI(const char* str)
    {
        return atoi(str);
    }

    /* The ARMCC compiler will compile this function with C++ linkage, unless
     * we specifically tell it to use C linkage again, in the function definiton.
     */
    extern int (*PlatformSpecificVSNprintf)(char *str, size_t size, const char* format, va_list args) = vsnprintf;

    static PlatformSpecificFile PlatformSpecificFOpenImplementation(const char* filename, const char* flag)
    {
       return 0;
    }

    static void PlatformSpecificFPutsImplementation(const char* str, PlatformSpecificFile file)
    {
        printf("%s", str);
    }

    static void PlatformSpecificFCloseImplementation(PlatformSpecificFile file)
    {
    }

    static void PlatformSpecificFlushImplementation()
    {
    }

    PlatformSpecificFile (*PlatformSpecificFOpen)(const char*, const char*) = PlatformSpecificFOpenImplementation;
    void (*PlatformSpecificFPuts)(const char*, PlatformSpecificFile) = PlatformSpecificFPutsImplementation;
    void (*PlatformSpecificFClose)(PlatformSpecificFile) = PlatformSpecificFCloseImplementation;

    int (*PlatformSpecificPutchar)(int) = putchar;
    void (*PlatformSpecificFlush)() = PlatformSpecificFlushImplementation; 

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.