git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 1/3] difftool: sanitize $workdir as early as possible

From
David Aguilar <davvid@gmail.com>
Date
Dec 9, 2016, 08:58 UTC
Message-ID
<20161209085848.10929-1-davvid@gmail.com>

The double-slash fixup on the $workdir variable was being performed just-in-time to avoid double-slashes in symlink targets, but the rest of the code was silently using paths with embedded "//" in them.

A recent user-reported error message contained double-slashes. Eliminate the issue by sanitizing inputs as soon as they arrive.

Signed-off-by: David Aguilar <davvid@gmail.com>
---
 git-difftool.perl | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/git-difftool.perl b/git-difftool.perl
index 959822d5f3..17c336321f 100755
--- a/git-difftool.perl
+++ b/git-difftool.perl
@@ -224,9 +224,7 @@ EOF
 	delete($ENV{GIT_INDEX_FILE});
 
 	# Changes in the working tree need special treatment since they are
-	# not part of the index. Remove any trailing slash from $workdir
-	# before starting to avoid double slashes in symlink targets.
-	$workdir =~ s|/$||;
+	# not part of the index.
 	for my $file (@working_tree) {
 		my $dir = dirname($file);
 		unless (-d "$rdir/$dir") {
@@ -389,6 +387,7 @@ sub dir_diff
 	my $repo = Git->repository();
 	my $repo_path = $repo->repo_path();
 	my $workdir = $repo->wc_path();
+	$workdir =~ s|/$||; # Avoid double slashes in symlink targets
 	my ($a, $b, $tmpdir, @worktree) = setup_dir_diff($workdir, $symlinks);
 
 	if (defined($extcmd)) {
-- 
2.11.0.26.gb65c994
Next: David Aguilar
Message 1 of 5 in “difftool: sanitize $workdir as early as possible”
  1. 1/3 difftool: sanitize $workdir as early as possibleDavid Aguilar, Dec 9, 2016
  2. 3/3 difftool: rename variables for consistencyDavid Aguilar, Dec 9, 2016
  3. 2/3 difftool: chdir as early as possibleDavid Aguilar, Dec 9, 2016
  4. Junio C HamanoDec 9, 2016
  5. David AguilarDec 10, 2016

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.