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.
If format strings can be influenced by an attacker, they can be exploited, and note that sprintf variations do not always 0-terminate.
libcanberra-0.30/src/malloc.c
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;
ca_assert(format);
for(;;) {
int r;
va_list ap;
ca_free(c);
if (!(c = ca_new(char, size)))
return NULL;
va_start(ap, format);
r = vsnprintf(c, size, format, ap);
va_end(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;
}
}
#ifndef HAVE_STRNDUP
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)