fedora 25
integer weakness #23


Weakness Breakdown


An integer overflow occurs when the answer to an arithmetic operation exceeds the maximum size of the integer type used to store it. The resulting value will appear to have wrapped around the maximum value and started again at the minimum value. This would look like a clock that represents 13:00 by pointing at 1:00. An attacker can use an integer overflow during a buffer length calculation, which results in the allocated buffer being too small to hold the data copied into it, thus causing a buffer overflow.

Warning code(s):

Unless checked, the resulting number can exceed the expected range.

File Name:



The highlighted line of code below is the trigger point of this particular Fedora 25 integer weakness.


static void die(const char *tag)

/* this is a very dumb "head" command that only copies from stdin to
 * stdout, but keeps embedded NUL characters.
 * It can accept a -N option, where N gives the number of lines.
 * If not given, defaults to 10.
 * Further or malformatted arguments are SILENTLY ignored.
 * Diagnosis: read/write errors are detected, printed with perror and
 * let this program exit(EXIT_FAILURE).

int main(int argc, char **argv) {
    int lines = 10, c;

    if (argc >= 2 && argv[1][0] == '-')
	lines = atoi(&argv[1][1]);

    while(lines && (c = getchar()) != EOF) { /* RATS: ignore */
	if (putchar(c) == EOF) die("stdout");
	if (c == '\n') lines--;
    if (ferror(stdin)) die("stdin");
    if (fflush(stdout) == EOF) die("stdout");
    exit (EXIT_SUCCESS);

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.