diff options
| author | Bryan Drewery <bdrewery@FreeBSD.org> | 2017-05-09 19:15:11 +0000 |
|---|---|---|
| committer | Bryan Drewery <bdrewery@FreeBSD.org> | 2017-05-09 19:15:11 +0000 |
| commit | 753bf53655cbaaba64de4993f57fb01aace1403f (patch) | |
| tree | 3bf14245fff8e855b4ca76fecb4e6832453540e7 /usr.bin/xinstall | |
| parent | d78fbfb3f744d50b2b78195a185f48b26eb8fab9 (diff) | |
Notes
Diffstat (limited to 'usr.bin/xinstall')
| -rw-r--r-- | usr.bin/xinstall/xinstall.c | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/usr.bin/xinstall/xinstall.c b/usr.bin/xinstall/xinstall.c index 5a51d97c1aa71..44ab194f9fbb7 100644 --- a/usr.bin/xinstall/xinstall.c +++ b/usr.bin/xinstall/xinstall.c @@ -667,7 +667,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; if (*from_name != '/') { /* this is already a relative link */ @@ -685,7 +685,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. */ @@ -693,9 +696,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++) |
