Skip to contentSkip to conversation

Added a test for fetching remote tags when there is not tags.

PATCH New Väinö Järvelä 5 participants 10 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Added a test for fetching remote tags when there is not tags.

When a user runs "git fetch -t", git crashes when it doesn't find any tags on the remote repository.

---
 t/t5510-fetch.sh |   12 ++++++++++++
 1 files changed, 12 insertions(+), 0 deletions(-)
t/t5510-fetch.sh +12 -0
index 73a4e3c..40ebf2e 100755
@@ -67,6 +67,18 @@ test_expect_success "fetch test for-merge" '
 	cut -f -2 .git/FETCH_HEAD >actual &&
 	diff expected actual'
 
+test_expect_success 'fetch tags when there is no tags' '
+
+    cd "$D" &&
+
+    mkdir notags &&
+    cd notags &&
+    git init &&
+
+    git fetch -t ..
+
+'
+
 test_expect_success 'fetch following tags' '
 
 	cd "$D" &&
Signature · 1 line
1.5.3.4.1156.g5407-dirty
#1 lore raw

PATCH 1/1 Fixed crash in fetching remote tags when there is not tags.

---
 remote.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
remote.c +2 -0
index e7d735b..5e92378 100644
@@ -537,6 +537,8 @@ static int count_refspec_match(const char *pattern,
 
 static void tail_link_ref(struct ref *ref, struct ref ***tail)
 {
+	if (!ref) return;
+	
 	**tail = ref;
 	while (ref->next)
 		ref = ref->next;
Signature · 1 line
1.5.3.4.1156.g5407-dirty
#2 lore raw

Re: [PATCH] Fixed crash in fetching remote tags when there is not tags.

Hi,

These patches should have been numbered, sorry, The test patch was supposed be number 1 of 2.

The patches were done on top of next. The fix should be checked, as it's mostly a quick fix to get it to work, probably not the correct way to fix that bug, or is it?

--
Väinö

Quoted 26 lines · Väinö Järvelä
---
 remote.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
remote.c +2 -0
index e7d735b..5e92378 100644
@@ -537,6 +537,8 @@ static int count_refspec_match(const char  
 *pattern,
 
 static void tail_link_ref(struct ref *ref, struct ref ***tail)
 {
+	if (!ref) return;
+	
 	**tail = ref;
 	while (ref->next)

ref = ref->next;

Signature · 6 lines
1.5.3.4.1156.g5407-dirty

-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#3 lore raw

Re: [PATCH] Fixed crash in fetching remote tags when there is not tags.

Väinö Järvelä, Tue, Oct 09, 2007 12:52:01 +0200:

Quoted 8 lines

Hi,

These patches should have been numbered, sorry, The test patch was supposed be number 1 of 2.

The patches were done on top of next. The fix should be checked, as it's mostly a quick fix to get it to work, probably not the correct way to fix that bug, or is it?

Your test does not crash on my system and your fix is obviously bogus. Just take a look at the only call site of the tail_link_ref: ret cannot be NULL. alloc_ref will crash in memset, if this were the case.

If you can reproduce the crash reliably, try compiling git with -g and run it in your test with valgrind or gdb (assuming these are available to you).

#4 lore raw

Re: [PATCH] Fixed crash in fetching remote tags when there is not tags.

Quoted 3 lines · Alex Riesen

Your test does not crash on my system and your fix is obviously bogus. Just take a look at the only call site of the tail_link_ref: ret cannot be NULL. alloc_ref will crash in memset, if this were the case.

His work is almost certainly on top of next, which crashes reliably with the test and has an additional call site for tail_link_ref. Aside from some trailing whitespace in the patch, I think his fix is reasonable.

-Peff

#5 lore raw

Re: [PATCH] Fixed crash in fetching remote tags when there is not tags.

Jeff King, Wed, Oct 10, 2007 07:10:35 +0200:

Quoted 9 lines · Alex Riesen
Quoted 4 lines

Your test does not crash on my system and your fix is obviously bogus. Just take a look at the only call site of the tail_link_ref: ret cannot be NULL. alloc_ref will crash in memset, if this were the case.

His work is almost certainly on top of next, which crashes reliably with the test and has an additional call site for tail_link_ref. Aside from some trailing whitespace in the patch, I think his fix is reasonable.

Ach, I see.

Still, I'd suggest move the test into the caller, firstly because it is the only place that special. Also, I can't think of a proper reason to add a NULL ref to a reflist, and so the crashing tail_link_ref will help us find the callers which use tail_link_ref incorrectly (illogically too).

As the result of patter expansion can be NULL (empty pattern, as it seems), lets just check for it. I parked the patch below locally.

remote.c +2 -1
index 5e92378..58d63ed 100644
@@ -884,7 +884,8 @@ int get_fetch_map(struct ref *remote_refs,
 			    rm->peer_ref->name);
 	}
 
-	tail_link_ref(ref_map, tail);
+	if (ref_map)
+		tail_link_ref(ref_map, tail);
 
 	return 0;
 }
#6 lore raw

Re: [PATCH] Fixed crash in fetching remote tags when there is not tags.

Quoted 2 lines · Alex Riesen

Still, I'd suggest move the test into the caller, firstly because it is the only place that special. Also, I can't think of a proper reason

Yes, I agree with that. I came very close to suggesting it in my other mail, but then realized I had never even looked at the surrounding code, and I ought not to be making assessments of how that data structure should be used. But now there are two of us. :)

-Peff

#7 lore raw

Re: [PATCH] Fixed crash in fetching remote tags when there is not tags.

In reply to Alex Riesen
Quoted 14 lines · Alex Riesen

Still, I'd suggest move the test into the caller, firstly because it is the only place that special. Also, I can't think of a proper reason to add a NULL ref to a reflist, and so the crashing tail_link_ref will help us find the callers which use tail_link_ref incorrectly (illogically too).

As the result of patter expansion can be NULL (empty pattern, as it seems), lets just check for it. I parked the patch below locally.

remote.c +0 -0
index 5e92378..58d63ed 100644

remote.c int get_fetch_map(struct ref *remote_refs, · line 891

Quoted 9 lines
remote.c +2 -1
@@ -884,7 +884,8 @@ int get_fetch_map(struct ref *remote_refs,
 			    rm->peer_ref->name);
 	}
 
-	tail_link_ref(ref_map, tail);
+	if (ref_map)
+		tail_link_ref(ref_map, tail);
 
 	return 0;
 }

I disagree with Alex's argument above, because the result of the pattern expansion can be NULL due to a pattern that matched nothing from the remote. This can easily happen if the user originally configured "remote.$name.fetch = +refs/heads/subdir/*:..." and then the remote deletes all branches from refs/heads/subdir at some point in the future.

I think the above patch is the only thing to do here. Perhaps Alex can write up a formal patch and send it to back to the list and CC Lars Hjemli <[email protected]> so he can put it into the patch queue.

Signature · 1 line
Shawn.
#8 lore raw

PATCH 1/1 Fix a crash in ls-remote when refspec expands into nothing

---
 remote.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)

Shawn O. Pearce, Fri, Oct 12, 2007 06:07:45 +0200:

Quoted 3 lines

I think the above patch is the only thing to do here. Perhaps Alex can write up a formal patch and send it to back to the list and CC Lars Hjemli <[email protected]> so he can put it into the patch queue.

here you go

remote.c +2 -1
index e7d735b..a25f66d 100644
@@ -882,7 +882,8 @@ int get_fetch_map(struct ref *remote_refs,
 			    rm->peer_ref->name);
 	}
 
-	tail_link_ref(ref_map, tail);
+	if (ref_map)
+		tail_link_ref(ref_map, tail);
 
 	return 0;
 }
Signature · 1 line
1.5.3.4.232.ga843
#9 lore raw

Re: [PATCH] Fix a crash in ls-remote when refspec expands into nothing

Quoted 7 lines · Alex Riesen

Shawn O. Pearce, Fri, Oct 12, 2007 06:07:45 +0200:

Quoted 3 lines

I think the above patch is the only thing to do here. Perhaps Alex can write up a formal patch and send it to back to the list and CC Lars Hjemli <[email protected]> so he can put it into the patch queue.

here you go

Thanks. I've replaced the tip of q/vj/fetch-t (in
git://hjemli.net/pub/git/git) with this patch.

Signature · 1 line
larsh