From: Andre Noll Date: Tue, 25 Apr 2017 16:04:57 +0000 (+0200) Subject: Merge branch 'maint' X-Git-Tag: v0.6.0~5 X-Git-Url: http://git.tuebingen.mpg.de/?a=commitdiff_plain;h=869fa1d76e7f88470120552792ca71068b49a747;hp=64411efdbd90f1080ad1fd010d468cea63aec923;p=paraslash.git Merge branch 'maint' 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(). --- diff --git a/aft.c b/aft.c index 7d3a6e0d..22890e56 100644 --- 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; diff --git a/audiod.c b/audiod.c index 254bcb8d..51795847 100644 --- 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 023d78d0..6c23fdd9 100644 --- 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]; diff --git a/wma_afh.c b/wma_afh.c index 6bf2d641..7394bf91 100644 --- 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;