Alsa-Devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Takashi Iwai <tiwai@suse.de>
To: Jaejoong Kim <climbbb.kim@gmail.com>
Cc: Jaroslav Kysela <perex@perex.cz>,
	stable@vger.kernel.org, alsa-devel@alsa-project.org
Subject: Re: [PATCH] ALSA: usb-audio: Fix out-of-bound error
Date: Wed, 15 Nov 2017 10:16:18 +0100	[thread overview]
Message-ID: <s5hefozc36l.wl-tiwai@suse.de> (raw)
In-Reply-To: <CAL6iAaJTKi+S4izrrbjdceuqHMHOwqDEYO2Mx9-B4Z8F7GrohQ@mail.gmail.com>

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;
 }


thanks,

Takashi

  reply	other threads:[~2017-11-15  9:16 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-15  8:07 [PATCH] ALSA: usb-audio: Fix out-of-bound error Jaejoong Kim
2017-11-15  8:57 ` Jaejoong Kim
2017-11-15  9:16   ` Takashi Iwai [this message]
2017-11-16  0:42     ` Jaejoong Kim

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=s5hefozc36l.wl-tiwai@suse.de \
    --to=tiwai@suse.de \
    --cc=alsa-devel@alsa-project.org \
    --cc=climbbb.kim@gmail.com \
    --cc=perex@perex.cz \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox