From e4034ba27de725e0fa9b6c4de8f32ca7ad0193a3 Mon Sep 17 00:00:00 2001 From: Jon Lund Steffensen Date: Mon, 9 Dec 2013 11:07:47 -0500 Subject: Do not allow NULL keys when setting options This should fix a bug where command line options for the "manual" location provider cannot override the config file. To keep compatability with previous versions the command line parser will still special case parsing "-l LAT:LON" and set the correct options in "manual". --- src/location-geoclue.c | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) (limited to 'src/location-geoclue.c') diff --git a/src/location-geoclue.c b/src/location-geoclue.c index ebc0cde..6d33a59 100644 --- a/src/location-geoclue.c +++ b/src/location-geoclue.c @@ -18,6 +18,7 @@ */ #include +#include #include #include @@ -104,6 +105,8 @@ void location_geoclue_free(location_geoclue_state_t *state) { if (state->position != NULL) g_object_unref(state->position); + if (state->provider != NULL) free(state->provider); + if (state->provider_path != NULL) free(state->provider_path); } void @@ -131,32 +134,22 @@ location_geoclue_set_option(location_geoclue_state_t *state, const char *path = NULL; /* Parse string value */ - if (key != NULL && strcasecmp(key, "name") == 0) { - if (value != NULL && strcasecmp(value, "default") == 0) { + if (strcasecmp(key, "name") == 0) { + if (strcasecmp(value, "default") == 0) { provider = DEFAULT_PROVIDER; - } else if (value != NULL) { - provider = value; } else { - fputs(_("Must specify a provider `name' (or use `default').\n"), stderr); - return -1; + provider = value; } - /* TODO I don't think we own the string here, should be copied. */ - state->provider = provider; - } else if (key != NULL && strcasecmp(key, "path") == 0) { + state->provider = strdup(provider); + } else if (strcasecmp(key, "path") == 0) { if (value != NULL && strcasecmp(value, "default") == 0) { path = DEFAULT_PROVIDER_PATH; - } else if (value != NULL) { - path = value; } else { - fputs(_("Must specify a provider `path' (or use `default').\n"), stderr); - return -1; + path = value; } - /* TODO I don't think we own the string here, should be copied. */ - state->provider_path = path; - } else if (key == NULL) { - return -1; + state->provider_path = strdup(path); } else { fprintf(stderr, _("Unknown method parameter: `%s'.\n"), key); return -1; -- cgit v1.2.3-70-g09d2