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.
--- pulseaudio-0.9.5/src/pulsecore/cli-text.c 2007-02-16 20:17:13.000000000 -0500
+++ pulseaudio-0.9.5/src/pulsecore/cli-text.c.new 2007-02-16 20:14:27.000000000 -0500
@@ -54,7 +54,7 @@
pa_strbuf_printf(s, "%u module(s) loaded.\n", pa_idxset_size(c->modules));
for (m = pa_idxset_first(c->modules, &idx); m; m = pa_idxset_next(c->modules, &idx))
- pa_strbuf_printf(s, " index: %u\n\tname: <%s>\n\targument: <%s>\n\tused: %i\n\tauto unload: %s\n", m->index, m->name, m->argument, m->n_used, m->auto_unload ? "yes" : "no");
+ pa_strbuf_printf(s, " index: %u\n\tname: <%s>\n\targument: <%s>\n\tused: %i\n\tauto unload: %s\n", m->index, m->name, m->argument ? m->argument : "", m->n_used, m->auto_unload ? "yes" : "no");
return pa_strbuf_tostring_free(s);
}
--- pulseaudio-0.9.5/src/pulse/xmalloc.c.orig 2007-02-16 20:21:20.000000000 -0500
+++ pulseaudio-0.9.5/src/pulse/xmalloc.c 2007-02-16 20:27:03.000000000 -0500
@@ -100,7 +100,7 @@
char *pa_xstrdup(const char *s) {
if (!s)
- return NULL;
+ return pa_xmemdup("",1);
return pa_xmemdup(s, strlen(s)+1);
}
@@ -109,7 +109,7 @@
char *e, *r;
if (!s)
- return NULL;
+ return pa_xmemdup("",1);
if ((e = memchr(s, 0, l)))
return pa_xmemdup(s, e-s+1);
_______________________________________________
pulseaudio-discuss mailing list
[email protected]
https://tango.0pointer.de/mailman/listinfo/pulseaudio-discuss