From ec5fe704ccfe92a3dcbaf8ef15f214caa6de0357 Mon Sep 17 00:00:00 2001 From: Roberto Hueso Gómez Date: Tue, 5 Nov 2019 10:39:05 +0100 Subject: #915 Validate POST /wol REST API parameters This patch ensures that all required parameters are sent in the request. --- sources/ogAdmServer.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'sources/ogAdmServer.cpp') diff --git a/sources/ogAdmServer.cpp b/sources/ogAdmServer.cpp index f275abe..4d61a8a 100644 --- a/sources/ogAdmServer.cpp +++ b/sources/ogAdmServer.cpp @@ -3293,6 +3293,8 @@ struct og_msg_params { }; #define OG_REST_PARAM_ADDR (1UL << 0) +#define OG_REST_PARAM_MAC (1UL << 1) +#define OG_REST_PARAM_WOL_TYPE (1UL << 2) static bool og_msg_params_validate(const struct og_msg_params *params, const uint64_t flags) @@ -3541,12 +3543,16 @@ static int og_json_parse_target(json_t *element, struct og_msg_params *params) params->ips_array[params->ips_array_len] = json_string_value(value); + + params->flags |= OG_REST_PARAM_ADDR; } else if (!strcmp(key, "mac")) { if (json_typeof(value) != JSON_STRING) return -1; params->mac_array[params->ips_array_len] = json_string_value(value); + + params->flags |= OG_REST_PARAM_MAC; } } @@ -3592,6 +3598,8 @@ static int og_json_parse_type(json_t *element, struct og_msg_params *params) else if (!strcmp(type, "broadcast")) params->wol_type = "1"; + params->flags |= OG_REST_PARAM_WOL_TYPE; + return 0; } @@ -3615,6 +3623,11 @@ static int og_cmd_wol(json_t *element, struct og_msg_params *params) break; } + if (!og_msg_params_validate(params, OG_REST_PARAM_ADDR | + OG_REST_PARAM_MAC | + OG_REST_PARAM_WOL_TYPE)) + return -1; + if (!Levanta((char **)params->ips_array, (char **)params->mac_array, params->ips_array_len, (char *)params->wol_type)) return -1; -- cgit v1.2.3-18-g5258