[pulseaudio-discuss] Patch for segfault on Solaris 8 (NULL pointers)

Kevin Mescher kevin.mescher at gmail.com
Fri Feb 16 17:38:30 PST 2007


I was building Pulseaudio on Solaris 8, and I found a problem with module loading.  When the module is loaded, the argument field of the module struct is set to a NULL pointer (instead of a null string).  While on Linux, this would not generate a problem, it does on Solaris when the module list is printed.

An example:

On Linux, running the list-modules command from the Pulseaudio command line:

...
index: 10
        name: <module-x11-publish>
        argument: <(null)>
        used: -1
        auto unload: no
...

On Solaris 8, it segfaults (on a strlen function inside vsnprintf)


Note the '(null)' as the value of the argument field.  I traced the actual call to generate this text:

from pulsecore/cli-text.c, line 57 (only relevant portion listed)

pa_strbuf_printf(s, "    ...argument: <%s>\n...", ..., m->argument,...);

The problem is when any one of the C strings in the argument list to the pa_strbuf_printf call is a NULL pointer.

The Solaris man pages for printf list the behavior as "undefined" when a NULL pointer is passed as a string argument.  It looks like the behavior persists in OpenSolaris (on purpose).
See See http://developers.sun.com/solaris/articles/portingUNIXapps.html for more info on Solaris' take on dealing with NULL pointers.




I think there are a few options for fixing this:

1.	Fix the pa_strbuf_printf function to go through the format string, and for every %s, check and correct any NULL pointer.  I'm not sure how to do this one.

2.	Fix each call to pa_strbuf_printf.  This is not difficult, but would be tedious, as there are quite a few of these calls  (example in cli-text.patch)

3.	Change pa_xstrdup to return an empty string if it's given a NULL pointer.  While not an exact duplication of a NULL pointer, it would be much cleaner, and more portable (example in xmalloc.patch)

I would recommend option 3, as it permanently adjusts the NULL strings before they propogate anywhere.  There would be no need to correct any calls to pa_strbuf_printf, provided that ONLY strings created from pa_xstrdup were used.



-------------- next part --------------
A non-text attachment was scrubbed...
Name: cli-text.patch
Type: text/x-diff
Size: 802 bytes
Desc: not available
URL: <http://lists.freedesktop.org/archives/pulseaudio-discuss/attachments/20070216/4787f223/attachment.patch>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: xmalloc.patch
Type: text/x-diff
Size: 515 bytes
Desc: not available
URL: <http://lists.freedesktop.org/archives/pulseaudio-discuss/attachments/20070216/4787f223/attachment-0001.patch>


More information about the pulseaudio-discuss mailing list