fixup! tizen-device: add sample spec and return it for connected device list 43/286843/5 accepted/tizen/unified/20230117.140512
authorSeungbae Shin <seungbae.shin@samsung.com>
Fri, 13 Jan 2023 11:28:31 +0000 (20:28 +0900)
committerSeungbae Shin <seungbae.shin@samsung.com>
Mon, 16 Jan 2023 07:01:18 +0000 (16:01 +0900)
fixes the following potential ASAN issue by retrieving device sample spec just in time.

==pulseaudio==605==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x007f940031f0
0x007f940031f0 is located 424 bytes to the right of 1480-byte region [0x007f94002a80,0x007f94003048)

[Version] 15.0.36
[Issue Type] ASAN

Change-Id: Id3d111cc4a73d026be3c31c6a4ba7a3a6f97d835

packaging/pulseaudio-modules-tizen.spec
src/device-manager-dbus.c
src/tizen-device.c
src/tizen-device.h

index 73c495b..5746218 100644 (file)
@@ -2,7 +2,7 @@
 
 Name:             pulseaudio-modules-tizen
 Summary:          Pulseaudio modules for Tizen
-Version:          15.0.35
+Version:          15.0.36
 Release:          0
 Group:            Multimedia/Audio
 License:          LGPL-2.1+
index 6b52c1b..7b32367 100644 (file)
@@ -697,13 +697,15 @@ static void array_iter_append(DBusMessageIter *array_iter, pa_idxset *device_lis
         name = pa_tz_device_get_name(device);
         vendor_id = (dbus_int32_t)pa_tz_device_get_vendor_id(device);
         product_id = (dbus_int32_t)pa_tz_device_get_product_id(device);
-        product_id = (dbus_int32_t)pa_tz_device_get_product_id(device);
         is_running = (dbus_bool_t)pa_tz_device_is_running(device);
 
+        format = samplerate = channels = 0;
         spec = pa_tz_device_get_sample_spec(device);
-        format = (dbus_int32_t)spec->format;
-        samplerate = (dbus_int32_t)spec->rate;
-        channels = (dbus_int32_t)spec->channels;
+        if (spec) {
+            format = (dbus_int32_t)spec->format;
+            samplerate = (dbus_int32_t)spec->rate;
+            channels = (dbus_int32_t)spec->channels;
+        }
 
         if (device_is_match_with_mask(device, mask)) {
             simple_device_dump(PA_LOG_INFO, "[MATCH]", device_id, type, name, direction, state);
index b40503a..4cdda11 100644 (file)
@@ -462,8 +462,6 @@ pa_tz_device* pa_tz_device_new(pa_tz_device_new_data *data) {
     pa_sink *sink;
     pa_source *source;
 
-    char spec_str[PA_SAMPLE_SPEC_SNPRINT_MAX] = { 0, };
-
     pa_assert(data);
 
     if (_check_valid_device_new_data(data) < 0) {
@@ -496,19 +494,10 @@ pa_tz_device* pa_tz_device_new(pa_tz_device_new_data *data) {
     device->is_running = false;
     device->specified_stream_role = pa_xstrdup("none");
 
-    if ((sink = device_get_sink(device, NULL))) {
+    if ((sink = device_get_sink(device, NULL)))
         sink->device_item = device;
-        device->sample_spec = &sink->sample_spec;
-    }
-    if ((source = device_get_source(device, NULL))) {
+    if ((source = device_get_source(device, NULL)))
         source->device_item = device;
-        device->sample_spec = &source->sample_spec;
-    }
-    pa_sample_spec_snprint(spec_str, sizeof(spec_str), device->sample_spec);
-
-    pa_log_info("New device: type(%s) spec(%s) id(%u) name(%s) system_id(%s) vendor_id(%04x) product_id(%04x)",
-            device->type, spec_str, device->id, device->name,
-            pa_strempty(device->system_id), device->vendor_id, device->product_id);
 
     pa_idxset_put(device->list, device, NULL);
 
@@ -787,9 +776,27 @@ bool pa_tz_device_is_use_internal_codec(pa_tz_device *device) {
 }
 
 const pa_sample_spec* pa_tz_device_get_sample_spec(pa_tz_device *device) {
+    pa_sink *sink;
+    pa_source *source;
+    const pa_sample_spec* spec;
+    char spec_str[PA_SAMPLE_SPEC_SNPRINT_MAX] = { 0, };
+
     pa_assert(device);
 
-    return device->sample_spec;
+    /* ToDo : Devices with multiple direction with multiple sample spec should be considered */
+    if ((sink = device_get_sink(device, NULL))) {
+        spec = &sink->sample_spec;
+    } else if ((source = device_get_source(device, NULL))) {
+        spec = &source->sample_spec;
+    } else {
+        pa_log_error("Failed to get sample spec!");
+        return NULL;
+    }
+
+    pa_sample_spec_snprint(spec_str, sizeof(spec_str), spec);
+    pa_log_info("sample spec for device(%p)(%s) : %s", device, device->name, spec_str);
+
+    return spec;
 }
 
 bool pa_tz_device_is_all_suspended(pa_tz_device *device) {
index 1d22ea0..1910617 100644 (file)
@@ -64,9 +64,6 @@ struct pa_tz_device {
     bool sco_opened;
 #endif
 
-    /* mirrors to the corresponding sink/source sample spec */
-    const pa_sample_spec *sample_spec;
-
     /* Devices are contained in this list */
     pa_idxset *list;