[pulseaudio-commits] 11 commits - coverity/model.c src/modules src/pulsecore

Peter Meerwald pmeerw at kemper.freedesktop.org
Tue Mar 7 09:00:32 UTC 2017


 coverity/model.c                        |   18 +++++++++++
 src/modules/raop/module-raop-discover.c |   22 +++++++++++---
 src/modules/raop/raop-client.c          |   49 ++++++++++++++++++--------------
 src/modules/raop/raop-sink.c            |    6 +--
 src/pulsecore/macro.h                   |    9 +++++
 5 files changed, 75 insertions(+), 29 deletions(-)

New commits:
commit 0cb72beaceca1e8e8e3eb330cbaa516912fa6dbd
Author: Peter Meerwald-Stadler <pmeerw at pmeerw.net>
Date:   Wed Mar 1 20:37:06 2017 +0100

    raop: Fix potential NULL dereference
    
    'realm' is mandatory
    
    Signed-off-by: Peter Meerwald-Stadler <pmeerw at pmeerw.net>

diff --git a/src/modules/raop/raop-client.c b/src/modules/raop/raop-client.c
index 9181e81..1bd4c4a 100644
--- a/src/modules/raop/raop-client.c
+++ b/src/modules/raop/raop-client.c
@@ -1259,13 +1259,13 @@ static void rtsp_auth_cb(pa_rtsp_client *rtsp, pa_rtsp_state_t state, pa_rtsp_st
                     pa_xfree(token);
                 }
 
-                if (pa_safe_streq(mth, "Basic")) {
+                if (pa_safe_streq(mth, "Basic") && realm) {
                     rtrim_char(realm, '\"');
 
                     pa_raop_basic_response(DEFAULT_USER_NAME, c->password, &response);
                     ath = pa_sprintf_malloc("Basic %s",
                         response);
-                } else if (pa_safe_streq(mth, "Digest")) {
+                } else if (pa_safe_streq(mth, "Digest") && realm && nonce) {
                     rtrim_char(realm, '\"');
                     rtrim_char(nonce, '\"');
 

commit 233cb4516a6d78cd65beef80ec6b46cd1f6c1aed
Author: Peter Meerwald-Stadler <pmeerw at pmeerw.net>
Date:   Tue Feb 28 08:01:20 2017 +0100

    raop: Fix potential resource leaks
    
    Coverity ID: #1410204, #1410203, #1410202, #1410201, #1410200, #1410199
    
    Signed-off-by: Peter Meerwald-Stadler <pmeerw at pmeerw.net>

diff --git a/src/modules/raop/module-raop-discover.c b/src/modules/raop/module-raop-discover.c
index dc55b9c..9c7ac3c 100644
--- a/src/modules/raop/module-raop-discover.c
+++ b/src/modules/raop/module-raop-discover.c
@@ -177,6 +177,7 @@ static void resolver_cb(
              *  - TCP = only TCP,
              *  - UDP = only UDP,
              *  - TCP,UDP = both supported (UDP should be prefered) */
+            pa_xfree(tp);
             if (pa_str_in_list(value, ",", "UDP"))
                 tp = pa_xstrdup("UDP");
             else if (pa_str_in_list(value, ",", "TCP"))
@@ -190,16 +191,18 @@ static void resolver_cb(
              *  - 2 = FairPlay,
              *  - 3 = MFiSAP,
              *  - 4 = FairPlay SAPv2.5. */
-             if (pa_str_in_list(value, ",", "1"))
-                 et = pa_xstrdup("RSA");
-             else
-                 et = pa_xstrdup("none");
+            pa_xfree(et);
+            if (pa_str_in_list(value, ",", "1"))
+                et = pa_xstrdup("RSA");
+            else
+                et = pa_xstrdup("none");
         } else if (pa_streq(key, "cn")) {
             /* Suported audio codecs:
              *  - 0 = PCM,
              *  - 1 = ALAC,
              *  - 2 = AAC,
              *  - 3 = AAC ELD. */
+            pa_xfree(cn);
             if (pa_str_in_list(value, ",", "1"))
                 cn = pa_xstrdup("ALAC");
             else
@@ -213,12 +216,15 @@ static void resolver_cb(
             /* Requires password ? (true/false) */
         } else if (pa_streq(key, "ch")) {
             /* Number of channels */
+            pa_xfree(ch);
             ch = pa_xstrdup(value);
         } else if (pa_streq(key, "ss")) {
             /* Sample size */
+            pa_xfree(ss);
             ss = pa_xstrdup(value);
         } else if (pa_streq(key, "sr")) {
             /* Sample rate */
+            pa_xfree(sr);
             sr = pa_xstrdup(value);
         }
 

commit 6c35ac7c8f3fecdcc70e6bb44cefd12d93e0fb63
Author: Peter Meerwald-Stadler <pmeerw at pmeerw.net>
Date:   Mon Feb 27 23:43:49 2017 +0100

    raop: Silence unchecked return value warnings
    
    Signed-off-by: Peter Meerwald-Stadler <pmeerw at pmeerw.net>

diff --git a/src/modules/raop/raop-client.c b/src/modules/raop/raop-client.c
index 7901871..9181e81 100644
--- a/src/modules/raop/raop-client.c
+++ b/src/modules/raop/raop-client.c
@@ -1039,9 +1039,9 @@ static void rtsp_stream_cb(pa_rtsp_client *rtsp, pa_rtsp_state_t state, pa_rtsp_
                         if ((pc = strstr(token, "="))) {
                             *pc = 0;
                             if (pa_streq(token, "control_port"))
-                                pa_atou(pc + 1, &cport);
+                                (void) pa_atou(pc + 1, &cport);
                             if (pa_streq(token, "timing_port"))
-                                pa_atou(pc + 1, &tport);
+                                (void) pa_atou(pc + 1, &tport);
                             *pc = '=';
                         }
                         pa_xfree(token);

commit 20960e7cc65f57771de60ca110053cf544eb871a
Author: Peter Meerwald-Stadler <pmeerw at pmeerw.net>
Date:   Mon Feb 27 23:39:38 2017 +0100

    raop: Fix indentation
    
    Signed-off-by: Peter Meerwald-Stadler <pmeerw at pmeerw.net>

diff --git a/src/modules/raop/raop-client.c b/src/modules/raop/raop-client.c
index dfa0f85..7901871 100644
--- a/src/modules/raop/raop-client.c
+++ b/src/modules/raop/raop-client.c
@@ -1037,8 +1037,8 @@ static void rtsp_stream_cb(pa_rtsp_client *rtsp, pa_rtsp_state_t state, pa_rtsp_
                     /* Now parse out the server port component of the response. */
                     while ((token = pa_split(trs, delimiters, &token_state))) {
                         if ((pc = strstr(token, "="))) {
-                        *pc = 0;
-                         if (pa_streq(token, "control_port"))
+                            *pc = 0;
+                            if (pa_streq(token, "control_port"))
                                 pa_atou(pc + 1, &cport);
                             if (pa_streq(token, "timing_port"))
                                 pa_atou(pc + 1, &tport);

commit 94fc8c9ee29c5e67544eb0c05f68f93415388287
Author: Peter Meerwald-Stadler <pmeerw at pmeerw.net>
Date:   Mon Feb 27 23:23:04 2017 +0100

    raop: Fix potential memory leak
    
    Coverity ID: #1410204
    
    Signed-off-by: Peter Meerwald-Stadler <pmeerw at pmeerw.net>

diff --git a/src/modules/raop/module-raop-discover.c b/src/modules/raop/module-raop-discover.c
index c0b4549..dc55b9c 100644
--- a/src/modules/raop/module-raop-discover.c
+++ b/src/modules/raop/module-raop-discover.c
@@ -152,7 +152,7 @@ static void resolver_cb(
 
     if (event != AVAHI_RESOLVER_FOUND) {
         pa_log("Resolving of '%s' failed: %s", name, avahi_strerror(avahi_client_errno(u->client)));
-        goto  finish;
+        goto finish;
     }
 
     if ((nicename = strstr(name, "@"))) {
@@ -235,6 +235,12 @@ static void resolver_cb(
         pa_log("Cannot construct valid device name from '%s'.", dname);
         avahi_free(device);
         pa_xfree(dname);
+        pa_xfree(tp);
+        pa_xfree(et);
+        pa_xfree(cn);
+        pa_xfree(ch);
+        pa_xfree(ss);
+        pa_xfree(sr);
         goto finish;
     }
 

commit 4d7922d0910c2f34b4d172ce6c2bb54089d8cf3a
Author: Peter Meerwald-Stadler <pmeerw at pmeerw.net>
Date:   Wed Feb 22 15:21:00 2017 +0100

    raop: Fix resource leaks
    
    Coverity ID: #1398158, #1398159
    
    Signed-off-by: Peter Meerwald-Stadler <pmeerw at pmeerw.net>

diff --git a/src/modules/raop/raop-client.c b/src/modules/raop/raop-client.c
index 7034094..dfa0f85 100644
--- a/src/modules/raop/raop-client.c
+++ b/src/modules/raop/raop-client.c
@@ -1228,7 +1228,7 @@ static void rtsp_auth_cb(pa_rtsp_client *rtsp, pa_rtsp_state_t state, pa_rtsp_st
             static bool waiting = false;
             const char *current = NULL;
             char space[] = " ";
-            char *token,*ath = NULL;
+            char *token, *ath = NULL;
             char *publ, *wath, *mth, *val;
             char *realm = NULL, *nonce = NULL, *response = NULL;
             char comma[] = ",";
@@ -1265,9 +1265,6 @@ static void rtsp_auth_cb(pa_rtsp_client *rtsp, pa_rtsp_state_t state, pa_rtsp_st
                     pa_raop_basic_response(DEFAULT_USER_NAME, c->password, &response);
                     ath = pa_sprintf_malloc("Basic %s",
                         response);
-
-                    pa_xfree(response);
-                    pa_xfree(realm);
                 } else if (pa_safe_streq(mth, "Digest")) {
                     rtrim_char(realm, '\"');
                     rtrim_char(nonce, '\"');
@@ -1276,17 +1273,18 @@ static void rtsp_auth_cb(pa_rtsp_client *rtsp, pa_rtsp_state_t state, pa_rtsp_st
                     ath = pa_sprintf_malloc("Digest username=\"%s\", realm=\"%s\", nonce=\"%s\", uri=\"*\", response=\"%s\"",
                         DEFAULT_USER_NAME, realm, nonce,
                         response);
-
-                    pa_xfree(response);
-                    pa_xfree(realm);
-                    pa_xfree(nonce);
                 } else {
                     pa_log_error("unsupported authentication method: %s", mth);
+                    pa_xfree(realm);
+                    pa_xfree(nonce);
                     pa_xfree(wath);
                     pa_xfree(mth);
                     goto error;
                 }
 
+                pa_xfree(response);
+                pa_xfree(realm);
+                pa_xfree(nonce);
                 pa_xfree(wath);
                 pa_xfree(mth);
 

commit 4bb25292f808d60cb054a75937d38cd3d36e2560
Author: Peter Meerwald-Stadler <pmeerw at pmeerw.net>
Date:   Wed Feb 22 15:09:02 2017 +0100

    raop: Fix memleak
    
    use local scope for trs variable simplifying cleanup
    Coverity ID: #1398160
    
    Signed-off-by: Peter Meerwald-Stadler <pmeerw at pmeerw.net>

diff --git a/src/modules/raop/raop-client.c b/src/modules/raop/raop-client.c
index 7045772..7034094 100644
--- a/src/modules/raop/raop-client.c
+++ b/src/modules/raop/raop-client.c
@@ -988,14 +988,13 @@ static void rtsp_stream_cb(pa_rtsp_client *rtsp, pa_rtsp_state_t state, pa_rtsp_
             pa_socket_client *sc = NULL;
             uint32_t sport = DEFAULT_UDP_AUDIO_PORT;
             uint32_t cport =0, tport = 0;
-            char *ajs, *trs, *token, *pc;
+            char *ajs, *token, *pc;
             const char *token_state = NULL;
             char delimiters[] = ";";
 
             pa_log_debug("RAOP: SETUP");
 
             ajs = pa_xstrdup(pa_headerlist_gets(headers, "Audio-Jack-Status"));
-            trs = pa_xstrdup(pa_headerlist_gets(headers, "Transport"));
 
             if (ajs) {
                 c->jack_type = JACK_TYPE_ANALOG;
@@ -1032,6 +1031,8 @@ static void rtsp_stream_cb(pa_rtsp_client *rtsp, pa_rtsp_state_t state, pa_rtsp_
                 pa_socket_client_unref(sc);
                 sc = NULL;
             } else if (c->protocol == PA_RAOP_PROTOCOL_UDP) {
+                char *trs = pa_xstrdup(pa_headerlist_gets(headers, "Transport"));
+
                 if (trs) {
                     /* Now parse out the server port component of the response. */
                     while ((token = pa_split(trs, delimiters, &token_state))) {
@@ -1045,6 +1046,7 @@ static void rtsp_stream_cb(pa_rtsp_client *rtsp, pa_rtsp_state_t state, pa_rtsp_
                         }
                         pa_xfree(token);
                     }
+                    pa_xfree(trs);
                 } else {
                     pa_log_warn("\"Transport\" missing in RTSP setup response");
                 }
@@ -1067,7 +1069,6 @@ static void rtsp_stream_cb(pa_rtsp_client *rtsp, pa_rtsp_state_t state, pa_rtsp_
 
             pa_rtsp_record(c->rtsp, &c->seq, &c->rtptime);
 
-            pa_xfree(trs);
             pa_xfree(ajs);
             break;
 

commit 95d850a5ad17bd7672682cb540ed2d0b25ac68ca
Author: Peter Meerwald-Stadler <pmeerw at pmeerw.net>
Date:   Tue Mar 7 08:22:25 2017 +0100

    raop: Fail after search for port number
    
    should also fail if port is 0 after the loop, as suggested by Georg Chini
    
    Signed-off-by: Peter Meerwald-Stadler <pmeerw at pmeerw.net>

diff --git a/src/modules/raop/raop-client.c b/src/modules/raop/raop-client.c
index e39663d..7045772 100644
--- a/src/modules/raop/raop-client.c
+++ b/src/modules/raop/raop-client.c
@@ -811,6 +811,11 @@ static int open_bind_udp_socket(pa_raop_client *c, uint16_t *actual_port) {
         }
     } while (++port > 0);
 
+    if (!port) {
+        pa_log("Could not bind port");
+        goto fail;
+    }
+
     pa_log_debug("Socket bound to port %d (SOCK_DGRAM)", port);
     *actual_port = port;
 

commit df9cda67d2041adad7a43a48435f473eb1143337
Author: Peter Meerwald-Stadler <pmeerw at pmeerw.net>
Date:   Wed Feb 22 15:02:43 2017 +0100

    raop: Fix loop searching for port number
    
    do...while not reachable, loop should try different ports in case EADDRINUSE is returned
    Coverity ID: #1398161
    
    Signed-off-by: Peter Meerwald-Stadler <pmeerw at pmeerw.net>

diff --git a/src/modules/raop/raop-client.c b/src/modules/raop/raop-client.c
index 94342d2..e39663d 100644
--- a/src/modules/raop/raop-client.c
+++ b/src/modules/raop/raop-client.c
@@ -799,13 +799,16 @@ static int open_bind_udp_socket(pa_raop_client *c, uint16_t *actual_port) {
     }
 
     do {
-        *sa_port = htons(port);
+        int ret;
 
-        if (bind(fd, sa, salen) < 0 && errno != EADDRINUSE) {
-            pa_log("bind_socket() failed: %s", pa_cstrerror(errno));
+        *sa_port = htons(port);
+        ret = bind(fd, sa, salen);
+        if (!ret)
+            break;
+        if (ret < 0 && errno != EADDRINUSE) {
+            pa_log("bind() failed: %s", pa_cstrerror(errno));
             goto fail;
         }
-        break;
     } while (++port > 0);
 
     pa_log_debug("Socket bound to port %d (SOCK_DGRAM)", port);

commit ad9c8603b0b100e00b52224d83ed4f86fe12b8dd
Author: Peter Meerwald-Stadler <pmeerw at pmeerw.net>
Date:   Wed Feb 22 14:49:48 2017 +0100

    raop: Fix double free
    
    make nick variable local, fix double free
    Coverity CID: #1398162
    
    Signed-off-by: Peter Meerwald-Stadler <pmeerw at pmeerw.net>

diff --git a/src/modules/raop/raop-sink.c b/src/modules/raop/raop-sink.c
index 7d8fe36..d321a2d 100644
--- a/src/modules/raop/raop-sink.c
+++ b/src/modules/raop/raop-sink.c
@@ -460,7 +460,6 @@ pa_sink* pa_raop_sink_new(pa_module *m, pa_modargs *ma, const char *driver) {
     const char /* *username, */ *password;
     pa_sink_new_data data;
     const char *name = NULL;
-    char * nick = NULL;
 
     pa_assert(m);
     pa_assert(ma);
@@ -550,9 +549,11 @@ pa_sink* pa_raop_sink_new(pa_module *m, pa_modargs *ma, const char *driver) {
     if ((name = pa_modargs_get_value(ma, "sink_name", NULL))) {
         pa_sink_new_data_set_name(&data, name);
     } else {
+        char *nick;
+
         if ((name = pa_modargs_get_value(ma, "name", NULL)))
             nick = pa_sprintf_malloc("raop_client.%s", name);
-        if (!nick)
+        else
             nick = pa_sprintf_malloc("raop_client.%s", server);
         pa_sink_new_data_set_name(&data, nick);
         pa_xfree(nick);
@@ -618,7 +619,6 @@ pa_sink* pa_raop_sink_new(pa_module *m, pa_modargs *ma, const char *driver) {
 
 fail:
     pa_xfree(thread_name);
-    pa_xfree(nick);
 
     if (u)
         userdata_free(u);

commit 424e97a5fa56de8a1f7b87ff8fda66059cd1a0fc
Author: Peter Meerwald-Stadler <pmeerw at pmeerw.net>
Date:   Mon Mar 6 08:15:29 2017 +0100

    build: Add Coverity scan model
    
    the modeling file help to avoid false positives and increase scanning
    accuracy by explaining code Coverity can't see (out of tree libraries);
    the model file must be uploaded by an admin to:
    https://scan.coverity.com/projects/pulseaudio?tab=analysis_settings
    
    the pa_assert_se() macro needs to be rewritten for Coverity so that
    the assignment is not declared a side-effect
    
    Signed-off-by: Peter Meerwald-Stadler <pmeerw at pmeerw.net>

diff --git a/coverity/model.c b/coverity/model.c
new file mode 100644
index 0000000..afe7ca5
--- /dev/null
+++ b/coverity/model.c
@@ -0,0 +1,18 @@
+/* Coverity Scan model
+ * Copyright (C) 2017 Peter Meerwald-Stadler <pmeerw at pmeerw.net>
+ *
+ * This is a modeling file for Coverity Scan which helps to avoid false
+ * positives and increase scanning accuracy by explaining code Coverity
+ * can't see (out of tree libraries); the model file must be uploaded by
+ * an admin to:
+ * https://scan.coverity.com/projects/pulseaudio?tab=analysis_settings
+ */
+
+void fail(void) {
+    __coverity_panic__();
+}
+
+void fail_unless(int x) {
+    if (!x)
+        __coverity_panic__();
+}
diff --git a/src/pulsecore/macro.h b/src/pulsecore/macro.h
index 2c5d5f2..dbce5cd 100644
--- a/src/pulsecore/macro.h
+++ b/src/pulsecore/macro.h
@@ -186,6 +186,7 @@ static inline size_t PA_ALIGN(size_t l) {
 
 /* pa_assert_se() is an assert which guarantees side effects of x,
  * i.e. is never optimized away, regardless of NDEBUG or FASTPATH. */
+#ifndef __COVERITY__
 #define pa_assert_se(expr)                                              \
     do {                                                                \
         if (PA_UNLIKELY(!(expr))) {                                     \
@@ -193,6 +194,14 @@ static inline size_t PA_ALIGN(size_t l) {
             abort();                                                    \
         }                                                               \
     } while (false)
+#else
+#define pa_assert_se(expr)                                              \
+    do {                                                                \
+        int _unique_var = (expr);                                       \
+        if (!_unique_var)                                               \
+            abort();                                                    \
+    } while (false)
+#endif
 
 /* Does exactly nothing */
 #define pa_nop() do {} while (false)



More information about the pulseaudio-commits mailing list