summaryrefslogtreecommitdiffstats
path: root/usr.bin
diff options
context:
space:
mode:
authormjg <mjg@FreeBSD.org>2017-12-31 03:17:28 +0000
committermjg <mjg@FreeBSD.org>2017-12-31 03:17:28 +0000
commit046f82c455b766a4a1d1a23203499211a06badcb (patch)
treea2be8860a0c357d744ac3598cb7c20c8e5d7c0fb /usr.bin
parent365d37952cdc329ebd1ff94205b934e29af6c472 (diff)
downloadFreeBSD-src-046f82c455b766a4a1d1a23203499211a06badcb.zip
FreeBSD-src-046f82c455b766a4a1d1a23203499211a06badcb.tar.gz
MFC r324547:
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.
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 44ab194..16eba77 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);
OpenPOWER on IntegriCloud