]> git.ipfire.org Git - thirdparty/systemd.git/commit
sd-device: replace lstat() + open() with open(O_NOFOLLOW) 5390/head
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Sun, 19 Feb 2017 19:17:19 +0000 (14:17 -0500)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Mon, 20 Feb 2017 21:03:42 +0000 (16:03 -0500)
commit2fa4861ad5a203bff604cac660136834e3b70108
tree890482030d556a19efd046c5b1b2171a8de30528
parent0357fa0dcea7e6bd599fbd5b6aac6df9b6961c8e
sd-device: replace lstat() + open() with open(O_NOFOLLOW)

Coverity was complaining about TOCTOU (CID #745806). Indeed, it seems better
to open the file and avoid the stat altogether:

- O_NOFOLLOW means we'll get ELOOP, which we can translate to EINVAL as before,
- similarly, open(O_WRONLY) on a directory will fail with EISDIR,
- and finally, it makes no sense to check access mode ourselves: just let
  the kernel do it and propagate the error.

v2:
- fix memleak, don't clober input arg
src/libsystemd/sd-device/sd-device.c