Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F175721211
D59709.id187497.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
1 KB
Referenced Files
None
Subscribers
None
D59709.id187497.diff
View Options
diff --git a/bin/pwd/pwd.c b/bin/pwd/pwd.c
--- a/bin/pwd/pwd.c
+++ b/bin/pwd/pwd.c
@@ -33,33 +33,40 @@
#include <sys/param.h>
#include <sys/stat.h>
+#include <assert.h>
#include <err.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
#include <unistd.h>
static char *
getcwd_logical(void)
{
struct stat log, phy;
- char *pwd, *p, *q;
+ char *pwd, *s, *e;
/* $PWD is set and absolute */
if ((pwd = getenv("PWD")) == NULL || *pwd != '/')
return (NULL);
+
/* $PWD does not contain /./ or /../ */
- for (p = pwd; *p; p = q) {
- for (q = ++p; *q && *q != '/'; q++)
- /* nothing */;
- if ((*p == '.' && q == ++p) ||
- (*p == '.' && q == ++p))
+ e = pwd;
+ do {
+ assert(*e == '/');
+ s = e + 1; /* Beginning of next component (may point to NUL). */
+ /* Search for the component's end. */
+ e = strchrnul(s, '/');
+ if (s[0] == '.' && (s + 1 == e || (s[1] == '.' && s + 2 == e)))
return (NULL);
- }
+ } while (*e != '\0');
+
/* $PWD refers to the current directory */
if (stat(pwd, &log) != 0 || stat(".", &phy) != 0 ||
log.st_dev != phy.st_dev || log.st_ino != phy.st_ino)
return (NULL);
+
return (pwd);
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Tue, Oct 13, 7:06 PM (13 h, 34 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
39525219
Default Alt Text
D59709.id187497.diff (1 KB)
Attached To
Mode
D59709: pwd(1): De-obfuscate, style(9)
Attached
Detach File
Event Timeline
Log In to Comment