alpine 3.8
integer weakness #10


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 Alpine 3.8 integer weakness.

 #include <stdlib.h>
#include <unistd.h>
#include <ftdi.h>

void ftdi_fatal (struct ftdi_context *ftdi, char *str)
    fprintf (stderr, "%s: %s\n",
             str, ftdi_get_error_string (ftdi));
    exit (1);

int main(int argc, char **argv)
    struct ftdi_context *ftdi;
    int i, t;
    unsigned char data;
    int delay = 100000; /* 100 thousand microseconds: 1 tenth of a second */

    while ((t = getopt (argc, argv, "d:")) != -1)
        switch (t)
            case 'd':
                delay = atoi (optarg);

    if ((ftdi = ftdi_new()) == 0)
        fprintf(stderr, "ftdi_bew failed\n");
        return EXIT_FAILURE;

    if (ftdi_usb_open(ftdi, 0x0403, 0x6001) < 0)
        ftdi_fatal (ftdi, "Can't open ftdi device");

    if (ftdi_set_bitmode(ftdi, 0xFF, BITMODE_BITBANG) < 0)
        ftdi_fatal (ftdi, "Can't enable bitbang");

    for (i=optind; i < argc ; i++)
        sscanf (argv[i], "%x", &t);
        data = t;
        if (ftdi_write_data(ftdi, &data, 1) < 0)
            fprintf(stderr,"write failed for 0x%x: %s\n",
                    data, ftdi_get_error_string(ftdi));

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.