Bug 55607 - crash because of null string on solaris
Summary: crash because of null string on solaris
Status: RESOLVED FIXED
Alias: None
Product: PulseAudio
Classification: Unclassified
Component: core (show other bugs)
Version: unspecified
Hardware: Other All
: medium normal
Assignee: pulseaudio-bugs
QA Contact: pulseaudio-bugs
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-10-04 08:58 UTC by Pierre Ossman
Modified: 2013-07-11 11:17 UTC (History)
2 users (show)

See Also:
i915 platform:
i915 features:


Attachments

Description Pierre Ossman 2012-10-04 08:58:36 UTC
Solaris' printf doesn't support NULL arguments for %s, which pulseaudio unfortunately gives it now and then. Making a safe printf wrapper is just a major pain, so I guess we'll have to find the offenders that provide null pointers. The most glaring one is pa_thread_get_name():

Index: src/pulsecore/thread-posix.c
===================================================================
--- src/pulsecore/thread-posix.c	(revision 25954)
+++ src/pulsecore/thread-posix.c	(working copy)
@@ -211,6 +211,9 @@
     }
 #endif
 
+    if (t->name == NULL)
+        return "(null)";
+
     return t->name;
 }
Comment 1 Peter Åstrand 2013-03-28 14:47:26 UTC
If there's anything we can do to make it easier to integrate this work, please let us know. Would a git pull request help?
Comment 2 Tanu Kaskinen 2013-03-29 12:23:18 UTC
Sorry for ignoring this. There was shortage of maintainer time prior to last November.

This particular change seems strange to me. "git grep pa_thread_new" indicates that threads are always created with a name, so t->name should never be NULL.

As for handling possibly-NULL strings in printf arguments in general, we have pa_strnull(), which may be in many cases more appropriate than patching string-returning functions to never return NULL.
Comment 3 Pierre Ossman 2013-07-10 14:40:24 UTC
Threads not created by PulseAudio however can lack a name. In this case the main thread.

Alternative patch using pa_strnull():

Index: src/pulsecore/log.c
===================================================================
--- src/pulsecore/log.c	(revision 27649)
+++ src/pulsecore/log.c	(working copy)
@@ -303,9 +303,9 @@
     pa_vsnprintf(text, sizeof(text), format, ap);
 
     if ((_flags & PA_LOG_PRINT_META) && file && line > 0 && func)
-        pa_snprintf(location, sizeof(location), "[%s][%s:%i %s()] ", pa_thread_get_name(pa_thread_self()), file, line, func);
+        pa_snprintf(location, sizeof(location), "[%s][%s:%i %s()] ", pa_strnull(pa_thread_get_name(pa_thread_self())), file, line, func);
     else if ((_flags & (PA_LOG_PRINT_META|PA_LOG_PRINT_FILE)) && file)
-        pa_snprintf(location, sizeof(location), "[%s] %s: ", pa_thread_get_name(pa_thread_self()), pa_path_get_filename(file));
+        pa_snprintf(location, sizeof(location), "[%s] %s: ", pa_strnull(pa_thread_get_name(pa_thread_self())), pa_path_get_filename(file));
     else
         location[0] = 0;


Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.