fedora 24
format weakness #54

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.

File Name:

avahi-0.6.32/avahi-core/dns-spin-test.c

Context:

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

 /* Regression test for Avahi bug #84.
 * This program tests whether the avahi_dns_packet_consume_name function
 * returns (rather than spinning forever). For a function as simple as
 * avahi_dns_packet_consume_name, we assume that 1 second of CPU time ≈ forever
 */

#ifdef HAVE_CONFIG_H
# include <config.h>
#endif

#include <string.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <sys/time.h>

#include "dns.h"

#define MAX_CPU_SECONDS 1

#define TEST_NAME "dns-spin-test"

static void fail(const char *fmt, ...) __attribute__((format(printf, 1, 2), noreturn));
static void unresolved(const char *fmt, ...) __attribute__((format(printf, 1, 2), noreturn));
static void stdlib_fail(const char *msg) __attribute__((noreturn));
static void handle(int sig) __attribute__((noreturn));

void stdlib_fail(const char *msg) {
    perror(msg);

    printf("UNRESOLVED: " TEST_NAME " (stdlib failure)\n");

    exit(77);
}

void unresolved(const char *fmt, ...) {
    va_list ap;

    printf("UNRESOLVED: " TEST_NAME ": ");
    va_start(ap, fmt);
    vprintf(fmt, ap);
    va_end(ap);
    printf("\n");

    exit(77);
}

void fail(const char *fmt, ...) {
    va_list ap; 

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.