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

File Name:



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

	tmpfilename = NULL;

	if ((safe_f = fdopen (fd, "w+b")) == NULL) {
		close (fd);
		return NULL;
	/* setvbuf(f,NULL,_IOFBF,4*BUFSIZ); */
	return safe_f;

#elif defined(HAVE_TMPFILE)
#define safe_tmpfile tmpfile
#error Neither mkstemp() nor tmpfile() is available on this platform.

#if (__STDC_VERSION__ + 0) < 199901
#undef restrict	/* force it! */
#define restrict

vsnprintf (char *restrict buf, size_t len,
		const char *restrict fmt, va_list args)
	int actual;
	int nread;
	size_t cnt = 0;
	FILE *fp;

	if ((buf == NULL) || (len < 1))
		return -1;

	buf[0] = '\0';	/* in case the caller does not check the return code! */

	if ((fp = safe_tmpfile ()) == NULL)
		return -1;
	if ((fp == NULL) && ((fp = safe_tmpfile ()) == NULL))
		return -1;
	rewind (fp);
	actual = vfprintf (fp, fmt, args);
	rewind (fp); 

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.