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

[PATCH] Don't dereference a strdup-returned NULL

From
Jim Meyering <jim@meyering.net>
Date
Jun 12, 2007, 20:59 UTC
Message-ID
<87abv4ubx2.fsf@rho.meyering.net>

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

Signed-off-by: Jim Meyering <jim@meyering.net>
---
 remote.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/remote.c b/remote.c
index 33c8e50..ed62a62 100644
--- a/remote.c
+++ b/remote.c
@@ -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
Message 1 of 1 in “Don't dereference a strdup-returned NULL”
  1. Don't dereference a strdup-returned NULLJim Meyering, Jun 12, 2007

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.