alpine 3.8
format weakness #6

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

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

File Name:

gmp/src/gmp-6.1.2/printf/printffuns.c

Context:

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

   * the GNU General Public License as published by the Free Software
    Foundation; either version 2 of the License, or (at your option) any
    later version.

or both in parallel, as here.

The GNU MP Library is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
for more details.

You should have received copies of the GNU General Public License and the
GNU Lesser General Public License along with the GNU MP Library.  If not,
see https://www.gnu.org/licenses/.  */

#include <stdarg.h>
#include <stdio.h>
#include <string.h>

#include "gmp.h"
#include "gmp-impl.h"

/* SunOS 4 stdio.h doesn't provide a prototype for this */
#if ! HAVE_DECL_VFPRINTF
int vfprintf (FILE *, const char *, va_list);
#endif


static int
gmp_fprintf_memory (FILE *fp, const char *str, size_t len)
{
  return fwrite (str, 1, len, fp);
}

/* 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; 

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.