From: Takashi Iwai <tiwai@suse.de>
To: alsa-devel@alsa-project.org
Subject: [PATCH lib 1/5] namehint: Fix invalid list access in snd_device_name_hint()
Date: Thu, 30 Apr 2015 15:06:14 +0200 [thread overview]
Message-ID: <1430399178-15173-2-git-send-email-tiwai@suse.de> (raw)
In-Reply-To: <1430399178-15173-1-git-send-email-tiwai@suse.de>
snd_device_name_hint() tries to free the allocated list at the error
path via snd_device_name_free_hint(). But snd_device_name_free_hint()
expects a list terminated by NULL while snd_device_name_hint() doesn't
add it. Adding it may again result in an error and thus isn't
guaranteed to work. Hence we can't add NULL at the error path.
Instead, now the code always allocates one entry more, and zero-clears
the newly allocated beforehand to guarantee the NULL termination.
Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
src/control/namehint.c | 21 ++++++++++-----------
1 file changed, 10 insertions(+), 11 deletions(-)
diff --git a/src/control/namehint.c b/src/control/namehint.c
index 28975a400b75..66de634d3550 100644
--- a/src/control/namehint.c
+++ b/src/control/namehint.c
@@ -52,10 +52,11 @@ static int hint_list_add(struct hint_list *list,
{
char *x;
- if (list->count == list->allocated) {
+ if (list->count + 1 >= list->allocated) {
char **n = realloc(list->list, (list->allocated + 10) * sizeof(char *));
if (n == NULL)
return -ENOMEM;
+ memset(n + list->allocated, 0, 10 * sizeof(*n));
list->allocated += 10;
list->list = n;
}
@@ -620,18 +621,16 @@ int snd_device_name_hint(int card, const char *iface, void ***hints)
}
err = 0;
__error:
- if (err < 0) {
+ /* add an empty entry if nothing has been added yet; the caller
+ * expects non-NULL return
+ */
+ if (!err && !list.list)
+ err = hint_list_add(&list, NULL, NULL);
+ if (err < 0)
snd_device_name_free_hint((void **)list.list);
- if (list.cardname)
- free(list.cardname);
- } else {
- err = hint_list_add(&list, NULL, NULL);
- if (err < 0)
- goto __error;
+ else
*hints = (void **)list.list;
- if (list.cardname)
- free(list.cardname);
- }
+ free(list.cardname);
if (local_config_rw)
snd_config_delete(local_config_rw);
if (local_config)
--
2.3.6
next prev parent reply other threads:[~2015-04-30 13:06 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-04-30 13:06 [PATCH lib 0/5] alsa-lib namehint fixes Takashi Iwai
2015-04-30 13:06 ` Takashi Iwai [this message]
2015-04-30 13:06 ` [PATCH lib 2/5] namehint: Fix the listing without device number Takashi Iwai
2015-04-30 13:06 ` [PATCH lib 3/5] namehint: Fix bad free with invalid iface name Takashi Iwai
2015-04-30 13:06 ` [PATCH lib 4/5] Allow hint for ctl, hwdep, timer and seq Takashi Iwai
2015-04-30 13:06 ` [PATCH lib 5/5] conf: Add hint descriptions to ctl, hwdep, seq and timer devices Takashi Iwai
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=1430399178-15173-2-git-send-email-tiwai@suse.de \
--to=tiwai@suse.de \
--cc=alsa-devel@alsa-project.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