]> git.mdlowis.com Git - proto/labwc.git/commitdiff
src/config/session.c: Handle allocation failures
authorConsolatis <35009135+Consolatis@users.noreply.github.com>
Thu, 28 Jul 2022 09:03:50 +0000 (11:03 +0200)
committerJohan Malm <johanmalm@users.noreply.github.com>
Fri, 29 Jul 2022 05:45:24 +0000 (06:45 +0100)
Reported-by: @heroin-moose
src/config/session.c

index cadb6834bb67b5d2451ac13d7fb556ae69b95380..f861e78501d319341dfcd8b057aa4e81497c7e89 100644 (file)
@@ -79,6 +79,9 @@ build_path(const char *dir, const char *filename)
        }
        int len = strlen(dir) + strlen(filename) + 2;
        char *buffer = calloc(1, len);
+       if (!buffer) {
+               return NULL;
+       }
        strcat(buffer, dir);
        strcat(buffer, "/");
        strcat(buffer, filename);
@@ -101,16 +104,24 @@ update_activation_env(const char *env_keys)
        const char *systemd = "systemctl --user import-environment ";
 
        cmd = calloc(1, strlen(dbus) + strlen(env_keys) + 1);
-       strcat(cmd, dbus);
-       strcat(cmd, env_keys);
-       spawn_async_no_shell(cmd);
-       free(cmd);
+       if (!cmd) {
+               wlr_log(WLR_ERROR, "Failed to allocate memory for dbus env update");
+       } else {
+               strcat(cmd, dbus);
+               strcat(cmd, env_keys);
+               spawn_async_no_shell(cmd);
+               free(cmd);
+       }
 
        cmd = calloc(1, strlen(systemd) + strlen(env_keys) + 1);
-       strcat(cmd, systemd);
-       strcat(cmd, env_keys);
-       spawn_async_no_shell(cmd);
-       free(cmd);
+       if (!cmd) {
+               wlr_log(WLR_ERROR, "Failed to allocate memory for systemd env update");
+       } else {
+               strcat(cmd, systemd);
+               strcat(cmd, env_keys);
+               spawn_async_no_shell(cmd);
+               free(cmd);
+       }
 }
 
 void
@@ -148,6 +159,10 @@ session_autostart_init(const char *dir)
        wlr_log(WLR_INFO, "run autostart file %s", autostart);
        int len = strlen(autostart) + 4;
        char *cmd = calloc(1, len);
+       if (!cmd) {
+               wlr_log(WLR_ERROR, "Failed to allocate memory for autostart command");
+               goto out;
+       }
        strcat(cmd, "sh ");
        strcat(cmd, autostart);
        spawn_async_no_shell(cmd);