Fix Coverity Defects 55/154555/5
authorSeungbae Shin <seungbae.shin@samsung.com>
Tue, 10 Oct 2017 12:10:07 +0000 (21:10 +0900)
committerSangchul Lee <sc11.lee@samsung.com>
Thu, 12 Oct 2017 00:55:59 +0000 (09:55 +0900)
[Version] 5.0-173
[Issue Type] Security

Change-Id: Ic9eb88001ad3de157ea4940bce64a7f79609a12b

packaging/pulseaudio-modules-tizen.spec
src/device-manager.c
src/module-sound-player.c
src/module-tizenaudio-sink.c
src/module-tizenaudio-source.c
src/stream-manager-dbus.c
src/stream-manager-volume.c
src/stream-manager.c
src/tizen-device-def.c

index 414361a75cad8c4d3e41449d8cb6059c93726a8e..26dcca187b397c11d1765c9faeec1cdf76547f74 100644 (file)
@@ -1,6 +1,6 @@
 Name:             pulseaudio-modules-tizen
 Summary:          Pulseaudio modules for Tizen
-Version:          5.0.172
+Version:          5.0.173
 Release:          0
 Group:            Multimedia/Audio
 License:          LGPL-2.1+
index 3aa2ea1bd9ee572d472c7720d02e26679a21f418..cc95ec850ce37602fa435a7de7bd9ffb858c0b2f 100644 (file)
@@ -651,7 +651,7 @@ static const char* pulse_device_get_device_string_removed_argument(pa_object *pd
         next_p++;
     }
 
-    strncpy(removed_param, next_p, DEVICE_PARAM_STRING_MAX);
+    pa_strlcpy(removed_param, next_p, DEVICE_PARAM_STRING_MAX);
 
     if (device_string_p > params_p) {
         prev_len = device_string_p - params_p;
@@ -970,7 +970,7 @@ static const char* build_params_to_load_device(const char *device_string, const
         if (params) {
             pa_strbuf_printf(args_buf, "%s", params);
         }
-        strncpy(args, pa_strbuf_tostring_free(args_buf), DEVICE_PARAM_STRING_MAX);
+        pa_strlcpy(args, pa_strbuf_tostring_free(args_buf), DEVICE_PARAM_STRING_MAX);
     } else {
         return params;
     }
@@ -2268,16 +2268,16 @@ static pa_idxset* parse_device_type_infos() {
             if ((device_o = json_object_array_get_idx(device_array_o, device_type_idx)) && json_object_is_type(device_o, json_type_object)) {
                 json_object *device_prop_o;
                 const char *type = NULL;
-                type_info = pa_xmalloc0(sizeof(struct device_type_info));
 
-                if (json_object_object_get_ex(device_o, DEVICE_TYPE_PROP_DEVICE_TYPE, &device_prop_o) && json_object_is_type(device_prop_o, json_type_string)) {
-                    type = json_object_get_string(device_prop_o);
-                    pa_log_info("[ Device - %s ]", type);
-                    type_info->type = type;
-                } else {
+                if (!json_object_object_get_ex(device_o, DEVICE_TYPE_PROP_DEVICE_TYPE, &device_prop_o) && json_object_is_type(device_prop_o, json_type_string)) {
                     pa_log_error("Get device type failed");
                     goto fail;
                 }
+                type = json_object_get_string(device_prop_o);
+                pa_log_info("[ Device - %s ]", type);
+
+                type_info = pa_xmalloc0(sizeof(struct device_type_info));
+                type_info->type = type;
 
                 if (json_object_object_get_ex(device_o, DEVICE_TYPE_PROP_PLAYBACK_DEVICES, &device_prop_o) && json_object_is_type(device_prop_o, json_type_object)) {
                     pa_log_info("Playback Devices");
index fb9660a6b84e66c6ec9c2c45614f35d85d4983c3..b8792055633767e23c6aad188da527cfa66f9839 100644 (file)
@@ -405,7 +405,7 @@ static void send_signal_for_eos(struct userdata *u, int32_t stream_idx) {
 
     pa_log_info("Send EOS signal for stream_idx(%d)", stream_idx);
 
-    pa_assert_se(signal_msg = dbus_message_new_signal(SOUND_PLAYER_OBJECT_PATH, SOUND_PLAYER_INTERFACE, SOUND_PLAYER_SIGNAL_EOS));
+    pa_assert_se((signal_msg = dbus_message_new_signal(SOUND_PLAYER_OBJECT_PATH, SOUND_PLAYER_INTERFACE, SOUND_PLAYER_SIGNAL_EOS)));
     pa_assert_se(dbus_message_append_args(signal_msg, DBUS_TYPE_INT32, &stream_idx, DBUS_TYPE_INVALID));
     pa_assert_se(dbus_connection_send(pa_dbus_connection_get(u->dbus_conn), signal_msg, NULL));
     dbus_message_unref(signal_msg);
@@ -440,7 +440,8 @@ static int init_ipc(struct userdata *u) {
     }
 
     /* for non-blocking read */
-    fcntl(u->fd, F_SETFL, O_NONBLOCK);
+    if (fcntl(u->fd, F_SETFL, O_NONBLOCK) == -1)
+        pa_log_warn("Setting non-block flag failed. errno=[%d][%s]", errno, pa_cstrerror(errno));
 
     /* change access mode so group can use keytone pipe */
     if (fchmod(u->fd, 0666) == -1)
index 35f16a0c1d3c5e439aeb48d9a7cc0ef21f3fd369..d81cecc5c69e53b1e4b03049bd46c61bdb6e110c 100644 (file)
@@ -258,7 +258,7 @@ static void sink_update_requested_latency_cb(pa_sink *s) {
     struct userdata *u;
 
     pa_sink_assert_ref(s);
-    pa_assert_se(u = s->userdata);
+    pa_assert_se((u = s->userdata));
 
     u->block_usec = pa_sink_get_requested_latency_within_thread(s);
 
@@ -566,7 +566,7 @@ int pa__get_n_used(pa_module *m) {
     struct userdata *u;
 
     pa_assert(m);
-    pa_assert_se(u = m->userdata);
+    pa_assert_se((u = m->userdata));
 
     return pa_sink_linked_by(u->sink);
 }
index c60f90b82c83138b646ccd7ff90cd7568622d7f6..90fc73537d7de2dcf3dd8bdc567ff02c7c51931c 100644 (file)
@@ -156,16 +156,25 @@ static int suspend(struct userdata *u) {
 static int unsuspend(struct userdata *u) {
     pa_sample_spec sample_spec;
     int32_t ret;
+    size_t frame_size;
+
     pa_assert(u);
     pa_assert(!u->pcm_handle);
 
     pa_log_info("Trying resume...");
+
     sample_spec = u->source->sample_spec;
+    frame_size = pa_frame_size(&sample_spec);
+    if (frame_size == 0) {
+        pa_log_error("Unexpected frame size zero!");
+        goto fail;
+    }
+
     ret = pa_hal_interface_pcm_open(u->hal_interface,
               (void **)&u->pcm_handle,
               DIRECTION_IN,
               &sample_spec,
-              u->frag_size / pa_frame_size(&sample_spec),
+              u->frag_size / frame_size,
               u->nfrags);
     if (ret) {
         pa_log_error("Error opening PCM device %x", ret);
@@ -246,7 +255,7 @@ static void source_update_requested_latency_cb(pa_source *s) {
     size_t nbytes;
 
     pa_source_assert_ref(s);
-    pa_assert_se(u = s->userdata);
+    pa_assert_se((u = s->userdata));
 
     u->block_usec = pa_source_get_requested_latency_within_thread(s);
 
@@ -270,6 +279,10 @@ static int process_render(struct userdata *u, pa_usec_t now) {
     while (u->timestamp < now + u->block_usec) {
         pa_memchunk chunk;
         frame_size = pa_frame_size(&u->source->sample_spec);
+        if (frame_size == 0) {
+            pa_log_error("Unexpected frame size zero!");
+            break;
+        }
 
         pa_hal_interface_pcm_available(u->hal_interface, u->pcm_handle, &avail);
         if (avail == 0) {
@@ -499,7 +512,7 @@ int pa__get_n_used(pa_module *m) {
     struct userdata *u;
 
     pa_assert(m);
-    pa_assert_se(u = m->userdata);
+    pa_assert_se((u = m->userdata));
 
     return pa_source_linked_by(u->source);
 }
index 54db24618d23b0a9642ebe186cc0b27b1fdb9380..39edf87ba8b4f4932bb035e1d761e6acec9c313b 100644 (file)
@@ -239,7 +239,7 @@ static DBusHandlerResult handle_introspect(DBusConnection *conn, DBusMessage *ms
     pa_assert(msg);
     pa_assert(userdata);
 
-    pa_assert_se(r = dbus_message_new_method_return(msg));
+    pa_assert_se((r = dbus_message_new_method_return(msg)));
     pa_assert_se(dbus_message_append_args(r, DBUS_TYPE_STRING, &xml, DBUS_TYPE_INVALID));
 
     if (r) {
@@ -1391,7 +1391,7 @@ static void send_volume_changed_signal(DBusConnection *conn, const char *directi
 
     pa_log_debug("direction[%s], type[%s], level[%d]", direction, volume_type, volume_level);
 
-    pa_assert_se(signal_msg = dbus_message_new_signal(STREAM_MANAGER_OBJECT_PATH, STREAM_MANAGER_INTERFACE, STREAM_MANAGER_SIGNAL_NAME_VOLUME_CHANGED));
+    pa_assert_se((signal_msg = dbus_message_new_signal(STREAM_MANAGER_OBJECT_PATH, STREAM_MANAGER_INTERFACE, STREAM_MANAGER_SIGNAL_NAME_VOLUME_CHANGED)));
     dbus_message_iter_init_append(signal_msg, &msg_iter);
 
     dbus_message_iter_append_basic(&msg_iter, DBUS_TYPE_STRING, &direction);
@@ -1412,7 +1412,7 @@ void send_command_signal(DBusConnection *conn, const char *name, int value) {
 
     pa_log_debug("name[%s], value[%d]", name, value);
 
-    pa_assert_se(signal_msg = dbus_message_new_signal(STREAM_MANAGER_OBJECT_PATH, STREAM_MANAGER_INTERFACE, STREAM_MANAGER_SIGNAL_NAME_COMMAND));
+    pa_assert_se((signal_msg = dbus_message_new_signal(STREAM_MANAGER_OBJECT_PATH, STREAM_MANAGER_INTERFACE, STREAM_MANAGER_SIGNAL_NAME_COMMAND)));
     dbus_message_iter_init_append(signal_msg, &msg_iter);
 
     dbus_message_iter_append_basic(&msg_iter, DBUS_TYPE_STRING, &name);
index 34379cba165dab6d916d12448e64c53c36d8741c..dc9e535706ac982c4e1482f5f6131e7de8aa3873 100644 (file)
@@ -428,6 +428,11 @@ int32_t set_volume_level_by_idx(pa_stream_manager *m, stream_type_t stream_type,
     pa_assert(m);
 
     s = pa_idxset_get_by_index(stream_type == STREAM_SINK_INPUT ? m->core->sink_inputs : m->core->source_outputs, idx);
+    if (s == NULL) {
+        pa_log_error("failed to get stream...[%d]", idx);
+        return -1;
+    }
+
     if (!(volume_type_str = pa_proplist_gets(GET_STREAM_PROPLIST(s, stream_type), PA_PROP_MEDIA_TIZEN_VOLUME_TYPE))) {
         pa_log_debug("idx[%u] doesn't have volume type", idx);
         return -1;
index 580f3654864e339c28fb9bac0f78f75322953da1..aed4bad9f25e753bab6f7797746ca334238ad755 100644 (file)
@@ -599,6 +599,19 @@ static void dump_stream_map(pa_stream_manager *m) {
     pa_log_debug("===========[END stream-map dump]===========");
 }
 
+static void stream_info_free(stream_info *s) {
+    pa_assert(s);
+
+    if (s->idx_avail_in_devices)
+        pa_idxset_free(s->idx_avail_in_devices, NULL);
+    if (s->idx_avail_out_devices)
+        pa_idxset_free(s->idx_avail_out_devices, NULL);
+    if (s->idx_avail_frameworks)
+        pa_idxset_free(s->idx_avail_frameworks, NULL);
+
+    pa_xfree(s);
+}
+
 static int init_stream_map(pa_stream_manager *m) {
     volume_info *v;
     stream_info *s;
@@ -616,7 +629,6 @@ static int init_stream_map(pa_stream_manager *m) {
     json_object *out_device_o;
     json_object *in_device_o;
     json_object *framework_o;
-    void *state = NULL;
 
     pa_assert(m);
 
@@ -627,7 +639,7 @@ static int init_stream_map(pa_stream_manager *m) {
     }
 
     /* Latencies */
-    m->latency_infos = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func);
+    m->latency_infos = pa_hashmap_new_full(pa_idxset_string_hash_func, pa_idxset_string_compare_func, NULL, pa_xfree);
     if (json_object_object_get_ex(o, STREAM_MAP_LATENCIES, &array_o) && json_object_is_type(array_o, json_type_array)) {
         array_length = json_object_array_length(array_o);
         for (i = 0; i < array_length; i++) {
@@ -682,7 +694,7 @@ static int init_stream_map(pa_stream_manager *m) {
     }
 
     /* Volumes */
-    m->volume_infos = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func);
+    m->volume_infos = pa_hashmap_new_full(pa_idxset_string_hash_func, pa_idxset_string_compare_func, NULL, pa_xfree);
     if (json_object_object_get_ex(o, STREAM_MAP_VOLUMES, &array_o) && json_object_is_type(array_o, json_type_array)) {
         array_length = json_object_array_length(array_o);
         for (i = 0; i < array_length; i++) {
@@ -709,7 +721,7 @@ static int init_stream_map(pa_stream_manager *m) {
     }
 
     /* Streams */
-    m->stream_infos = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func);
+    m->stream_infos = pa_hashmap_new_full(pa_idxset_string_hash_func, pa_idxset_string_compare_func, NULL, (pa_free_cb_t)stream_info_free);
     if (json_object_object_get_ex(o, STREAM_MAP_STREAMS, &array_o) && json_object_is_type(array_o, json_type_array)) {
         array_length = json_object_array_length(array_o);
         for (i = 0; i < array_length; i++) {
@@ -817,65 +829,26 @@ static int init_stream_map(pa_stream_manager *m) {
     return 0;
 fail:
     pa_log_error("failed to initialize stream-map");
-    if (m->stream_infos) {
-        PA_HASHMAP_FOREACH(s, m->stream_infos, state) {
-            if (s->idx_avail_in_devices)
-                pa_idxset_free(s->idx_avail_in_devices, NULL);
-            if (s->idx_avail_out_devices)
-                pa_idxset_free(s->idx_avail_out_devices, NULL);
-            if (s->idx_avail_frameworks)
-                pa_idxset_free(s->idx_avail_frameworks, NULL);
-            pa_xfree(s);
-        }
+
+    if (m->stream_infos)
         pa_hashmap_free(m->stream_infos);
-    }
-    if (m->volume_infos) {
-        PA_HASHMAP_FOREACH(v, m->volume_infos, state) {
-            pa_xfree(v);
-        }
+    if (m->volume_infos)
         pa_hashmap_free(m->volume_infos);
-    }
-    if (m->latency_infos) {
-        PA_HASHMAP_FOREACH(l, m->latency_infos, state) {
-            pa_xfree(l);
-        }
+    if (m->latency_infos)
         pa_hashmap_free(m->latency_infos);
-    }
+
     return -1;
 }
 
 static void deinit_stream_map(pa_stream_manager *m) {
-    stream_info *s = NULL;
-    volume_info *v = NULL;
-    latency_info *l = NULL;
-    void *state = NULL;
-
     pa_assert(m);
 
-    if (m->stream_infos) {
-        PA_HASHMAP_FOREACH(s, m->stream_infos, state) {
-            if (s->idx_avail_in_devices)
-                pa_idxset_free(s->idx_avail_in_devices, NULL);
-            if (s->idx_avail_out_devices)
-                pa_idxset_free(s->idx_avail_out_devices, NULL);
-            if (s->idx_avail_frameworks)
-                pa_idxset_free(s->idx_avail_frameworks, NULL);
-            pa_xfree(s);
-        }
+    if (m->stream_infos)
         pa_hashmap_free(m->stream_infos);
-    }
-    if (m->volume_infos) {
-        PA_HASHMAP_FOREACH(v, m->volume_infos, state) {
-            pa_xfree(v);
-        }
+    if (m->volume_infos)
         pa_hashmap_free(m->volume_infos);
-    }
-    if (m->latency_infos) {
-        PA_HASHMAP_FOREACH(l, m->latency_infos, state) {
-            pa_xfree(l);
-        }
+    if (m->latency_infos)
         pa_hashmap_free(m->latency_infos);
-    }
 }
 
 static bool check_name_to_skip(pa_stream_manager *m, process_command_type_t command, void *stream, stream_type_t type, bool is_new_data) {
index c911a0956e1823617fad9d885e542fede0ab3fc3..37a192d53d83051ed297b34935726651dbc6f6ad 100644 (file)
@@ -156,7 +156,7 @@ bool device_type_is_valid_direction(const char *device_type, dm_device_direction
 }
 
 const char* device_direction_to_string(dm_device_direction_t direction) {
-    if (direction <= DM_DEVICE_DIRECTION_NONE || direction > DM_DEVICE_DIRECTION_BOTH) {
+    if (direction > DM_DEVICE_DIRECTION_BOTH) {
         return NULL;
     }