client: fortify check for mandatory cmd json field in shell/output

Revisit 6cbe69e89e ("rest: add cmd to shell/output") to reject response with
no 'cmd' field, otherwise strdup() crashes when dealing with NULL string.

Set retcode to zero, otherwise this value remains uninitialized if no retcode
json field is provided by the client.
master
OpenGnSys Support Team 2024-07-15 11:53:15 +02:00
parent 3f02d64104
commit 88330288e6
1 changed files with 2 additions and 2 deletions

View File

@ -172,7 +172,7 @@ static int og_resp_probe(struct og_client *cli, json_t *data)
static int og_resp_shell_run(struct og_client *cli, json_t *data)
{
const char *cmd = NULL, *output = NULL;
uint32_t retcode;
uint32_t retcode = 0;
const char *key;
json_t *value;
int err = -1;
@ -197,7 +197,7 @@ static int og_resp_shell_run(struct og_client *cli, json_t *data)
}
if (!output) {
if (!cmd || !output) {
syslog(LOG_ERR, "%s:%d: malformed json response\n",
__FILE__, __LINE__);
return -1;