backlight: Prevent dereference of potential NULL argv
authorChris Wilson <chris@chris-wilson.co.uk>
Thu, 17 Jul 2014 15:14:16 +0000 (16:14 +0100)
committerChris Wilson <chris@chris-wilson.co.uk>
Thu, 17 Jul 2014 15:14:16 +0000 (16:14 +0100)
commit3140d72826b5227f7f7ac9a428faa4bcfd4b377b
tree085f8745071adfbd1d4b05fc1a6d7bc22efdf8b9
parentbcd09ff6eb76bc4df046ece4da29b1455fed8dff
backlight: Prevent dereference of potential NULL argv

Adam Sampson spotted that

"It's possible (but not very sensible) to exec a program with an empty
argument list, so argv[0] is not necessarily a valid pointer. For
example:

$ cat exec0.c

int main(int argc, char *argv[]) {
    char *empty[1] = { NULL };
    execvp(argv[1], empty);
    perror("execvp");
    return 1;
}
$ ./exec0 /usr/libexec/xf86-video-intel-backlight-helper
Usage: (null) <iface>
"

He sensibly suggested that we hardcode the program name to avoid the
NULL dereference. Being the paranoid type, we should also be careful not
to write to any file descriptors outside of our control (i.e. stderr),
so disable the messages unless we are debugging.

Reported-by: Adam Sampson
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
tools/backlight_helper.c