Skip to contentSkip to conversation

ALSA: oss-mixer - use strlcpy() instead strcpy()

PATCH In review Dan Carpenter 2 participants 2 messages Oct 4, 2011

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

PATCH 1/1 ALSA: oss-mixer - use strlcpy() instead strcpy()

This is mostly a static checker fix more than anything else. We're copying from a 64 char buffer into a 44 char buffer.

The 64 character buffer is str[] in snd_mixer_oss_build_test_all(). The call tree is:

	snd_mixer_oss_build_test_all()
	-> snd_mixer_oss_build_test()
	   -> snd_mixer_oss_build_test().

We never actually do fill str[] buffer all the way to 64 characters. The longest string is:

	sprintf(str, "%s Playback Switch", ptr->name);

ptr->name is a 32 character buffer so 32 plus 16 characters for " Playback Switch" still puts us over the 44 limit from "id.name".

Most likely ptr->name never gets filled to the limit, but we can't really change the size of that buffer so lets just use strlcpy() here and be safe.

sound/core/oss/mixer_oss.c +1 -1
index 27ac611..18297f7 100644
@@ -500,7 +500,7 @@ static struct snd_kcontrol *snd_mixer_oss_test_id(struct snd_mixer_oss *mixer, c
 	
 	memset(&id, 0, sizeof(id));
 	id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
-	strcpy(id.name, name);
+	strlcpy(id.name, name, sizeof(id.name));
 	id.index = index;
 	return snd_ctl_find_id(card, &id);
 }
#1 lore raw

At Tue, 4 Oct 2011 09:29:39 +0300,

Quoted 13 lines · Dan Carpenter

This is mostly a static checker fix more than anything else. We're copying from a 64 char buffer into a 44 char buffer.

The 64 character buffer is str[] in snd_mixer_oss_build_test_all(). The call tree is:

	snd_mixer_oss_build_test_all()
	-> snd_mixer_oss_build_test()
	   -> snd_mixer_oss_build_test().

We never actually do fill str[] buffer all the way to 64 characters. The longest string is:

	sprintf(str, "%s Playback Switch", ptr->name);
Quoted 8 lines

ptr->name is a 32 character buffer so 32 plus 16 characters for " Playback Switch" still puts us over the 44 limit from "id.name".

Most likely ptr->name never gets filled to the limit, but we can't really change the size of that buffer so lets just use strlcpy() here and be safe.

Applied now. Thanks.

Takashi

Quoted 14 lines
sound/core/oss/mixer_oss.c +1 -1
index 27ac611..18297f7 100644
@@ -500,7 +500,7 @@ static struct snd_kcontrol *snd_mixer_oss_test_id(struct snd_mixer_oss *mixer, c
 
 	memset(&id, 0, sizeof(id));
 	id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
-	strcpy(id.name, name);
+	strlcpy(id.name, name, sizeof(id.name));
 	id.index = index;
 	return snd_ctl_find_id(card, &id);
 }