[PATCHv5 1/4] Fix prefix handling in ref iteration functions

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Josh Triplett <josh@xxxxxxxxxxxxxxxx>

The do_for_each_ref iteration function accepts a prefix and a trim, and
checks for the prefix on each ref before passing in that ref; it also
supports trimming off part of the ref before passing it.  Several
callers passed a prefix of "refs/" to filter out everything outside of
refs/, but a trim of 0 to avoid trimming off the "refs/".  However,
do_for_each_ref used trim as the length of the prefix to check, so it
ignored the "refs/" prefix entirely.  Switch to using prefixcmp,
checking the entire length of the prefix string, to properly support a
trim value different than the length of the prefix.

This fixes a bug where the ref iteration functions did not properly
ignore refs outside of "refs/".  The loose ref functions can never
supply such refs, and packed-refs would not normally include such refs,
but nothing prevents a packed-refs file from including refs outside of
"refs/".  (Confirmed by manually editing a packed-refs file.)

Commit by Josh Triplett and Jamey Sharp.

Signed-off-by: Josh Triplett <josh@xxxxxxxxxxxxxxxx>
Signed-off-by: Jamey Sharp <jamey@xxxxxxxxxxx>
---
 refs.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/refs.c b/refs.c
index e3c0511..003680f 100644
--- a/refs.c
+++ b/refs.c
@@ -584,7 +584,7 @@ int read_ref(const char *ref, unsigned char *sha1)
 static int do_one_ref(const char *base, each_ref_fn fn, int trim,
 		      int flags, void *cb_data, struct ref_list *entry)
 {
-	if (strncmp(base, entry->name, trim))
+	if (prefixcmp(entry->name, base))
 		return 0;
 
 	if (!(flags & DO_FOR_EACH_INCLUDE_BROKEN)) {
-- 
1.7.5.3

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]