From: Michael Orlitzky Date: Mon, 26 Feb 2018 03:11:47 +0000 (-0500) Subject: Add safe_open() function to fix symlink traversal in non-terminal components. X-Git-Tag: v0.1.0~18 X-Git-Url: https://gitweb.michael.orlitzky.com/?a=commitdiff_plain;h=2dee89ff5a032f896d57a353c04525c506372669;hp=2dee89ff5a032f896d57a353c04525c506372669;p=apply-default-acl.git Add safe_open() function to fix symlink traversal in non-terminal components. The standard library provides lots of ways to avoid symlinks in the "baz" component of "foo/bar/baz", but very few (i.e. zero) ways to avoid them in the "bar" component. Of course, they're just as dangerous in either place, so it would be cool if we could ignore symlinks entirely. This commit adds a safe_open() function, which looks just like open() to the caller, but which starts at the root and calls openat() one component at-a-time. Thus if you use O_NOFOLLOW, nobody can trick you with an intermediate component: there are no intermediate components; it works one at-a-time. This slows things down a bit, but not fatally. ---