summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOpenGnSys Support Team <soporte-og@soleta.eu>2024-07-15 11:53:15 +0200
committerOpenGnSys Support Team <soporte-og@soleta.eu>2024-07-15 11:56:26 +0200
commit88330288e66320df4b243ce77ca90bf3f91e66d7 (patch)
tree8c57550faf91c78fd6aef6d91ecbf6e963135dd3
parent3f02d64104fede43074df2e0f229f514d24363fe (diff)
client: fortify check for mandatory cmd json field in shell/output
Revisit 6cbe69e89e71 ("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.
-rw-r--r--src/client.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/src/client.c b/src/client.c
index 4876f78..0d898d7 100644
--- a/src/client.c
+++ b/src/client.c
@@ -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;