[PATCH v2] module-coreaudio-device: respect PA_NAME_MAX length for source and sink names.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Not doing so leads to failures when creating sinks/sources for devices
with more than about 8 channels or too long channel names.

A "safety margin" of 20 characters is kept to allow for automatic
deduplication (e.g., appending a string like ".<number>") or additional
data (e.g., appending a string like ".data".)

Signed-off-by: Mihai Moldovan <ionic at ionic.de>
---
 src/modules/macosx/module-coreaudio-device.c | 23 +++++++++++++++++++----
 1 file changed, 19 insertions(+), 4 deletions(-)

diff --git a/src/modules/macosx/module-coreaudio-device.c b/src/modules/macosx/module-coreaudio-device.c
index 83921b0..aa5c493 100644
--- a/src/modules/macosx/module-coreaudio-device.c
+++ b/src/modules/macosx/module-coreaudio-device.c
@@ -43,6 +43,7 @@
 #include <pulsecore/thread.h>
 #include <pulsecore/thread-mq.h>
 #include <pulsecore/i18n.h>
+#include <pulsecore/namereg.h>
 
 #include <CoreAudio/CoreAudio.h>
 #include <CoreAudio/CoreAudioTypes.h>
@@ -408,7 +409,7 @@ static int ca_device_create_sink(pa_module *m, AudioBuffer *buf, int channel_idx
     coreaudio_sink *ca_sink;
     pa_sink *sink;
     unsigned int i, channels;
-    char tmp[255];
+    char tmp[255], *tmp_clamp;
     pa_strbuf *strbuf;
     AudioObjectPropertyAddress property_address;
     CFStringRef tmp_cfstr = NULL;
@@ -451,7 +452,14 @@ static int ca_device_create_sink(pa_module *m, AudioBuffer *buf, int channel_idx
         pa_strbuf_puts(strbuf, tmp);
     }
 
-    ca_sink->name = pa_strbuf_tostring_free(strbuf);
+    /* Clamp to PA_NAME_MAX and leave a "safety margin" for deduplication
+     * and other appended data. */
+    tmp_clamp = pa_strbuf_tostring_free(strbuf);
+    strncpy(tmp, tmp_clamp, PA_NAME_MAX - 20);
+    tmp[PA_NAME_MAX - 20] = 0;
+    pa_xfree(tmp_clamp);
+
+    ca_sink->name = pa_xstrndup(tmp, PA_NAME_MAX);
 
     pa_log_debug("Stream name is >%s<", ca_sink->name);
 
@@ -542,7 +550,7 @@ static int ca_device_create_source(pa_module *m, AudioBuffer *buf, int channel_i
     coreaudio_source *ca_source;
     pa_source *source;
     unsigned int i, channels;
-    char tmp[255];
+    char tmp[255], *tmp_clamp;
     pa_strbuf *strbuf;
     AudioObjectPropertyAddress property_address;
     CFStringRef tmp_cfstr = NULL;
@@ -585,7 +593,14 @@ static int ca_device_create_source(pa_module *m, AudioBuffer *buf, int channel_i
         pa_strbuf_puts(strbuf, tmp);
     }
 
-    ca_source->name = pa_strbuf_tostring_free(strbuf);
+    /* Clamp to PA_NAME_MAX and leave a "safety margin" for deduplication
+     * and other appended data. */
+    tmp_clamp = pa_strbuf_tostring_free(strbuf);
+    strncpy(tmp, tmp_clamp, PA_NAME_MAX - 20);
+    tmp[PA_NAME_MAX - 20] = 0;
+    pa_xfree(tmp_clamp);
+
+    ca_source->name = pa_xstrndup(tmp, PA_NAME_MAX);
 
     pa_log_debug("Stream name is >%s<", ca_source->name);
 
-- 
2.3.5


-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 4265 bytes
Desc: S/MIME Cryptographic Signature
URL: <http://lists.freedesktop.org/archives/pulseaudio-discuss/attachments/20150420/1530ff10/attachment.bin>


[Index of Archives]     [Linux Audio Users]     [AMD Graphics]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux