threads / patch / 65166

patchhistory: initialize rev_info in cmd_history_reword()

Subject: [PATCH] history: initialize rev_info in cmd_history_reword()

## tl;dr

2 messages between Mar 8, 2026 and Mar 10, 2026. Diffs are folded; open one to read it.

replies: 1people: 2as markdown or json

René Scharfe· Mar 8, 2026, 09:57 UTC · lore

git history reword expects a single valid revision argument and errors out if it doesn't get it. In that case the struct rev_info passed to release_revisions() for cleanup is still uninitialized, which can result in attempts to free(3) random pointers. Avoid that by initializing the structure.

Signed-off-by: René Scharfe <l.s.r@web.de>
---
 builtin/history.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Show changes to builtin/history.c +1 −1
diff --git a/builtin/history.c b/builtin/history.c
index 1cf6c668cf..88822a184f 100644
--- a/builtin/history.c
+++ b/builtin/history.c
@@ -425,7 +425,7 @@ static int cmd_history_reword(int argc,
 	};
 	struct strbuf reflog_msg = STRBUF_INIT;
 	struct commit *original, *rewritten;
-	struct rev_info revs;
+	struct rev_info revs = { 0 };
 	int ret;
 
 	argc = parse_options(argc, argv, prefix, options, usage, 0);
-- 
2.53.0
Patrick Steinhardt· Mar 10, 2026, 12:16 UTC · re: René Scharfe · lore

Re: [PATCH] history: initialize rev_info in cmd_history_reword()

On Sun, Mar 08, 2026 at 10:57:02AM +0100, René Scharfe wrote:
Show 5 quoted lines
> git history reword expects a single valid revision argument and errors
> out if it doesn't get it.  In that case the struct rev_info passed to
> release_revisions() for cleanup is still uninitialized, which can result
> in attempts to free(3) random pointers.  Avoid that by initializing the
> structure.
This looks obviously correct to me. Thanks!
Patrick

← back to recent threads