[alsa-devel] [PATCH] ALSA: usb-audio: Fix out-of-bound error

Jaejoong Kim climbbb.kim at gmail.com
Thu Nov 16 01:42:38 CET 2017


Hi, Takashi

2017-11-15 18:16 GMT+09:00 Takashi Iwai <tiwai at suse.de>:
> On Wed, 15 Nov 2017 09:57:56 +0100,
> Jaejoong Kim wrote:
>>
>> diff --git a/sound/usb/mixer.c b/sound/usb/mixer.c
>> index e630813..5a83c2c 100644
>> --- a/sound/usb/mixer.c
>> +++ b/sound/usb/mixer.c
>> @@ -204,7 +204,8 @@ static int snd_usb_copy_string_desc(struct mixer_build
>> *state,
>>                                     int index, char *buf, int maxlen)
>>  {
>>         int len = usb_string(state->chip->dev, index, buf, maxlen - 1);
>> -       buf[len] = 0;
>> +       if (len > 0)
>> +               buf[len] = 0;
>>         return len;
>
> I'd rather put an explicit error bail-out, i.e.
>
> diff --git a/sound/usb/mixer.c b/sound/usb/mixer.c
> index 91bc8f18791e..296a63a9d09c 100644
> --- a/sound/usb/mixer.c
> +++ b/sound/usb/mixer.c
> @@ -204,6 +204,10 @@ static int snd_usb_copy_string_desc(struct mixer_build *state,
>                                     int index, char *buf, int maxlen)
>  {
>         int len = usb_string(state->chip->dev, index, buf, maxlen - 1);
> +
> +       if (len < 0)
> +               return len;
> +
>         buf[len] = 0;
>         return len;
>  }

OK.

I will resend v2 patch with your suggestion.

>
>
> thanks,
>
> Takashi

thanks,
Jaejoong


More information about the Alsa-devel mailing list