]> code.delx.au - pulseaudio/commitdiff
esound,streams: Fix some crashes.
authorColin Guthrie <colin@mageia.org>
Wed, 8 Jun 2011 19:18:12 +0000 (20:18 +0100)
committerColin Guthrie <colin@mageia.org>
Wed, 22 Jun 2011 21:45:28 +0000 (22:45 +0100)
After the rework to the add pa_sink_input_new_data_set_sink() (and
the source equiv) calling with a NULL sink object will hit an assert.

This caused crashes with the esd protocol and there was the potential
(albeit unlikely) for a crash when creating a sink input without any
sinks available (module-always-sink mitigates this risk but it's still
a potential crasher).

src/pulsecore/protocol-esound.c
src/pulsecore/sink-input.c
src/pulsecore/source-output.c

index edca96a1929f59fa522a884007d6b988798b91ba..484821c5aa6c6a72d9d464770d395555d1b64a88 100644 (file)
@@ -426,7 +426,8 @@ static int esd_proto_stream_play(connection *c, esd_proto_t request, const void
     sdata.driver = __FILE__;
     sdata.module = c->options->module;
     sdata.client = c->client;
-    pa_sink_input_new_data_set_sink(&sdata, sink, FALSE);
+    if (sink)
+        pa_sink_input_new_data_set_sink(&sdata, sink, FALSE);
     pa_sink_input_new_data_set_sample_spec(&sdata, &ss);
 
     pa_sink_input_new(&c->sink_input, c->protocol->core, &sdata);
@@ -524,7 +525,8 @@ static int esd_proto_stream_record(connection *c, esd_proto_t request, const voi
     sdata.driver = __FILE__;
     sdata.module = c->options->module;
     sdata.client = c->client;
-    pa_source_output_new_data_set_source(&sdata, source, FALSE);
+    if (source)
+        pa_source_output_new_data_set_source(&sdata, source, FALSE);
     pa_source_output_new_data_set_sample_spec(&sdata, &ss);
 
     pa_source_output_new(&c->source_output, c->protocol->core, &sdata);
index 9a43e044acf36af57cd2ea04af818ff55a6ac959..2e718c455f861fa559c88237f5cb5b5196fd1217 100644 (file)
@@ -273,9 +273,11 @@ int pa_sink_input_new(
 
     pa_return_val_if_fail(!data->driver || pa_utf8_valid(data->driver), -PA_ERR_INVALID);
 
-    if (!data->sink)
-        pa_sink_input_new_data_set_sink(data, pa_namereg_get(core, NULL, PA_NAMEREG_SINK), FALSE);
-
+    if (!data->sink) {
+        pa_sink *sink = pa_namereg_get(core, NULL, PA_NAMEREG_SINK);
+        pa_return_val_if_fail(sink, -PA_ERR_NOENTITY);
+        pa_sink_input_new_data_set_sink(data, sink, FALSE);
+    }
     /* Routing's done, we have a sink. Now let's fix the format and set up the
      * sample spec */
 
@@ -298,7 +300,6 @@ int pa_sink_input_new(
         pa_sink_input_new_data_set_sample_spec(data, &ss);
     }
 
-    pa_return_val_if_fail(data->sink, -PA_ERR_NOENTITY);
     pa_return_val_if_fail(PA_SINK_IS_LINKED(pa_sink_get_state(data->sink)), -PA_ERR_BADSTATE);
     pa_return_val_if_fail(!data->sync_base || (data->sync_base->sink == data->sink && pa_sink_input_get_state(data->sync_base) == PA_SINK_INPUT_CORKED), -PA_ERR_INVALID);
 
index e6cec605ebec169f2eb43a5515d0efaa7216f619..59b6c2fff42c9fd4271f43aa111476d63a08b192 100644 (file)
@@ -253,8 +253,11 @@ int pa_source_output_new(
 
     pa_return_val_if_fail(!data->driver || pa_utf8_valid(data->driver), -PA_ERR_INVALID);
 
-    if (!data->source)
-        pa_source_output_new_data_set_source(data, pa_namereg_get(core, NULL, PA_NAMEREG_SOURCE), FALSE);
+    if (!data->source) {
+        pa_source *source = pa_namereg_get(core, NULL, PA_NAMEREG_SOURCE);
+        pa_return_val_if_fail(source, -PA_ERR_NOENTITY);
+        pa_source_output_new_data_set_source(data, source, FALSE);
+    }
 
     /* Routing's done, we have a source. Now let's fix the format and set up the
      * sample spec */
@@ -278,7 +281,6 @@ int pa_source_output_new(
         pa_source_output_new_data_set_sample_spec(data, &ss);
     }
 
-    pa_return_val_if_fail(data->source, -PA_ERR_NOENTITY);
     pa_return_val_if_fail(PA_SOURCE_IS_LINKED(pa_source_get_state(data->source)), -PA_ERR_BADSTATE);
     pa_return_val_if_fail(!data->direct_on_input || data->direct_on_input->sink == data->source->monitor_of, -PA_ERR_INVALID);