alsa/0046-snd_pcm_direct_parse_open_conf-use-thread-safe-getgr.patch

42 lines
1.3 KiB
Diff
Raw Normal View History

From 2cfc8b9b44a8e493c41b3d63d5a00b306a18a5ed Mon Sep 17 00:00:00 2001
From: Jerome Forissier <jerome@taodyne.com>
Date: Wed, 30 Jan 2013 16:22:17 +0100
Subject: [PATCH 46/50] snd_pcm_direct_parse_open_conf(): use thread-safe
getgrnam_r()
Fixes a thread safety issue with snd_pcm_open().
Signed-off-by: Jerome Forissier <jerome@taodyne.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
src/pcm/pcm_direct.c | 15 +++++++++++----
1 file changed, 11 insertions(+), 4 deletions(-)
--- a/src/pcm/pcm_direct.c
+++ b/src/pcm/pcm_direct.c
@@ -1629,13 +1629,20 @@ int snd_pcm_direct_parse_open_conf(snd_c
continue;
}
if (isdigit(*group) == 0) {
- struct group *grp = getgrnam(group);
- if (grp == NULL) {
+ long clen = sysconf(_SC_GETGR_R_SIZE_MAX);
+ size_t len = (clen == -1) ? 1024 : (size_t)clen;
+ struct group grp, *pgrp;
+ char *buffer = (char *)malloc(len);
+ if (buffer == NULL)
+ return -ENOMEM;
+ int st = getgrnam_r(group, &grp, buffer, len, &pgrp);
+ if (st != 0) {
SNDERR("The field ipc_gid must be a valid group (create group %s)", group);
- free(group);
+ free(buffer);
return -EINVAL;
}
- rec->ipc_gid = grp->gr_gid;
+ rec->ipc_gid = pgrp->gr_gid;
+ free(buffer);
} else {
rec->ipc_gid = strtol(group, &endp, 10);
}