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

@ -344,6 +344,9 @@ bool ipc_get_workspaces(struct swaybar *bar) {
size_t len = 0;
char *res = ipc_single_command(bar->ipc_socketfd,
IPC_GET_WORKSPACES, NULL, &len);
if (res == NULL) {
return false;
}
json_object *results = json_tokener_parse(res);
if (!results) {
free(res);
@ -418,7 +421,7 @@ bool ipc_initialize(struct swaybar *bar) {
size_t len = strlen(bar->id);
char *res = ipc_single_command(bar->ipc_socketfd,
IPC_GET_BAR_CONFIG, bar->id, &len);
if (!ipc_parse_config(bar->config, res)) {
if (res == NULL || !ipc_parse_config(bar->config, res)) {
free(res);
return false;
}