alpine 3.9
integer weakness #5

2

Weakness Breakdown


Definition:

An integer overflow occurs when the answer to an arithmetic operation exceeds the maximum size of the integer type used to store it. The resulting value will appear to have wrapped around the maximum value and started again at the minimum value. This would look like a clock that represents 13:00 by pointing at 1:00. An attacker can use an integer overflow during a buffer length calculation, which results in the allocated buffer being too small to hold the data copied into it, thus causing a buffer overflow.

Warning code(s):

Unless checked, the resulting number can exceed the expected range.

File Name:

alsa-lib/src/alsa-lib-1.1.8/src/topology/pcm.c

Context:

The highlighted line of code below is the trigger point of this particular Alpine 3.9 integer weakness.

 	if (!elem)
		return -ENOMEM;

	link = elem->link;
	link->size = elem->size;

	tplg_dbg(" CC: %s\n", elem->id);

	snd_config_for_each(i, next, cfg) {

		n = snd_config_iterator_entry(i);
		if (snd_config_get_id(n, &id) < 0)
			continue;

		/* skip comments */
		if (strcmp(id, "comment") == 0)
			continue;
		if (id[0] == '#')
			continue;

		if (strcmp(id, "id") == 0) {
			if (snd_config_get_string(n, &val) < 0)
				return -EINVAL;

			link->id = atoi(val);
			tplg_dbg("\t%s: %d\n", id, link->id);
			continue;
		}

	}

	return 0;
}

static int get_audio_hw_format(const char *val)
{
	if (!strlen(val))
		return -EINVAL;

	if (!strcmp(val, "I2S"))
		return SND_SOC_DAI_FORMAT_I2S;

	if (!strcmp(val, "RIGHT_J"))
		return SND_SOC_DAI_FORMAT_RIGHT_J;

	if (!strcmp(val, "LEFT_J"))
		return SND_SOC_DAI_FORMAT_LEFT_J;

	if (!strcmp(val, "DSP_A"))
		return SND_SOC_DAI_FORMAT_DSP_A; 

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.