Skip to contentSkip to conversation

Don't dereference a strdup-returned NULL

PATCH New Jim Meyering 1 participant 1 message Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Don't dereference a strdup-returned NULL

There are only a dozen or so uses of strdup in all of git. Of those, most seem ok, but this one isn't:

---
 remote.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
remote.c +1 -1
index 33c8e50..ed62a62 100644
@@ -542,7 +542,7 @@ int match_refs(struct ref *src, struct ref *dst, struct ref ***dst_tail,
 			strcpy(dst_name, pat->dst);
 			strcat(dst_name, src->name + strlen(pat->src));
 		} else
-			dst_name = strdup(src->name);
+			dst_name = xstrdup(src->name);
 		dst_peer = find_ref_by_name(dst, dst_name);
 		if (dst_peer && dst_peer->peer_ref)
 			/* We're already sending something to this ref. */

--
1.5.2.1.159.g8d11