instead of kicking clients with invalid UTF8 stream names, filter invalid characters and use that instead

git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@881 fefdeb5f-60dc-0310-8127-8f9354f1896f
This commit is contained in:
Lennart Poettering 2006-05-16 01:40:01 +00:00
parent 53595938d0
commit 56b685ab46

View file

@ -87,6 +87,8 @@ struct connection {
pa_source_output *source_output; pa_source_output *source_output;
pa_memblockq *input_memblockq, *output_memblockq; pa_memblockq *input_memblockq, *output_memblockq;
pa_defer_event *defer_event; pa_defer_event *defer_event;
char *original_name;
struct { struct {
pa_memblock *current_memblock; pa_memblock *current_memblock;
@ -175,7 +177,6 @@ static struct proto_handler proto_map[ESD_PROTO_MAX] = {
{ 0, esd_proto_get_latency, "get latency" } { 0, esd_proto_get_latency, "get latency" }
}; };
static void connection_free(struct connection *c) { static void connection_free(struct connection *c) {
assert(c); assert(c);
pa_idxset_remove_by_data(c->protocol->connections, c, NULL); pa_idxset_remove_by_data(c->protocol->connections, c, NULL);
@ -218,7 +219,8 @@ static void connection_free(struct connection *c) {
if (c->auth_timeout_event) if (c->auth_timeout_event)
c->protocol->core->mainloop->time_free(c->auth_timeout_event); c->protocol->core->mainloop->time_free(c->auth_timeout_event);
pa_xfree(c->original_name);
pa_xfree(c); pa_xfree(c);
} }
@ -316,7 +318,7 @@ static int esd_proto_connect(struct connection *c, PA_GCC_UNUSED esd_proto_t req
} }
static int esd_proto_stream_play(struct connection *c, PA_GCC_UNUSED esd_proto_t request, const void *data, size_t length) { static int esd_proto_stream_play(struct connection *c, PA_GCC_UNUSED esd_proto_t request, const void *data, size_t length) {
char name[ESD_NAME_MAX]; char name[ESD_NAME_MAX], *utf8_name;
int32_t format, rate; int32_t format, rate;
pa_sink *sink; pa_sink *sink;
pa_sample_spec ss; pa_sample_spec ss;
@ -341,14 +343,16 @@ static int esd_proto_stream_play(struct connection *c, PA_GCC_UNUSED esd_proto_t
strncpy(name, data, sizeof(name)); strncpy(name, data, sizeof(name));
name[sizeof(name)-1] = 0; name[sizeof(name)-1] = 0;
utf8_name = pa_utf8_filter(name);
CHECK_VALIDITY(pa_utf8_valid(name), "Invalid UTF8 in stream name");
pa_client_set_name(c->client, name); pa_client_set_name(c->client, utf8_name);
c->original_name = pa_xstrdup(name);
assert(!c->sink_input && !c->input_memblockq); assert(!c->sink_input && !c->input_memblockq);
c->sink_input = pa_sink_input_new(sink, __FILE__, name, &ss, NULL, NULL, 0, -1); c->sink_input = pa_sink_input_new(sink, __FILE__, utf8_name, &ss, NULL, NULL, 0, -1);
pa_xfree(utf8_name);
CHECK_VALIDITY(c->sink_input, "Failed to create sink input."); CHECK_VALIDITY(c->sink_input, "Failed to create sink input.");
@ -381,7 +385,7 @@ static int esd_proto_stream_play(struct connection *c, PA_GCC_UNUSED esd_proto_t
} }
static int esd_proto_stream_record(struct connection *c, esd_proto_t request, const void *data, size_t length) { static int esd_proto_stream_record(struct connection *c, esd_proto_t request, const void *data, size_t length) {
char name[ESD_NAME_MAX]; char name[ESD_NAME_MAX], *utf8_name;
int32_t format, rate; int32_t format, rate;
pa_source *source; pa_source *source;
pa_sample_spec ss; pa_sample_spec ss;
@ -426,13 +430,15 @@ static int esd_proto_stream_record(struct connection *c, esd_proto_t request, co
strncpy(name, data, sizeof(name)); strncpy(name, data, sizeof(name));
name[sizeof(name)-1] = 0; name[sizeof(name)-1] = 0;
CHECK_VALIDITY(pa_utf8_valid(name), "Invalid UTF8 in stream name."); utf8_name = pa_utf8_filter(name);
pa_client_set_name(c->client, utf8_name);
pa_client_set_name(c->client, name); pa_xfree(utf8_name);
c->original_name = pa_xstrdup(name);
assert(!c->output_memblockq && !c->source_output); assert(!c->output_memblockq && !c->source_output);
if (!(c->source_output = pa_source_output_new(source, __FILE__, name, &ss, NULL, -1))) { if (!(c->source_output = pa_source_output_new(source, __FILE__, c->client->name, &ss, NULL, -1))) {
pa_log(__FILE__": failed to create source output"); pa_log(__FILE__": failed to create source output");
return -1; return -1;
} }
@ -549,8 +555,11 @@ static int esd_proto_all_info(struct connection *c, esd_proto_t request, const v
connection_write(c, &id, sizeof(int32_t)); connection_write(c, &id, sizeof(int32_t));
/* name */ /* name */
assert(conn->client); memset(name, 0, ESD_NAME_MAX); /* don't leak old data */
strncpy(name, conn->client->name, ESD_NAME_MAX); if (conn->original_name)
strncpy(name, conn->original_name, ESD_NAME_MAX);
else if (conn->client && conn->client->name)
strncpy(name, conn->client->name, ESD_NAME_MAX);
connection_write(c, name, ESD_NAME_MAX); connection_write(c, name, ESD_NAME_MAX);
/* rate */ /* rate */
@ -593,6 +602,7 @@ static int esd_proto_all_info(struct connection *c, esd_proto_t request, const v
connection_write(c, &id, sizeof(int32_t)); connection_write(c, &id, sizeof(int32_t));
/* name */ /* name */
memset(name, 0, ESD_NAME_MAX); /* don't leak old data */
if (strncmp(ce->name, SCACHE_PREFIX, sizeof(SCACHE_PREFIX)-1) == 0) if (strncmp(ce->name, SCACHE_PREFIX, sizeof(SCACHE_PREFIX)-1) == 0)
strncpy(name, ce->name+sizeof(SCACHE_PREFIX)-1, ESD_NAME_MAX); strncpy(name, ce->name+sizeof(SCACHE_PREFIX)-1, ESD_NAME_MAX);
else else
@ -1177,6 +1187,8 @@ static void on_connection(pa_socket_server*s, pa_iochannel *io, void *userdata)
c->scache.memchunk.memblock = NULL; c->scache.memchunk.memblock = NULL;
c->scache.name = NULL; c->scache.name = NULL;
c->original_name = NULL;
if (!c->authorized) { if (!c->authorized) {
struct timeval tv; struct timeval tv;
pa_gettimeofday(&tv); pa_gettimeofday(&tv);