Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 6 Jun 2014 13:37:40 +0000 (UTC)
From:      Jilles Tjoelker <jilles@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org
Subject:   svn commit: r267161 - stable/10/lib/libc/stdlib
Message-ID:  <201406061337.s56Dbet4040947@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: jilles
Date: Fri Jun  6 13:37:40 2014
New Revision: 267161
URL: http://svnweb.freebsd.org/changeset/base/267161

Log:
  MFC r264417: realpath(): Properly fail "." or ".." components after
  non-directories.
  
  If realpath() is called on pathnames like "/dev/null/." or "/dev/null/..",
  it should fail with [ENOTDIR]. Pathnames like "/dev/null/" already failed as
  they should.
  
  Also, put the check for non-directories after lstatting the previous
  component instead of when the empty component (consecutive or trailing
  slashes) is detected, saving an lstat() call and some lines of code.
  
  PR:		82980

Modified:
  stable/10/lib/libc/stdlib/realpath.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/lib/libc/stdlib/realpath.c
==============================================================================
--- stable/10/lib/libc/stdlib/realpath.c	Fri Jun  6 13:36:52 2014	(r267160)
+++ stable/10/lib/libc/stdlib/realpath.c	Fri Jun  6 13:37:40 2014	(r267161)
@@ -132,26 +132,7 @@ realpath(const char * __restrict path, c
 			resolved[resolved_len] = '\0';
 		}
 		if (next_token[0] == '\0') {
-			/*
-			 * Handle consequential slashes.  The path
-			 * before slash shall point to a directory.
-			 *
-			 * Only the trailing slashes are not covered
-			 * by other checks in the loop, but we verify
-			 * the prefix for any (rare) "//" or "/\0"
-			 * occurrence to not implement lookahead.
-			 */
-			if (lstat(resolved, &sb) != 0) {
-				if (m)
-					free(resolved);
-				return (NULL);
-			}
-			if (!S_ISDIR(sb.st_mode)) {
-				if (m)
-					free(resolved);
-				errno = ENOTDIR;
-				return (NULL);
-			}
+			/* Handle consequential slashes. */
 			continue;
 		}
 		else if (strcmp(next_token, ".") == 0)
@@ -236,6 +217,11 @@ realpath(const char * __restrict path, c
 				}
 			}
 			left_len = strlcpy(left, symlink, sizeof(left));
+		} else if (!S_ISDIR(sb.st_mode) && p != NULL) {
+			if (m)
+				free(resolved);
+			errno = ENOTDIR;
+			return (NULL);
 		}
 	}
 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201406061337.s56Dbet4040947>