mirror of
https://github.com/alsa-project/alsa-lib.git
synced 2025-11-05 13:30:00 -05:00
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>
This commit is contained in:
parent
1629e2fbf3
commit
2cfc8b9b44
1 changed files with 11 additions and 4 deletions
|
|
@ -1629,13 +1629,20 @@ int snd_pcm_direct_parse_open_conf(snd_config_t *root, snd_config_t *conf,
|
|||
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);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue