Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F137967498
D44743.id136931.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
D44743.id136931.diff
View Options
diff --git a/usr.bin/xinstall/xinstall.c b/usr.bin/xinstall/xinstall.c
--- a/usr.bin/xinstall/xinstall.c
+++ b/usr.bin/xinstall/xinstall.c
@@ -657,8 +657,10 @@
makelink(const char *from_name, const char *to_name,
const struct stat *target_sb)
{
- char src[MAXPATHLEN], dst[MAXPATHLEN], lnk[MAXPATHLEN];
- struct stat to_sb;
+ char src[MAXPATHLEN], dst[MAXPATHLEN], lnk[MAXPATHLEN];
+ char *to_name_copy, *d, *ld, *ls, *s;
+ const char *base, *dir;
+ struct stat to_sb;
/* Try hard links first. */
if (dolink & (LN_HARD|LN_MIXED)) {
@@ -719,8 +721,6 @@
}
if (dolink & LN_RELATIVE) {
- char *to_name_copy, *cp, *d, *ld, *ls, *s;
-
if (*from_name != '/') {
/* this is already a relative link */
do_symlink(from_name, to_name, target_sb);
@@ -740,17 +740,18 @@
to_name_copy = strdup(to_name);
if (to_name_copy == NULL)
err(EX_OSERR, "%s: strdup", to_name);
- cp = dirname(to_name_copy);
- if (realpath(cp, dst) == NULL)
- err(EX_OSERR, "%s: realpath", cp);
- /* .. and add the last component. */
- if (strcmp(dst, "/") != 0) {
- if (strlcat(dst, "/", sizeof(dst)) > sizeof(dst))
+ base = basename(to_name_copy);
+ if (base > to_name_copy + 1) {
+ dir = dirname(to_name_copy);
+ if (realpath(dir, dst) == NULL)
+ err(EX_OSERR, "%s: realpath", dir);
+ if (strcmp(dst, "/") != 0 &&
+ strlcat(dst, "/", sizeof(dst)) > sizeof(dst))
errx(1, "resolved pathname too long");
+ } else {
+ (void)strlcpy(dst, "/", sizeof(dst));
}
- strcpy(to_name_copy, to_name);
- cp = basename(to_name_copy);
- if (strlcat(dst, cp, sizeof(dst)) > sizeof(dst))
+ if (strlcat(dst, base, sizeof(dst)) > sizeof(dst))
errx(1, "resolved pathname too long");
free(to_name_copy);
@@ -834,6 +835,8 @@
} else {
devnull = 1;
}
+ if (*to_name == '\0')
+ errx(EX_USAGE, "target cannot be an empty string");
target = (lstat(to_name, &to_sb) == 0);
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Fri, Nov 28, 6:29 PM (17 h, 39 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
26294722
Default Alt Text
D44743.id136931.diff (1 KB)
Attached To
Mode
D44743: install: Simplify path construction.
Attached
Detach File
Event Timeline
Log In to Comment