#915 Validate POST /shell/run REST API parameters

This patch ensures that all required parameters are sent in the request.
master
Roberto Hueso Gómez 2019-11-05 10:41:34 +01:00 committed by OpenGnSys Support Team
parent ec5fe704cc
commit b403c7ae6c
1 changed files with 7 additions and 0 deletions

View File

@ -3295,6 +3295,7 @@ 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)
#define OG_REST_PARAM_RUN_CMD (1UL << 3)
static bool og_msg_params_validate(const struct og_msg_params *params,
const uint64_t flags)
@ -3643,6 +3644,8 @@ static int og_json_parse_run(json_t *element, struct og_msg_params *params)
snprintf(params->run_cmd, sizeof(params->run_cmd), "%s",
json_string_value(element));
params->flags |= OG_REST_PARAM_RUN_CMD;
return 0;
}
@ -3668,6 +3671,10 @@ static int og_cmd_run_post(json_t *element, struct og_msg_params *params)
break;
}
if (!og_msg_params_validate(params, OG_REST_PARAM_ADDR |
OG_REST_PARAM_RUN_CMD))
return -1;
for (i = 0; i < params->ips_array_len; i++) {
len = snprintf(iph + strlen(iph), sizeof(iph), "%s;",
params->ips_array[i]);