alpine 3.6
format weakness #3

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:

abook/src/abook-0.6.1/misc.c

Context:

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

 
/* varargs declarations: */

#ifdef HAVE_STDARG_H
#	define MY_VA_LOCAL_DECL   va_list ap
#	define MY_VA_START(f)     va_start(ap, f)
#	define MY_VA_SHIFT(v,t)   v = va_arg(ap, t)
#	define MY_VA_END          va_end(ap)
#else
#	error HAVE_STDARG_H not defined
#endif

char *
strdup_printf (const char *format, ... )
{
	MY_VA_LOCAL_DECL;
	size_t size = 100;
	char *buffer = xmalloc (size);

	assert(format != NULL);

	for(;;) {
		int n;
		MY_VA_START(format);
		n = vsnprintf (buffer, size,
				format, ap);
		MY_VA_END;

		if (n > -1 && n < size)
			return buffer;

		if (n > -1)
			size = n + 1;
		else
			size *= 2;

		buffer = xrealloc(buffer, size);
	}
}


char*
strconcat (const char *str, ...)
{
	unsigned long l;
	MY_VA_LOCAL_DECL;
	char *s, *concat;

	assert(str != NULL);
 

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.