--- src/modules/macosx/module-coreaudio-device.c.old	2016-05-03 08:17:39.000000000 +0200
+++ src/modules/macosx/module-coreaudio-device.c	2016-09-27 03:14:04.000000000 +0200
@@ -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>
@@ -452,7 +453,11 @@ static int ca_device_create_sink(pa_modu
         pa_xfree(tmp);
     }
 
-    ca_sink->name = pa_strbuf_to_string_free(strbuf);
+    /* Clamp to PA_NAME_MAX and leave a "safety margin" for deduplication
+     * and other appended data. */
+    tmp = pa_strbuf_to_string_free(strbuf);
+    ca_sink->name = pa_xstrndup(tmp, PA_NAME_MAX - 20);
+    pa_xfree(tmp);
 
     pa_log_debug("Stream name is >%s<", ca_sink->name);
 
@@ -585,7 +590,11 @@ static int ca_device_create_source(pa_mo
         pa_xfree(tmp);
     }
 
-    ca_source->name = pa_strbuf_to_string_free(strbuf);
+    /* Clamp to PA_NAME_MAX and leave a "safety margin" for deduplication
+     * and other appended data. */
+    tmp = pa_strbuf_to_string_free(strbuf);
+    ca_source->name = pa_xstrndup(tmp, PA_NAME_MAX - 20);
+    pa_xfree(tmp);
 
     pa_log_debug("Stream name is >%s<", ca_source->name);
 
