From 489421b9e763865881df614a3ef550b289409677 Mon Sep 17 00:00:00 2001 From: Érico Rolim Date: Thu, 22 Oct 2020 03:47:15 -0300 Subject: imv, ipc: improve error checking for ipc creation. Since this isn't essential functionality, it's ok to simply not provide it. In cases where XDG_RUNTIME_DIR was empty (but not unset) or set to a directory where the user didn't have write permissions, socket creation would fail and lead to segmentation faults in imv, due to the return value of imv_ipc_create() not being checked. --- src/imv.c | 4 +++- src/ipc.c | 3 +++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/imv.c b/src/imv.c index 2a78012..34bfc54 100644 --- a/src/imv.c +++ b/src/imv.c @@ -533,7 +533,9 @@ struct imv *imv_create(void) imv->console = imv_console_create(); imv_console_set_command_callback(imv->console, &command_callback, imv); imv->ipc = imv_ipc_create(); - imv_ipc_set_command_callback(imv->ipc, &command_callback, imv); + if (imv->ipc) { + imv_ipc_set_command_callback(imv->ipc, &command_callback, imv); + } imv->title_text = strdup( "imv - [${imv_current_index}/${imv_file_count}]" " [${imv_width}x${imv_height}] [${imv_scale}%]" diff --git a/src/ipc.c b/src/ipc.c index 180bf2b..565777c 100644 --- a/src/ipc.c +++ b/src/ipc.c @@ -92,6 +92,9 @@ struct imv_ipc *imv_ipc_create(void) } struct imv_ipc *ipc = calloc(1, sizeof *ipc); + if (ipc == NULL) { + return NULL; + } ipc->fd = sockfd; pthread_t thread; -- cgit v1.2.3