alpine 3.6
integer weakness #2

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:

argp-standalone/src/argp-standalone-1.3/argp-test.c

Context:

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

     printf ("KEY %s: %s\n", buf, arg);
  else
    printf ("KEY %s\n", buf);
}

static error_t
parse_opt (int key, char *arg, struct argp_state *state)
{
  struct params *params = state->input;

  switch (key)
    {
    case ARGP_KEY_NO_ARGS:
      printf ("NO ARGS\n");
      break;

    case ARGP_KEY_ARG:
      if (state->arg_num > 0)
	return ARGP_ERR_UNKNOWN; /* Leave it for the sub-arg parser.  */
      printf ("ARG: %s\n", arg);
      break;

    case 'f':
      if (arg)
	params->foonly = atoi (arg);
      else
	params->foonly = params->foonly_default;
      popt (key, arg);
      break;

    case 'p': case 'P': case OPT_PGRP: case 'x': case 'Q':
    case 'r': case OPT_SESS: case 'z':
      popt (key, arg);
      break;

    default:
      return ARGP_ERR_UNKNOWN;
    }
  return 0;
}

static char *
help_filter (int key, const char *text, void *input)
{
  char *new_text;
  struct params *params = input;

  if (key == ARGP_KEY_HELP_POST_DOC && text)
    {
      time_t now = time (0); 

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.