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

[PATCH 1/4] test-prio-queue: use xmalloc

From
Jeff King <peff@peff.net>
Date
Apr 11, 2019, 13:48 UTC
Message-ID
<20190411134814.GA9182@sigill.intra.peff.net>
In-Reply-To
<20190411134736.GA28543@sigill.intra.peff.net>

test-prio-queue.c doesn't check the return value of malloc, and could segfault.

It's unlikely for this to matter in practice; it's a small allocation, and this code isn't even installed alongside the rest of Git. But let's use xmalloc(), which makes auditing for other accidental uses of bare malloc() easier.

Reported-by: 王健强 <jianqiang.wang@securitygossip.com>
Signed-off-by: Jeff King <peff@peff.net>
---
 t/helper/test-prio-queue.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/t/helper/test-prio-queue.c b/t/helper/test-prio-queue.c
index 5bc9c46ea5..f4028442e3 100644
--- a/t/helper/test-prio-queue.c
+++ b/t/helper/test-prio-queue.c
@@ -40,7 +40,7 @@ int cmd__prio_queue(int argc, const char **argv)
 		} else if (!strcmp(*argv, "stack")) {
 			pq.compare = NULL;
 		} else {
-			int *v = malloc(sizeof(*v));
+			int *v = xmalloc(sizeof(*v));
 			*v = atoi(*argv);
 			prio_queue_put(&pq, v);
 		}
-- 
2.21.0.922.g1a559e573c
Previous: Jeff KingNext: Jeff King
Message 2 of 9 in “use xmalloc in more places”
  1. 0/4 use xmalloc in more placesJeff King, Apr 11, 2019
  2. 1/4 test-prio-queue: use xmallocJeff King, Apr 11, 2019
  3. 2/4 xdiff: use git-compat-utilJeff King, Apr 11, 2019
  4. 3/4 xdiff: use xmalloc/xreallocJeff King, Apr 11, 2019
  5. 4/4 progress: use xmalloc/xcallocJeff King, Apr 11, 2019
  6. Taylor BlauApr 11, 2019
  7. Jeff KingApr 11, 2019
  8. Taylor BlauApr 11, 2019
  9. Jeff KingApr 11, 2019

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.