summaryrefslogtreecommitdiffstats
path: root/usr.bin
diff options
context:
space:
mode:
authorbdrewery <bdrewery@FreeBSD.org>2017-05-09 19:14:26 +0000
committerbdrewery <bdrewery@FreeBSD.org>2017-05-09 19:14:26 +0000
commitb80e7c9dc20cd43922c7a5b28fd20b694de86e7a (patch)
tree43fd7fa19422f22a40ff037924406d8f6e63f018 /usr.bin
parentcaeb6c9d8924e536cb8baca9b02352b9d53bcb2c (diff)
downloadFreeBSD-src-b80e7c9dc20cd43922c7a5b28fd20b694de86e7a.zip
FreeBSD-src-b80e7c9dc20cd43922c7a5b28fd20b694de86e7a.tar.gz
MFC r303450:
Pull a copy of the input string before calling basename() and dirname().
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/xinstall/xinstall.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/usr.bin/xinstall/xinstall.c b/usr.bin/xinstall/xinstall.c
index c4397a6..8595145 100644
--- a/usr.bin/xinstall/xinstall.c
+++ b/usr.bin/xinstall/xinstall.c
@@ -669,7 +669,7 @@ makelink(const char *from_name, const char *to_name,
}
if (dolink & LN_RELATIVE) {
- char *cp, *d, *s;
+ char *to_name_copy, *cp, *d, *s;
/* Resolve pathnames. */
if (realpath(from_name, src) == NULL)
@@ -679,7 +679,10 @@ makelink(const char *from_name, const char *to_name,
* The last component of to_name may be a symlink,
* so use realpath to resolve only the directory.
*/
- cp = dirname(to_name);
+ 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. */
@@ -687,9 +690,11 @@ makelink(const char *from_name, const char *to_name,
if (strlcat(dst, "/", sizeof(dst)) > sizeof(dst))
errx(1, "resolved pathname too long");
}
- cp = basename(to_name);
+ strcpy(to_name_copy, to_name);
+ cp = basename(to_name_copy);
if (strlcat(dst, cp, sizeof(dst)) > sizeof(dst))
errx(1, "resolved pathname too long");
+ free(to_name_copy);
/* Trim common path components. */
for (s = src, d = dst; *s == *d; s++, d++)
OpenPOWER on IntegriCloud