alpine 3.7
format weakness #9

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:

gawk/src/gawk-4.2.0/missing_d/snprintf.c

Context:

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

 	}
	else if ((size_t) actual < len)
		len = actual;
	else
		--len;
	while (cnt < len && (nread = fread (buf + cnt, 1, len - cnt, fp)) > 0)
		cnt += nread;
	buf[cnt] = '\0';
#ifdef SNPRINTF_REENTRANT
	fclose (fp);
	if (tmpfilename != NULL) {
		unlink(tmpfilename);
		free(tmpfilename);
		tmpfilename = NULL;
	}
#endif
	if (cnt < len)
		return -1;

	return actual;
}

int
#if defined(HAVE_STDARG_H) && defined(__STDC__) && __STDC__
snprintf (char *restrict buf, size_t len, const char *restrict fmt, ...)
#else
snprintf (va_alist)
     va_dcl
#endif
{
	int rv;
	va_list args;

#if defined(HAVE_STDARG_H) && defined(__STDC__) && __STDC__
	va_start (args, fmt);
#else
	char *buf;
	size_t len;
	char *fmt;

	va_start (args);
	buf = va_arg (args, char *);
	len = va_arg (args, size_t);
	fmt = va_arg (args, char *);
#endif
	rv = vsnprintf (buf, len, fmt, args);
	va_end (args);
	return rv;
} 

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.