From de08fae66ab68e3eba96fdee33da971d08605f45 Mon Sep 17 00:00:00 2001 From: Jouni Malinen Date: Tue, 11 Feb 2020 06:41:33 +0200 Subject: [PATCH] DPP: Do not require dpp_configurator_params to start with a space This ugly hack for being able to search for optional arguments with space before them was quite inconvenient and unexpected. Clean this up by handling this mess internally with a memory allocation and string duplication if needed so that the users of wpa_supplicant control interface do not need to care about such details. Signed-off-by: Jouni Malinen --- src/common/dpp.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/common/dpp.c b/src/common/dpp.c index 7152703e6..b200d00da 100644 --- a/src/common/dpp.c +++ b/src/common/dpp.c @@ -4680,9 +4680,22 @@ int dpp_set_configurator(struct dpp_global *dpp, void *msg_ctx, const char *cmd) { const char *pos; + char *tmp = NULL; + int ret = -1; if (!cmd) return 0; + if (cmd[0] != ' ') { + size_t len; + + len = os_strlen(cmd); + tmp = os_malloc(len + 2); + if (!tmp) + goto fail; + tmp[0] = ' '; + os_memcpy(tmp + 1, cmd, len + 1); + cmd = tmp; + } wpa_printf(MSG_DEBUG, "DPP: Set configurator parameters: %s", cmd); @@ -4693,7 +4706,7 @@ int dpp_set_configurator(struct dpp_global *dpp, void *msg_ctx, if (!auth->conf) { wpa_printf(MSG_INFO, "DPP: Could not find the specified configurator"); - return -1; + goto fail; } } @@ -4712,9 +4725,12 @@ int dpp_set_configurator(struct dpp_global *dpp, void *msg_ctx, if (dpp_configuration_parse(auth, cmd) < 0) { wpa_msg(msg_ctx, MSG_INFO, "DPP: Failed to set configurator parameters"); - return -1; + goto fail; } - return 0; + ret = 0; +fail: + os_free(tmp); + return ret; }