Author: mjg
Date: Thu Oct 12 13:59:23 2017
New Revision: 324547
URL: https://svnweb.freebsd.org/changeset/base/324547

Log:
  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

Modified:
  head/usr.bin/xinstall/xinstall.c

Modified: head/usr.bin/xinstall/xinstall.c
==============================================================================
--- head/usr.bin/xinstall/xinstall.c    Thu Oct 12 08:27:57 2017        
(r324546)
+++ head/usr.bin/xinstall/xinstall.c    Thu Oct 12 13:59:23 2017        
(r324547)
@@ -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);
_______________________________________________
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to