]> git.tuebingen.mpg.de Git - paraslash.git/commitdiff
Merge branch 'maint'
authorAndre Noll <maan@tuebingen.mpg.de>
Tue, 25 Apr 2017 16:04:57 +0000 (18:04 +0200)
committerAndre Noll <maan@tuebingen.mpg.de>
Tue, 25 Apr 2017 16:04:57 +0000 (18:04 +0200)
A couple of fixes found by the clang static analyzer.

* maint:
  aft: Check return value of load_afsi().
  audiod: Avoid reading garbage in get_time_string().
  net: Always initialize struct sockaddr_storage.
  wma_afh: Fix two bugs in convert_utf8_to_utf16().

aft.c
audiod.c
net.c
wma_afh.c

diff --git a/aft.c b/aft.c
index 7d3a6e0d98a01e40974f22285e9be2d9fac01b46..22890e569c0fdc73561644d1a346f7792853b38e 100644 (file)
--- a/aft.c
+++ b/aft.c
@@ -2297,7 +2297,9 @@ static int copy_selector_info(__a_unused struct osl_table *table,
        ret = get_afsi_object_of_row(row, &target_afsi_obj);
        if (ret < 0)
                return ret;
-       load_afsi(&target_afsi, &target_afsi_obj);
+       ret = load_afsi(&target_afsi, &target_afsi_obj);
+       if (ret < 0)
+               return ret;
        old_afsi = target_afsi;
        if (cad->flags & CPSI_FLAG_COPY_LYRICS_ID)
                target_afsi.lyrics_id = cad->source_afsi.lyrics_id;
index 254bcb8d8c4bac2947e52c3310fb7051fe5f1153..517958474f39077ebbbf3b6557d4bab6a6ebf82c 100644 (file)
--- a/audiod.c
+++ b/audiod.c
@@ -305,6 +305,7 @@ char *get_time_string(void)
                rskip; /* receiver start - sss */
        int slot_num = get_play_time_slot_num();
        struct slot_info *s = slot_num < 0? NULL : &slot[slot_num];
+       bool writer_active = s && s->wns && s->wns[0].btrn;
        char *msg;
 
        if (audiod_status == AUDIOD_OFF)
@@ -318,11 +319,11 @@ char *get_time_string(void)
        }
        /*
         * Valid status items and playing, set length and tmp to the stream
-        * start. We use the slot info and fall back to the info from current
-        * status items if no slot info is available.
+        * start. We use the writer start time from the slot info and fall back
+        * to the info from current status items if no writer is active yet.
         */
        tmp = &stat_task->server_stream_start;
-       if (s && s->wns && s->wns[0].btrn) { /* writer active in this slot */
+       if (writer_active) {
                btr_get_node_start(s->wns[0].btrn, &wstime);
                if (wstime.tv_sec != 0) { /* writer wrote something */
                        if (s->server_stream_start.tv_sec == 0) {
@@ -339,7 +340,7 @@ char *get_time_string(void)
                tv_diff(tmp, &stat_task->sa_time_diff, &sss);
        else
                tv_add(tmp, &stat_task->sa_time_diff, &sss);
-       if (!s || !s->wns || !s->wns[0].btrn || wstime.tv_sec == 0) {
+       if (!writer_active) {
                struct timeval diff;
                tv_diff(now, &sss, &diff);
                seconds = diff.tv_sec + stat_task->offset_seconds;
diff --git a/net.c b/net.c
index 023d78d08175f2f3810af6dd387f5eec14a06dcc..6c23fdd9ce6b248e562e84c23d3e089e4484b178 100644 (file)
--- a/net.c
+++ b/net.c
@@ -603,7 +603,7 @@ static inline int estimated_header_overhead(const int af_type)
  */
 int generic_max_transport_msg_size(int sockfd)
 {
-       struct sockaddr_storage ss;
+       struct sockaddr_storage ss = {0};
        socklen_t sslen = sizeof(ss);
        int af_type = AF_INET;
 
@@ -629,7 +629,7 @@ int generic_max_transport_msg_size(int sockfd)
  */
 char *remote_name(int fd)
 {
-       struct sockaddr_storage ss;
+       struct sockaddr_storage ss = {0};
        const struct sockaddr *sa;
        socklen_t sslen = sizeof(ss);
        char hbuf[NI_MAXHOST], sbuf[NI_MAXSERV];
index 6bf2d64134539f07237fb31db9a83a7629db3f83..7394bf91768276b92884e1548f61ed791946540d 100644 (file)
--- a/wma_afh.c
+++ b/wma_afh.c
@@ -316,22 +316,24 @@ static const char top_level_header_object_guid[] = {
 
 static int convert_utf8_to_utf16(char *src, char **dst)
 {
-       /*
-        * Without specifying LE (little endian), iconv includes a byte order
-        * mark (e.g. 0xFFFE) at the beginning.
-        */
-       iconv_t cd = iconv_open("UTF-16LE", "UTF-8");
+       iconv_t cd;
        size_t sz, inbytes, outbytes, inbytesleft, outbytesleft;
        char *inbuf, *outbuf;
        int ret;
 
        if (!src || !*src) {
                *dst = para_calloc(2);
-               ret = 0;
-               goto out;
+               return 0;
        }
-       if (cd == (iconv_t) -1)
+       /*
+        * Without specifying LE (little endian), iconv includes a byte order
+        * mark (e.g. 0xFFFE) at the beginning.
+        */
+       cd = iconv_open("UTF-16LE", "UTF-8");
+       if (cd == (iconv_t)-1) {
+               *dst = NULL;
                return -ERRNO_TO_PARA_ERROR(errno);
+       }
        inbuf = src;
        /* even though src is in UTF-8, strlen() should DTRT */
        inbytes = inbytesleft = strlen(src);
@@ -340,6 +342,8 @@ static int convert_utf8_to_utf16(char *src, char **dst)
        sz = iconv(cd, ICONV_CAST &inbuf, &inbytesleft, &outbuf, &outbytesleft);
        if (sz == (size_t)-1) {
                ret = -ERRNO_TO_PARA_ERROR(errno);
+               free(*dst);
+               *dst = NULL;
                goto out;
        }
        assert(outbytes >= outbytesleft);
@@ -351,8 +355,6 @@ static int convert_utf8_to_utf16(char *src, char **dst)
        *dst = outbuf;
        PARA_INFO_LOG("converted %s to %d UTF-16 bytes\n", src, ret);
 out:
-       if (ret < 0)
-               free(*dst);
        if (iconv_close(cd) < 0)
                PARA_WARNING_LOG("iconv_close: %s\n", strerror(errno));
        return ret;