Skip to contentSkip to conversation

ALSA: usb/mixer: remove bogus cast

PATCH In review Dan Carpenter 2 participants 2 messages Sep 16, 2010

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ALSA: usb/mixer: remove bogus cast

"uinfo->value.enumerated.item" is an unsigned int. If it's negative when we do the comparison:

	if ((int)uinfo->value.enumerated.item >= cval->max)

then we would read past the end of the array on the next line.

I also changed the strcpy() to strlcpy() out of paranoia.

sound/usb/mixer.c +3 -2
index 3ed3901..93c95c5 100644
@@ -1642,9 +1642,10 @@ static int mixer_ctl_selector_info(struct snd_kcontrol *kcontrol, struct snd_ctl
 	uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
 	uinfo->count = 1;
 	uinfo->value.enumerated.items = cval->max;
-	if ((int)uinfo->value.enumerated.item >= cval->max)
+	if (uinfo->value.enumerated.item >= cval->max)
 		uinfo->value.enumerated.item = cval->max - 1;
-	strcpy(uinfo->value.enumerated.name, itemlist[uinfo->value.enumerated.item]);
+	strlcpy(uinfo->value.enumerated.name, itemlist[uinfo->value.enumerated.item],
+		sizeof(uinfo->value.enumerated.name));
 	return 0;
 }
 
#1 lore raw

At Thu, 16 Sep 2010 20:13:47 +0200,

Quoted 5 lines · Dan Carpenter

"uinfo->value.enumerated.item" is an unsigned int. If it's negative when we do the comparison:

	if ((int)uinfo->value.enumerated.item >= cval->max)

then we would read past the end of the array on the next line.

This cast was for the old crappy gcc who spews bogus warnings when compared with signed and unsigned ints. The kernel sets a compile flag for avoiding this since long time ago, so we can get rid of such cast gracefully now, indeed.

Quoted 3 lines

I also changed the strcpy() to strlcpy() out of paranoia.

Applied now. Thanks.

Takashi

Quoted 18 lines
sound/usb/mixer.c +3 -2
index 3ed3901..93c95c5 100644
@@ -1642,9 +1642,10 @@ static int mixer_ctl_selector_info(struct snd_kcontrol *kcontrol, struct snd_ctl
 	uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
 	uinfo->count = 1;
 	uinfo->value.enumerated.items = cval->max;
-	if ((int)uinfo->value.enumerated.item >= cval->max)
+	if (uinfo->value.enumerated.item >= cval->max)
 		uinfo->value.enumerated.item = cval->max - 1;
-	strcpy(uinfo->value.enumerated.name, itemlist[uinfo->value.enumerated.item]);
+	strlcpy(uinfo->value.enumerated.name, itemlist[uinfo->value.enumerated.item],
+		sizeof(uinfo->value.enumerated.name));
 	return 0;
 }