alsa-devel.alsa-project.org archive mirror
 help / color / mirror / Atom feed
From: Jerome Forissier <jerome@taodyne.com>
To: alsa-devel@alsa-project.org
Cc: Jerome Forissier <jerome@taodyne.com>
Subject: [PATCH 2/2] snd_pcm_direct_parse_open_conf(): use thread-safe getgrnam_r()
Date: Wed, 30 Jan 2013 16:22:17 +0100	[thread overview]
Message-ID: <1359559337-15533-3-git-send-email-jerome@taodyne.com> (raw)
In-Reply-To: <1359559337-15533-1-git-send-email-jerome@taodyne.com>

Fixes a thread safety issue with snd_pcm_open().

Signed-off-by: Jerome Forissier <jerome@taodyne.com>
---
 src/pcm/pcm_direct.c | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/src/pcm/pcm_direct.c b/src/pcm/pcm_direct.c
index 6802ecc..38c6c66 100644
--- a/src/pcm/pcm_direct.c
+++ b/src/pcm/pcm_direct.c
@@ -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);
 			}
-- 
1.8.1.2

  parent reply	other threads:[~2013-01-30 15:23 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-01-30 15:22 [PATCH 0/2] Fix thread safety issues Jerome Forissier
2013-01-30 15:22 ` [PATCH 1/2] Make snd_device_name_hint() thread-safe by locking a mutex Jerome Forissier
2013-01-30 15:22 ` Jerome Forissier [this message]
2013-01-30 16:03 ` [PATCH 0/2] Fix thread safety issues Takashi Iwai
2013-01-30 18:13   ` Jérôme Forissier
2013-01-31  8:54     ` Takashi Iwai
2013-01-31  9:48       ` Jérôme Forissier
2013-01-31 10:09         ` Takashi Iwai
2013-01-31 11:38           ` Jaroslav Kysela

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=1359559337-15533-3-git-send-email-jerome@taodyne.com \
    --to=jerome@taodyne.com \
    --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;
as well as URLs for NNTP newsgroup(s).