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;
|
continue;
|
||||||
}
|
}
|
||||||
if (isdigit(*group) == 0) {
|
if (isdigit(*group) == 0) {
|
||||||
struct group *grp = getgrnam(group);
|
long clen = sysconf(_SC_GETGR_R_SIZE_MAX);
|
||||||
if (grp == NULL) {
|
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);
|
SNDERR("The field ipc_gid must be a valid group (create group %s)", group);
|
||||||
free(group);
|
free(buffer);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
rec->ipc_gid = grp->gr_gid;
|
rec->ipc_gid = pgrp->gr_gid;
|
||||||
|
free(buffer);
|
||||||
} else {
|
} else {
|
||||||
rec->ipc_gid = strtol(group, &endp, 10);
|
rec->ipc_gid = strtol(group, &endp, 10);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue