alpine 3.6
buffer weakness #209

5

Weakness Breakdown


Definition:

Buffer overflows are one of the most well-known software vulnerabilities. Even though most developers know what buffer overflows are, attacks against the vulnerabilities are common in both legacy and newer applications. A classic buffer overflow exploit begins with the attacker sending data to a program, which it then stores in an undersized stack buffer. Besides stack buffer overflows, other kinds of buffer overflows include heap overflows, off-by-one errors and many others. Learn more about buffer overflows on OWASP attack index.

Warning code(s):

Easily used incorrectly.

File Name:

v4l-utils/src/v4l-utils-1.12.5/lib/libdvbv5/descriptors.c

Context:

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

 uint32_t dvb_bcd(uint32_t bcd)
{
	uint32_t ret = 0, mult = 1;
	while (bcd) {
		ret += (bcd & 0x0f) * mult;
		bcd >>=4;
		mult *= 10;
	}
	return ret;
}

void dvb_hexdump(struct dvb_v5_fe_parms *parms, const char *prefix, const unsigned char *data, int length)
{
	char ascii[17];
	char hex[50];
	int i, j = 0;

	if (!data)
		return;
	hex[0] = '\0';
	for (i = 0; i < length; i++) {
		char t[4];

		snprintf (t, sizeof(t), "%02x ", (unsigned int) data[i]);
		strncat (hex, t, sizeof(hex) - 1);
		if (data[i] > 31 && data[i] < 128 )
			ascii[j] = data[i];
		else
			ascii[j] = '.';
		j++;
		if (j == 8)
			strncat(hex, " ", sizeof(hex) - 1);
		if (j == 16) {
			ascii[j] = '\0';
			dvb_loginfo("%s%s  %s", prefix, hex, ascii);
			j = 0;
			hex[0] = '\0';
		}
	}
	if (j > 0 && j < 16) {
		char spaces[50];
		for (i = 0; i < sizeof(spaces) - 1 - strlen(hex); i++)
			spaces[i] = ' ';
		spaces[i] = '\0';
		ascii[j] = '\0';
		dvb_loginfo("%s%s %s %s", prefix, hex, spaces, ascii);
	}
} 

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.