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

[PATCH v2 4/4] dir: revert work-around for retired dangerous behavior

From
Eric Sunshine <sunshine@sunshineco.com>
Date
Sep 17, 2013, 07:06 UTC
Message-ID
<1379401577-36799-5-git-send-email-sunshine@sunshineco.com>
In-Reply-To
<1379401577-36799-1-git-send-email-sunshine@sunshineco.com>

directory_exists_in_index_icase() dangerously assumed that it could access one character beyond the end of its directory argument, and that that character would unconditionally be '/'. 2eac2a4c (ls-files -k: a directory only can be killed if the index has a non-directory, 2013-08-15) added a caller which did not respect this undocumented assumption, and 680be044 (dir.c::test_one_path(): work around directory_exists_in_index_icase() breakage, 2013-08-23) added a work-around which temporarily appends a '/' before invoking directory_exists_in_index_icase().

Since the dangerous behavior of directory_exists_in_index_icase() has been eliminated, the work-around is now redundant, so retire it (but not the tests added by the same commit).

Signed-off-by: Eric Sunshine <sunshine@sunshineco.com>
---
 dir.c | 18 +++---------------
 1 file changed, 3 insertions(+), 15 deletions(-)
diff --git a/dir.c b/dir.c
index fccd479..23b6de4 100644
--- a/dir.c
+++ b/dir.c
@@ -1160,21 +1160,9 @@ static enum path_treatment treat_one_path(struct dir_struct *dir,
 	 */
 	if ((dir->flags & DIR_COLLECT_KILLED_ONLY) &&
 	    (dtype == DT_DIR) &&
-	    !has_path_in_index) {
-		/*
-		 * NEEDSWORK: directory_exists_in_index_icase()
-		 * assumes that one byte past the given path is
-		 * readable and has '/', which needs to be fixed, but
-		 * until then, work it around in the caller.
-		 */
-		strbuf_addch(path, '/');
-		if (directory_exists_in_index(path->buf, path->len - 1) ==
-		    index_nonexistent) {
-			strbuf_setlen(path, path->len - 1);
-			return path_none;
-		}
-		strbuf_setlen(path, path->len - 1);
-	}
+	    !has_path_in_index &&
+	    (directory_exists_in_index(path->buf, path->len) == index_nonexistent))
+		return path_none;
 
 	exclude = is_excluded(dir, path->buf, &dtype);
 
-- 
1.8.4.535.g7b94f8e
Previous: Eric SunshineNext: Junio C Hamano
Message 5 of 6 in “stop storing trailing slash in dir-hash”
  1. 0/4 stop storing trailing slash in dir-hashEric Sunshine, Sep 17, 2013
  2. 1/4 name-hash: refactor polymorphic index_name_exists()Eric Sunshine, Sep 17, 2013
  3. 2/4 employ new explicit "exists in index?" APIEric Sunshine, Sep 17, 2013
  4. 3/4 name-hash: stop storing trailing '/' on paths in index_state.dir_hashEric Sunshine, Sep 17, 2013
  5. 4/4 dir: revert work-around for retired dangerous behaviorEric Sunshine, Sep 17, 2013
  6. Junio C HamanoSep 17, 2013

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.