alpine 3.8
integer weakness #16


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.

   if (!f)
      perror ("fopen");
      exit (EXIT_FAILURE);
  if (fprintf (f, "%d\n", seed) < 0)
      perror ("fprintf");
      exit (EXIT_FAILURE);
  if (fclose (f) < 0)
      perror ("fclose");
      exit (EXIT_FAILURE);
  g_print ("seed: %d\n", seed);

main (int argc, char **argv)
  int seed;

  if (argc > 1)
    seed = atoi (argv[1]);
      seed = time (NULL);
      write_seed (seed);
  g_print ("the last tested image is saved to the file \"pixbuf-random-image\"\n\n");

  g_random_set_seed (seed);

#define GIF_HEADER 'G', 'I', 'F', '8', '9', 'a'
#define PNG_HEADER 0x89, 'P', 'N', 'G', 0x0d, 0x0a, 0x1a, 0x0a
#define TIFF1_HEADER 'M', 'M', 0x00, 0x2a
#define TIFF2_HEADER 'I', 'I', 0x2a, 0x00
#define JPEG_HEADER 0xFF, 0xd8
#define PNM_HEADER 'P', '6'
#define XBM_HEADER '#', 'd', 'e', 'f', 'i', 'n', 'e', ' '  
#define BMP_HEADER 'B', 'M'  
#define XPM_HEADER '/', '*', ' ', 'X', 'P', 'M', ' ', '*', '/'
#define RAS_HEADER 0x59, 0xA6, 0x6A, 0x95

#define TEST_RANDOM(header, n_img)				\
do {								\
	static guchar h[] = { header };				\ 

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.