]> code.delx.au - pulseaudio/commitdiff
core-util: Don't accept random words in pa_parse_boolean()
authorTanu Kaskinen <tanuk@iki.fi>
Wed, 13 Jun 2012 08:15:03 +0000 (11:15 +0300)
committerArun Raghavan <arun.raghavan@collabora.co.uk>
Mon, 3 Jun 2013 19:08:40 +0000 (00:38 +0530)
The old code accepted any word that started with "y", "Y",
"n", "N", "t", "T", "f" or "F". Fix this by having
a whitelist of full strings instead of checking just the
first letter.

src/pulsecore/core-util.c

index 96cf4e837bee9725b0f3f15017ac420ce1f62887..da8266b38b6d4456afe3e4d60e4e076cbea9253d 100644 (file)
@@ -937,9 +937,11 @@ int pa_parse_boolean(const char *v) {
     pa_assert(v);
 
     /* First we check language independent */
-    if (pa_streq(v, "1") || v[0] == 'y' || v[0] == 'Y' || v[0] == 't' || v[0] == 'T' || !strcasecmp(v, "on"))
+    if (pa_streq(v, "1") || !strcasecmp(v, "y") || !strcasecmp(v, "t")
+            || !strcasecmp(v, "yes") || !strcasecmp(v, "true") || !strcasecmp(v, "on"))
         return 1;
-    else if (pa_streq(v, "0") || v[0] == 'n' || v[0] == 'N' || v[0] == 'f' || v[0] == 'F' || !strcasecmp(v, "off"))
+    else if (pa_streq(v, "0") || !strcasecmp(v, "n") || !strcasecmp(v, "f")
+                 || !strcasecmp(v, "no") || !strcasecmp(v, "false") || !strcasecmp(v, "off"))
         return 0;
 
 #ifdef HAVE_LANGINFO_H