alpine 3.8
format weakness #10

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, and note that sprintf variations do not always 0-terminate.

File Name:

gmp/src/gmp-6.1.2/printf/snprntffuns.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"


#if ! HAVE_VSNPRINTF
#define vsnprintf  __gmp_replacement_vsnprintf
#endif


/* glibc 2.0.x vsnprintf returns either -1 or size-1 for an overflow, with
   no indication how big the output would have been.  It's necessary to
   re-run to determine that size.

   "size-1" would mean success from a C99 vsnprintf, and the re-run is
   unnecessary in this case, but we don't bother to try to detect what sort
   of vsnprintf we've got.  size-1 should occur rarely in normal
   circumstances.

   vsnprintf might trash it's given ap (it does for instance in glibc 2.1.3
   on powerpc), so copy it in case we need to use it to probe for the size
   output that would have been produced.  Note there's no need to preserve
   it for our callers, just for ourselves.  */

static int
gmp_snprintf_format (struct gmp_snprintf_t *d, const char *fmt,
                     va_list orig_ap)
{
  int      ret, step, alloc, avail;
  va_list  ap;
  char     *p;
 

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.