alpine 3.8
integer weakness #24

2

Weakness Breakdown


Definition:

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:

fftw/src/fftw-3.3.6-pl2/mpi/testsched.c

Context:

The highlighted line of code below is the trigger point of this particular Alpine 3.8 integer weakness.

      else
	  width = 3;

     for (pe = 0; pe < npes; ++pe) {
	  printf("pe %*d schedule:", width, pe);
	  for (i = 0; sched[pe][i] != -1; ++i)
	       printf("  %*d",width,sched[pe][i]);
	  printf("\n");
     }
}

int main(int argc, char **argv)
{
     int **sched;
     int npes = -1, sortpe = -1, steps, i;

     if (argc >= 2) {
	  npes = atoi(argv[1]);
	  if (npes <= 0) {
	       fprintf(stderr,"npes must be positive!");
	       return 1;
	  }
     }
     if (argc >= 3) {
	  sortpe = atoi(argv[2]);
	  if (sortpe < 0 || sortpe >= npes) {
	       fprintf(stderr,"sortpe must be between 0 and npes-1.\n");
	       return 1;
	  }
     }

     if (npes != -1) {
	  printf("Computing schedule for npes = %d:\n",npes);
	  sched = make_comm_schedule(npes);
	  if (!sched) {
	       fprintf(stderr,"Out of memory!");
	       return 6;
	  }
	  
	  if (steps = check_comm_schedule(sched,npes))
	       printf("schedule OK (takes %d steps to complete).\n", steps);
	  else
	       printf("schedule not OK.\n");

	  print_comm_schedule(sched, npes);
	  
	  if (sortpe != -1) {
	       printf("\nRe-creating schedule for pe = %d...\n", sortpe);
	       int *sched1 = (int*) malloc(sizeof(int) * npes);
	       for (i = 0; i < npes; ++i) sched1[i] = -1; 

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.