aboutsummaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorMateusz Guzik <mjg@FreeBSD.org>2017-10-12 13:59:23 +0000
committerMateusz Guzik <mjg@FreeBSD.org>2017-10-12 13:59:23 +0000
commit92b25dcd615a84b272a7d127492f50ab11ef0134 (patch)
tree92fc0404e18637d8b1a41d52064c78279de1b925 /usr.bin
parent9aaf913e1325a8f324bb75be92c6824d01eb9e5a (diff)
downloadsrc-92b25dcd615a84b272a7d127492f50ab11ef0134.tar.gz
src-92b25dcd615a84b272a7d127492f50ab11ef0134.zip
xinstall: plug an infinite loop in directory creation
If stat continues to fail with ENOENT and mkdir with EEXIST the code wont finish. In particular this can show up when the target path follows through a symlink to a non-existent directory. Reported by: ae MFC after: 1 week
Notes
Notes: svn path=/head/; revision=324547
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/xinstall/xinstall.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/usr.bin/xinstall/xinstall.c b/usr.bin/xinstall/xinstall.c
index 44ab194f9fbb..16eba7768d89 100644
--- a/usr.bin/xinstall/xinstall.c
+++ b/usr.bin/xinstall/xinstall.c
@@ -1292,17 +1292,19 @@ install_dir(char *path)
{
char *p;
struct stat sb;
- int ch;
+ int ch, tried_mkdir;
for (p = path;; ++p)
if (!*p || (p != path && *p == '/')) {
+ tried_mkdir = 0;
ch = *p;
*p = '\0';
again:
if (stat(path, &sb) < 0) {
- if (errno != ENOENT)
+ if (errno != ENOENT || tried_mkdir)
err(EX_OSERR, "stat %s", path);
if (mkdir(path, 0755) < 0) {
+ tried_mkdir = 1;
if (errno == EEXIST)
goto again;
err(EX_OSERR, "mkdir %s", path);