centos 7
format weakness #14

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:

libcanberra-0.30/src/proplist.c

Context:

The highlighted line of code below is the trigger point of this particular Centos 7 format weakness.

         int ret;
        char *k;
        ca_prop *prop;
        size_t size = 100;
        unsigned h;

        ca_return_val_if_fail(p, CA_ERROR_INVALID);
        ca_return_val_if_fail(key, CA_ERROR_INVALID);
        ca_return_val_if_fail(format, CA_ERROR_INVALID);

        if (!(k = ca_strdup(key)))
                return CA_ERROR_OOM;

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

                if (!(prop = ca_malloc(CA_ALIGN(sizeof(ca_prop)) + size))) {
                        ca_free(k);
                        return CA_ERROR_OOM;
                }


                va_start(ap, format);
                r = vsnprintf(CA_PROP_DATA(prop), size, format, ap);
                va_end(ap);

                ((char*) CA_PROP_DATA(prop))[size-1] = 0;

                if (r > -1 && (size_t) r < size) {
                        prop->nbytes = (size_t) r+1;
                        break;
                }

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

                ca_free(prop);
        }

        prop->key = k;

        ca_mutex_lock(p->mutex);

        if ((ret = _unset(p, key)) < 0) {
                ca_free(prop);
                ca_free(k);
                goto finish; 

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.