[polypaudio-commits] r804 - /trunk/src/polyp/channelmap.c

svnmailer-noreply at 0pointer.de svnmailer-noreply at 0pointer.de
Wed Apr 26 09:07:08 PDT 2006


Author: lennart
Date: Wed Apr 26 18:07:05 2006
New Revision: 804

URL: http://0pointer.de/cgi-bin/viewcvs.cgi?rev=804&root=polypaudio&view=rev
Log:
* make a validity check of parsed channel maps before rteurning theme
* don't overwrite the return buffer unless the parsed channel map is known to be valid

Modified:
    trunk/src/polyp/channelmap.c

Modified: trunk/src/polyp/channelmap.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/src/polyp/channelmap.c?rev=804&root=polypaudio&r1=803&r2=804&view=diff
==============================================================================
--- trunk/src/polyp/channelmap.c (original)
+++ trunk/src/polyp/channelmap.c Wed Apr 26 18:07:05 2006
@@ -214,42 +214,48 @@
     return s;
 }
 
-pa_channel_map *pa_channel_map_parse(pa_channel_map *map, const char *s) {
+pa_channel_map *pa_channel_map_parse(pa_channel_map *rmap, const char *s) {
     const char *state;
+    pa_channel_map map;
     char *p;
     
-    assert(map);
+    assert(rmap);
     assert(s);
 
-    memset(map, 0, sizeof(pa_channel_map));
+    memset(&map, 0, sizeof(map));
 
     if (strcmp(s, "stereo") == 0) {
-        map->channels = 2;
-        map->map[0] = PA_CHANNEL_POSITION_LEFT;
-        map->map[1] = PA_CHANNEL_POSITION_RIGHT;
-        return map;
+        map.channels = 2;
+        map.map[0] = PA_CHANNEL_POSITION_LEFT;
+        map.map[1] = PA_CHANNEL_POSITION_RIGHT;
+        goto finish;
     }
 
     state = NULL;
-    map->channels = 0;
+    map.channels = 0;
     
     while ((p = pa_split(s, ",", &state))) {
+
+        if (map.channels >= PA_CHANNELS_MAX) {
+            pa_xfree(p);
+            return NULL;
+        }
         
         /* Some special aliases */
         if (strcmp(p, "left") == 0)
-            map->map[map->channels++] = PA_CHANNEL_POSITION_LEFT;
+            map.map[map.channels++] = PA_CHANNEL_POSITION_LEFT;
         else if (strcmp(p, "right") == 0)
-            map->map[map->channels++] = PA_CHANNEL_POSITION_RIGHT;
+            map.map[map.channels++] = PA_CHANNEL_POSITION_RIGHT;
         else if (strcmp(p, "center") == 0)
-            map->map[map->channels++] = PA_CHANNEL_POSITION_CENTER;
+            map.map[map.channels++] = PA_CHANNEL_POSITION_CENTER;
         else if (strcmp(p, "subwoofer") == 0)
-            map->map[map->channels++] = PA_CHANNEL_POSITION_SUBWOOFER;
+            map.map[map.channels++] = PA_CHANNEL_POSITION_SUBWOOFER;
         else {
             pa_channel_position_t i;
             
             for (i = 0; i < PA_CHANNEL_POSITION_MAX; i++)
                 if (strcmp(p, table[i]) == 0) {
-                    map->map[map->channels++] = i;
+                    map.map[map.channels++] = i;
                     break;
                 }
             
@@ -262,12 +268,14 @@
         pa_xfree(p);
     }
 
-    if (!map->channels)
+finish:
+    
+    if (!pa_channel_map_valid(&map))
         return NULL;
-
-    return map;
-}
-
+    
+    *rmap = map;
+    return rmap;
+}
 
 int pa_channel_map_valid(const pa_channel_map *map) {
     unsigned c;




More information about the pulseaudio-commits mailing list