threads / patch / 52119

patchmingw: avoid a buffer overrun in needs_hiding()

Subject: [PATCH 0/1] mingw: avoid a buffer overrun in needs_hiding()

## tl;dr

2 messages between Oct 25, 2019 and Oct 25, 2019. Diffs are folded; open one to read it.

replies: 1people: 1as markdown or json

Johannes Schindelin via GitGitGadget· Oct 25, 2019, 14:13 UTC · lore

On Unix, files are hidden from the output of ls by default when their names start with a .. On Windows, there is an explicit flag that you need to set.

It is quite uncommon, though, to hide all of the "dot files" on Windows, which is why Git hides only .git by default, and it has a setting to override this default (core.hideDotFiles).

The code to determine whether that flag needs to be set for a given file had a buffer overrun, though, if the path that was passed into the function ended with a directory separator. This patch fixes this.

The original contribution by Alex is over at https://github.com/gitgitgadget/git/pull/414, and I worked with him to evolve it into the current version.

Cc: Alexandr Miloslavskiy alexandr.miloslavskiy@syntevo.com
[alexandr.miloslavskiy@syntevo.com]
Johannes Schindelin (1):
  mingw: avoid a buffer overrun in `needs_hiding()`
 compat/mingw.c | 2 ++
 1 file changed, 2 insertions(+)
base-commit: 566a1439f6f56c2171b8853ddbca0ad3f5098770
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-427%2Fdscho%2Ffix-needs-hiding-buffer-overrun-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-427/dscho/fix-needs-hiding-buffer-overrun-v1
Pull-Request: https://github.com/gitgitgadget/git/pull/427
-- 
gitgitgadget
Johannes Schindelin via GitGitGadget· Oct 25, 2019, 14:13 UTC · re: Johannes Schindelin via GitGitGadget · lore

[PATCH 1/1] mingw: avoid a buffer overrun in `needs_hiding()`

From: Johannes Schindelin <johannes.schindelin@gmx.de>

When this function is passed a path with a trailing slash, it runs right over the end of that path.

Let's fix this.
Co-authored-by: Alexandr Miloslavskiy <alexandr.miloslavskiy@syntevo.com>
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
 compat/mingw.c | 2 ++
 1 file changed, 2 insertions(+)
Show changes to compat/mingw.c +2 −0
diff --git a/compat/mingw.c b/compat/mingw.c
index 6b765d936c..fe609239dd 100644
--- a/compat/mingw.c
+++ b/compat/mingw.c
@@ -363,6 +363,8 @@ static inline int needs_hiding(const char *path)
 			/* ignore trailing slashes */
 			if (*path)
 				basename = path;
+			else
+				break;
 		}
 
 	if (hide_dotfiles == HIDE_DOTFILES_TRUE)
-- 
gitgitgadget

← back to recent threads