diff options
author | millert <> | 2002-01-12 16:24:35 +0000 |
---|---|---|
committer | millert <> | 2002-01-12 16:24:35 +0000 |
commit | ab193f788e40e3bc214a6c15e3bd5171dd7b163d (patch) | |
tree | d1c7be457e61521b79063c5dc7d1faa46f706a2c /src | |
parent | 561945e61a05b7541f45f80101c7c2b03f581f76 (diff) | |
download | openbsd-ab193f788e40e3bc214a6c15e3bd5171dd7b163d.tar.gz openbsd-ab193f788e40e3bc214a6c15e3bd5171dd7b163d.tar.bz2 openbsd-ab193f788e40e3bc214a6c15e3bd5171dd7b163d.zip |
If the user passes in "" as the string to resolve the lstat() will
fail anyway so check for that. Also convert "." to "" since that
way we avoid the lstat() (which we don't need) and the subsequent
chdir() and some dir checks.
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/libc/stdlib/realpath.c | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/src/lib/libc/stdlib/realpath.c b/src/lib/libc/stdlib/realpath.c index a6195c1dcb..061f1a7ef1 100644 --- a/src/lib/libc/stdlib/realpath.c +++ b/src/lib/libc/stdlib/realpath.c | |||
@@ -35,7 +35,7 @@ | |||
35 | */ | 35 | */ |
36 | 36 | ||
37 | #if defined(LIBC_SCCS) && !defined(lint) | 37 | #if defined(LIBC_SCCS) && !defined(lint) |
38 | static char *rcsid = "$OpenBSD: realpath.c,v 1.5 2001/06/27 00:58:56 lebel Exp $"; | 38 | static char *rcsid = "$OpenBSD: realpath.c,v 1.6 2002/01/12 16:24:35 millert Exp $"; |
39 | #endif /* LIBC_SCCS and not lint */ | 39 | #endif /* LIBC_SCCS and not lint */ |
40 | 40 | ||
41 | #include <sys/param.h> | 41 | #include <sys/param.h> |
@@ -70,6 +70,10 @@ realpath(path, resolved) | |||
70 | return (NULL); | 70 | return (NULL); |
71 | } | 71 | } |
72 | 72 | ||
73 | /* Convert "." -> "" to optimize away a needless lstat() and chdir() */ | ||
74 | if (path[0] == '.' && path[1] == '\0') | ||
75 | path = ""; | ||
76 | |||
73 | /* | 77 | /* |
74 | * Find the dirname and basename from the path to be resolved. | 78 | * Find the dirname and basename from the path to be resolved. |
75 | * Change directory to the dirname component. | 79 | * Change directory to the dirname component. |
@@ -98,7 +102,7 @@ loop: | |||
98 | p = resolved; | 102 | p = resolved; |
99 | 103 | ||
100 | /* Deal with the last component. */ | 104 | /* Deal with the last component. */ |
101 | if (lstat(p, &sb) == 0) { | 105 | if (*p != '\0' && lstat(p, &sb) == 0) { |
102 | if (S_ISLNK(sb.st_mode)) { | 106 | if (S_ISLNK(sb.st_mode)) { |
103 | if (++symlinks > MAXSYMLINKS) { | 107 | if (++symlinks > MAXSYMLINKS) { |
104 | errno = ELOOP; | 108 | errno = ELOOP; |