Revert "initd: fix off-by-one error in mkdev.c"
authorNick Hainke <vincent@systemli.org>
Tue, 31 Aug 2021 09:09:18 +0000 (11:09 +0200)
committerDaniel Golle <daniel@makrotopia.org>
Tue, 31 Aug 2021 11:24:14 +0000 (12:24 +0100)
This reverts commit 8eb1d783cca6e0d501dd3a2f94262ffc36ae6482.

This line reads a symbolic link into the string buffer "buf".
len = readlink(buf2, buf, sizeof(buf));
The commit replaced now
buf[len] = 0;
with
buf[sizeof(buf) - 1] = '\0';

However, that does not work since readlink does not null-terminate
the string written into "buf" and  "buf[len] = 0" was used for that.

What happens if the buffer is to small?
"If the buf argument is not large enough to contain the link content,
the first bufsize bytes shall be placed in buf."
(Source: https://pubs.opengroup.org/onlinepubs/009695399/functions/readlink.htm)

Signed-off-by: Nick Hainke <vincent@systemli.org>
initd/mkdev.c

index 1c9c97ab8e0560e11fd5c56efc2d09c2244aae9d..44101aa12df5e5a102b626d2eb41f1a10a40e2ad 100644 (file)
@@ -86,7 +86,7 @@ static void find_devs(bool block)
                if (len <= 0)
                        continue;
 
-               buf[sizeof(buf) - 1] = '\0';
+               buf[len] = 0;
                if (!find_pattern(buf))
                        continue;