]> git.proxmox.com Git - mirror_lxc.git/commitdiff
setproctitle(): Handle potential NULL return from strrchr()
authorSolar Designer <solar@openwall.com>
Tue, 11 Apr 2023 13:29:46 +0000 (15:29 +0200)
committerSolar Designer <solar@openwall.com>
Tue, 11 Apr 2023 14:14:37 +0000 (16:14 +0200)
Signed-off-by: Solar Designer <solar@openwall.com>
src/lxc/initutils.c

index 444a65c8e48128486f86a71611b3b487104b3e8c..0a3f8fa8539f138e00584df1b44b5c15b2bb71f3 100644 (file)
@@ -245,20 +245,19 @@ int setproctitle(char *title)
        /*
         * executable names may contain spaces, so we search backwards for the
         * ), which is the kernel's marker for "end of executable name". this
-        * skips the first two fields.
+        * puts the pointer at the end of the second field.
         */
-       buf_ptr = strrchr(buf, ')')+2;
+       buf_ptr = strrchr(buf, ')');
+       if (!buf_ptr)
+               return -1;
 
-       /* Skip the next 23 fields, column 26-28 are start_code, end_code,
-        * and start_stack */
-       buf_ptr = strchr(buf_ptr, ' ');
-       for (i = 0; i < 22; i++) {
+       /* Skip the space and the next 23 fields, column 26-28 are start_code,
+         * end_code, and start_stack */
+       for (i = 0; i < 24; i++) {
+               buf_ptr = strchr(buf_ptr + 1, ' ');
                if (!buf_ptr)
                        return -1;
-               buf_ptr = strchr(buf_ptr + 1, ' ');
        }
-       if (!buf_ptr)
-               return -1;
 
        i = sscanf(buf_ptr, "%" PRIu64 " %" PRIu64 " %" PRIu64, &start_code, &end_code, &start_stack);
        if (i != 3)
@@ -266,14 +265,11 @@ int setproctitle(char *title)
 
        /* Skip the next 19 fields, column 45-51 are start_data to arg_end */
        for (i = 0; i < 19; i++) {
+               buf_ptr = strchr(buf_ptr + 1, ' ');
                if (!buf_ptr)
                        return -1;
-               buf_ptr = strchr(buf_ptr + 1, ' ');
        }
 
-       if (!buf_ptr)
-               return -1;
-
        i = sscanf(buf_ptr, "%" PRIu64 " %" PRIu64 " %" PRIu64 " %*u %*u %" PRIu64 " %" PRIu64, &start_data,
                   &end_data, &start_brk, &env_start, &env_end);
        if (i != 5)