common: ipc_single_command can return NULL

Especially printf's %s with NULL value is undefined behavior.
This commit is contained in:
Tobias Stoeckmann 2021-05-07 21:27:33 +02:00
parent 06ab0d166a
commit 3e69928f13
4 changed files with 22 additions and 5 deletions

View file

@ -478,6 +478,14 @@ int main(int argc, char **argv) {
ipc_set_recv_timeout(socketfd, timeout);
size_t len = strlen(command);
char *resp = ipc_single_command(socketfd, type, command, &len);
if (resp == NULL) {
if (!quiet) {
sway_log(SWAY_ERROR, "Failed to receive reply");
}
close(socketfd);
free(socket_path);
return 1;
}
// pretty print the json
json_object *obj = json_tokener_parse(resp);