fedora 23
format weakness #41

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:

apitrace-7.1/common/os_string.hpp

Context:

The highlighted line of code below is the trigger point of this particular Fedora 23 format weakness.

     /**
     * From a printf-like format string
     */
    static String
    format(const char *format, ...)
#ifdef __GNUC__
    __attribute__ ((format (printf, 1, 2)))
#endif
    {

        va_list args;

        va_start(args, format);

        int length;
        va_list args_copy;
        va_copy(args_copy, args);
#ifdef _WIN32
        /* We need to use _vscprintf to calculate the length as vsnprintf returns -1
         * if the number of characters to write is greater than count.
         */
        length = _vscprintf(format, args_copy);
#else
        char dummy;
        length = vsnprintf(&dummy, sizeof dummy, format, args_copy);
#endif
        va_end(args_copy);

        assert(length >= 0);
        size_t size = length + 1;

        String path(size);

        va_start(args, format);
        vsnprintf(path.buf(), size, format, args);
        va_end(args);

        return path;
    }

    /*
     * Conversion to ordinary C strings.
     */

    const char *str(void) const {
        assert(buffer.back() == 0);
        return &buffer[0];
    }

    operator const char *(void) const { 

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.