alpine 3.8
format weakness #7


Weakness Breakdown


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):

If format strings can be influenced by an attacker, they can be exploited.

File Name:



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

/* glibc putc is a function, at least when it's in multi-threaded mode or
   some such, so fwrite chunks instead of making many calls. */
static int
gmp_fprintf_reps (FILE *fp, int c, int reps)
  char  buf[256];
  int   i, piece, ret;
  ASSERT (reps >= 0);

  memset (buf, c, MIN (reps, sizeof (buf)));
  for (i = reps; i > 0; i -= sizeof (buf))
      piece = MIN (i, sizeof (buf));
      ret = fwrite (buf, 1, piece, fp);
      if (ret == -1)
        return ret;
      ASSERT (ret == piece);

  return reps;

const struct doprnt_funs_t  __gmp_fprintf_funs = {
  (doprnt_format_t) vfprintf,
  (doprnt_memory_t) gmp_fprintf_memory,
  (doprnt_reps_t)   gmp_fprintf_reps,

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.