[vlc-commits] PulseAudio: do not assume sysconf() returns a finite value

Rémi Denis-Courmont git at videolan.org
Mon Aug 13 21:10:24 CEST 2012


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Mon Aug 13 22:09:50 2012 +0300| [191f071695d272e99de17787d33e773606656430] | committer: Rémi Denis-Courmont

PulseAudio: do not assume sysconf() returns a finite value

(Here -1 means infinity.)

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=191f071695d272e99de17787d33e773606656430
---

 modules/audio_output/vlcpulse.c |   33 +++++++++++++++++++++------------
 1 file changed, 21 insertions(+), 12 deletions(-)

diff --git a/modules/audio_output/vlcpulse.c b/modules/audio_output/vlcpulse.c
index 7926f6e..a9fedcf 100644
--- a/modules/audio_output/vlcpulse.c
+++ b/modules/audio_output/vlcpulse.c
@@ -117,18 +117,27 @@ pa_context *vlc_pa_connect (vlc_object_t *obj, pa_threaded_mainloop **mlp)
         //pa_proplist_sets (props, PA_PROP_APPLICATION_PROCESS_BINARY,
         //                  PACKAGE_NAME);
 
-        char buf[sysconf (_SC_GETPW_R_SIZE_MAX)];
-        struct passwd pwbuf, *pw;
-
-        if (getpwuid_r (getuid (), &pwbuf, buf, sizeof (buf), &pw) == 0
-         && pw != NULL)
-            pa_proplist_sets (props, PA_PROP_APPLICATION_PROCESS_USER,
-                              pw->pw_name);
-
-        char hostname[sysconf (_SC_HOST_NAME_MAX)];
-        if (gethostname (hostname, sizeof (hostname)) == 0)
-            pa_proplist_sets (props, PA_PROP_APPLICATION_PROCESS_HOST,
-                              hostname);
+        for (size_t max = sysconf (_SC_GETPW_R_SIZE_MAX), len = max % 1024 + 1024;
+             len < max; len += 1024)
+        {
+            struct passwd pwbuf, *pw;
+            char buf[len];
+
+            if (getpwuid_r (getuid (), &pwbuf, buf, sizeof (buf), &pw) == 0
+             && pw != NULL)
+                pa_proplist_sets (props, PA_PROP_APPLICATION_PROCESS_USER,
+                                  pw->pw_name);
+        }
+
+        for (size_t max = sysconf (_SC_HOST_NAME_MAX), len = max % 1024 + 1024;
+             len < max; len += 1024)
+        {
+            char hostname[len];
+
+            if (gethostname (hostname, sizeof (hostname)) == 0)
+                pa_proplist_sets (props, PA_PROP_APPLICATION_PROCESS_HOST,
+                                  hostname);
+        }
 
         const char *session = getenv ("XDG_SESSION_COOKIE");
         if (session != NULL)



More information about the vlc-commits mailing list