alpine 3.8
format weakness #21

4

Weakness Breakdown


Definition:

A format string exploit occurs when the data of an input string is evaluated as a command by the program. This class of attacks is very similar to buffer overflows since an attacker could execute code, read the stack or cause new behaviors that compromise security. Learn more about format string attacks on OWASP attack index.

Warning code(s):

Potential format string problem.

File Name:

gmp/src/gmp-6.1.2/tests/misc/t-printf.c

Context:

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

       case 'A':
	/* The exact value of the exponent isn't guaranteed in glibc, and it
	   and gmp_printf do slightly different things, so don't compare
	   directly. */
	goto done;
      case 'F':
	if (p > fmt_orig && *(p-1) == '.')
	  goto done;  /* don't test the "all digits" cases */
	/* discard 'F' type */
	break;
      case 'Z':
	/* transmute */
	*q++ = 'l';
	break;
      default:
	*q++ = *p;
	break;
      }
    }
  *q = '\0';

  want_len = strlen (want);
  ASSERT_ALWAYS (want_len < sizeof(got));

  got_len = vsprintf (got, fmt, ap);

  if (got_len != want_len || strcmp (got, want) != 0)
    {
      printf ("wanted data doesn't match plain vsprintf\n");
      printf ("  fmt      |%s|\n", fmt);
      printf ("  got      |%s|\n", got);
      printf ("  want     |%s|\n", want);
      printf ("  got_len  %d\n", got_len);
      printf ("  want_len %d\n", want_len);
      abort ();
    }

 done:
  (*__gmp_free_func) (fmt, fmtsize);
}

void
check_vsprintf (const char *want, const char *fmt, va_list ap)
{
  char  got[MAX_OUTPUT];
  int   got_len, want_len;

  want_len = strlen (want);
  got_len = gmp_vsprintf (got, fmt, ap);
 

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.