centos 7
format weakness #12


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 Centos 7 format weakness.

        if (!(r = ca_malloc(size)))
                return NULL;

        memcpy(r, p, size);
        return r;

char *ca_sprintf_malloc(const char *format, ...) {
        size_t  size = 100;
        char *c = NULL;


        for(;;) {
                int r;
                va_list ap;


                if (!(c = ca_new(char, size)))
                        return NULL;

                va_start(ap, format);
                r = vsnprintf(c, size, format, ap);

                c[size-1] = 0;

                if (r > -1 && (size_t) r < size)
                        return c;

                if (r > -1)    /* glibc 2.1 */
                        size = (size_t) r+1;
                else           /* glibc 2.0 */
                        size *= 2;

char *ca_strndup(const char *s, size_t n) {
        size_t n_avail;
        char *p;

        if (!s)
                return NULL;

        if (memchr(s, '\0', n)) {
                n_avail = strlen(s);
                if (n_avail > n) 

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.