Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 9 May 2017 19:14:26 +0000 (UTC)
From:      Bryan Drewery <bdrewery@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org
Subject:   svn commit: r318096 - stable/10/usr.bin/xinstall
Message-ID:  <201705091914.v49JEQoN004813@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: bdrewery
Date: Tue May  9 19:14:26 2017
New Revision: 318096
URL: https://svnweb.freebsd.org/changeset/base/318096

Log:
  MFC r303450:
  
    Pull a copy of the input string before calling basename() and dirname().

Modified:
  stable/10/usr.bin/xinstall/xinstall.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/usr.bin/xinstall/xinstall.c
==============================================================================
--- stable/10/usr.bin/xinstall/xinstall.c	Tue May  9 19:01:57 2017	(r318095)
+++ stable/10/usr.bin/xinstall/xinstall.c	Tue May  9 19:14:26 2017	(r318096)
@@ -669,7 +669,7 @@ makelink(const char *from_name, const ch
 	}
 
 	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 ch
 		 * 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 ch
 			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++)



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201705091914.v49JEQoN004813>