void-linux/void-runit

vlogger: Potential crash on startup

jdbourbaki opened this issue · 3 comments

I haven't tried to produce this crash, but I did notice that there is a potential segfault in these lines of code:

if ((p = strrchr(pwd, '/')) && strncmp(p+1, "log", 3) == 0 &&
(*p = '\0', (p = strrchr(pwd, '/'))) && (*(p+1) != '\0')) {

If someone decided to exec vlogger as ./run from within the directory '/log' then the second call to strrchr above should pass an empty string as the first argument and so this second invocation of strrchr should return a null pointer and then the code (*(p+1) != '\0')) at the end would be expected to segfault.

If strrchr returns NULL, the && is false and shortcuts.

Ah, indeed; I should have read the parentheses a bit more carefully.

My apologies.

q66 commented

arguably writing this more verbosely would be more readable and less prone to having actual bugs though :p