Re: What's cooking in git.git (Aug 2022, #08; Wed, 24)
- From
Jeff King <peff@peff.net>
- Date
- Aug 25, 2022, 10:04 UTC
- Message-ID
- <YwdJRRuST2SP8ZT7@coredump.intra.peff.net>
- In-Reply-To
- <xmqqa67s5275.fsf@gitster.g>
On Wed, Aug 24, 2022 at 10:20:30PM -0700, Junio C Hamano wrote:
Show 18 quoted lines
> * sy/mv-out-of-cone (2022-08-10) 9 commits > (merged to 'next' on 2022-08-17 at 2316d9ce4d) > + mv: check overwrite for in-to-out move > + advice.h: add advise_on_moving_dirty_path() > + mv: cleanup empty WORKING_DIRECTORY > + mv: from in-cone to out-of-cone > + mv: remove BOTH from enum update_mode > + mv: check if <destination> is a SKIP_WORKTREE_DIR > + mv: free the with_slash in check_dir_in_index() > + mv: rename check_dir_in_index() to empty_dir_has_sparse_contents() > + t7002: add tests for moving from in-cone to out-of-cone > > "git mv A B" in a sparsely populated working tree can be asked to > move a path from a directory that is "in cone" to another directory > that is "out of cone". Handling of such a case has been improved. > > Will merge to 'master'. > source: <20220809120910.2021413-1-shaoxuan.yuan02@gmail.com>
This topic (and now 'next') segfaults with SANITIZE=address in t7001. The problem is running:
git mv path1/path2/ .
The "." in the destination is normalized to the empty string by internal_prefix_pathspec(). But commit c08830de41 (mv: check if <destination> is a SKIP_WORKTREE_DIR, 2022-08-09) then calls add_slash() on the result, and it isn't prepared to see an empty string.
This makes the problem go away:
diff --git a/builtin/mv.c b/builtin/mv.c index 11aea7b4db..6c6385dbb5 100644 --- a/builtin/mv.c +++ b/builtin/mv.c @@ -72,7 +72,7 @@ static const char **internal_prefix_pathspec(const char *prefix, static const char *add_slash(const char *path) { size_t len = strlen(path); - if (path[len - 1] != '/') { + if (len && path[len - 1] != '/') { char *with_slash = xmalloc(st_add(len, 2)); memcpy(with_slash, path, len); with_slash[len++] = '/'; but I didn't follow the topic well enough to know if there's anything subtle (i.e., I'm not sure why we need the slash in the first place, and whether "./" would be more appropriate, etc). So punting to folks who were involved. :) -Peff