diff options
Diffstat (limited to 'src/pulsecore/modargs.c')
-rw-r--r-- | src/pulsecore/modargs.c | 30 |
1 files changed, 22 insertions, 8 deletions
diff --git a/src/pulsecore/modargs.c b/src/pulsecore/modargs.c index 7ce3dd08..5f5902c9 100644 --- a/src/pulsecore/modargs.c +++ b/src/pulsecore/modargs.c @@ -1,5 +1,3 @@ -/* $Id$ */ - /*** This file is part of PulseAudio. @@ -48,11 +46,17 @@ struct entry { static int add_key_value(pa_hashmap *map, char *key, char *value, const char* const valid_keys[]) { struct entry *e; - + pa_assert(map); pa_assert(key); pa_assert(value); + if (pa_hashmap_get(map, key)) { + pa_xfree(key); + pa_xfree(value); + return -1; + } + if (valid_keys) { const char*const* v; for (v = valid_keys; *v; v++) @@ -70,7 +74,7 @@ static int add_key_value(pa_hashmap *map, char *key, char *value, const char* co e->key = key; e->value = value; pa_hashmap_put(map, key, e); - + return 0; } @@ -80,7 +84,15 @@ pa_modargs *pa_modargs_new(const char *args, const char* const* valid_keys) { map = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func); if (args) { - enum { WHITESPACE, KEY, VALUE_START, VALUE_SIMPLE, VALUE_DOUBLE_QUOTES, VALUE_TICKS } state; + enum { + WHITESPACE, + KEY, + VALUE_START, + VALUE_SIMPLE, + VALUE_DOUBLE_QUOTES, + VALUE_TICKS + } state; + const char *p, *key, *value; size_t key_len = 0, value_len = 0; @@ -100,6 +112,8 @@ pa_modargs *pa_modargs_new(const char *args, const char* const* valid_keys) { case KEY: if (*p == '=') state = VALUE_START; + else if (isspace(*p)) + goto fail; else key_len++; break; @@ -172,7 +186,7 @@ fail: static void free_func(void *p, PA_GCC_UNUSED void*userdata) { struct entry *e = p; pa_assert(e); - + pa_xfree(e->key); pa_xfree(e->value); pa_xfree(e); @@ -225,7 +239,7 @@ int pa_modargs_get_value_s32(pa_modargs *ma, const char *key, int32_t *value) { return 0; } -int pa_modargs_get_value_boolean(pa_modargs *ma, const char *key, int *value) { +int pa_modargs_get_value_boolean(pa_modargs *ma, const char *key, pa_bool_t *value) { const char *v; int r; @@ -250,7 +264,7 @@ int pa_modargs_get_sample_spec(pa_modargs *ma, pa_sample_spec *rss) { const char *format; uint32_t channels; pa_sample_spec ss; - + pa_assert(ma); pa_assert(rss); |