fedora 25
format weakness #22

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:

magicpoint-1.13a/missing/snprintf.c

Context:

The highlighted line of code below is the trigger point of this particular Fedora 25 format weakness.

 	fp = _findiop();
	fp->_file = -1;
	fp->_cnt = n;
	fp->_base = fp->_ptr = (unsigned char *)string;
#ifdef HAVE__SETBUFEND
	_setbufend(fp, string + n);
#else
	fp->_bufsiz = n;
#endif
	fp->_flag = _IOWRT;
	ret = _doprnt(fmt, ap, fp);
	if (fp->_flag & _IOERR) {
		string[n - 1] = '\0';
		return n;
	}
	*fp->_ptr = '\0';
	fp->_base = fp->_ptr = 0;
	fp->_cnt = 0;
	fp->_flag = 0;
	return ret;
}


int
snprintf(char *string, int n, const char *fmt, ...)
{
	int ret;
	va_list ap;

	va_start(ap, fmt);
	ret = vsnprintf(string, n, fmt, ap);
	va_end(ap);
	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.