]> git.ipfire.org Git - thirdparty/libbsd.git/commitdiff
Fix handling of non-contiguous argv + envp in setproctitle()
authorGuillem Jover <guillem@hadrons.org>
Sun, 16 Jul 2017 22:57:07 +0000 (00:57 +0200)
committerGuillem Jover <guillem@hadrons.org>
Sun, 16 Jul 2017 22:58:06 +0000 (00:58 +0200)
The two arrays might not reference contiguous memory, and assuming they
are does break at least now on GNU/Hurd, which contains an unmapped
memory block between the memory used by the two arrays.

Just check that each element is strictly after the previous one, so that
we know there are no unmapped memory blocks inbetween.

src/setproctitle.c

index c18c61c9cdff517e3c14af9587095cece6d1bb57..038ac7d535f0b60e0be4818d73e23bc788b007c2 100644 (file)
@@ -173,14 +173,14 @@ setproctitle_init(int argc, char *argv[], char *envp[])
        end = nul + 1;
 
        for (i = 0; i < argc || (i >= argc && argv[i]); i++) {
-               if (argv[i] == NULL || argv[i] < end)
+               if (argv[i] == NULL || argv[i] != end)
                        continue;
 
                end = argv[i] + strlen(argv[i]) + 1;
        }
 
        for (i = 0; envp[i]; i++) {
-               if (envp[i] < end)
+               if (envp[i] != end)
                        continue;
 
                end = envp[i] + strlen(envp[i]) + 1;