git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] decode_header: fix pointential memory leak if decode_header failed
@ 2025-05-08 13:38 Lidong Yan via GitGitGadget
  2025-05-08 22:16 ` Junio C Hamano
  2025-05-11 16:14 ` [PATCH v2] mailinfo: fix pointential memory leak if `decode_header` failed Lidong Yan via GitGitGadget
  0 siblings, 2 replies; 10+ messages in thread
From: Lidong Yan via GitGitGadget @ 2025-05-08 13:38 UTC (permalink / raw)
  To: git; +Cc: Lidong Yan, Lidong Yan

From: Lidong Yan <502024330056@smail.nju.edu.cn>

In mailinfo.c line 539, if convert_to_utf8 failed, the strbuf stored
in dec will leak. Simply add strbuf_release and free(dec) will solve
this problem.

Signed-off-by: Lidong Yan <502024330056@smail.nju.edu.cn>
---
    decode_header: fix pointential memory leak if decode_header failed
    
    In mailinfo.c line 539, if convert_to_utf8 failed, the strbuf stored in
    dec will leak. Simply add strbuf_release and free(dec) will solve this
    problem.

Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-1956%2Fbrandb97%2Ffix-mailinfo-decode-header-leak-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-1956/brandb97/fix-mailinfo-decode-header-leak-v1
Pull-Request: https://github.com/git/git/pull/1956

 mailinfo.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/mailinfo.c b/mailinfo.c
index 7b001fa5dbd..7a54471a481 100644
--- a/mailinfo.c
+++ b/mailinfo.c
@@ -536,8 +536,11 @@ static void decode_header(struct mailinfo *mi, struct strbuf *it)
 			dec = decode_q_segment(&piecebuf, 1);
 			break;
 		}
-		if (convert_to_utf8(mi, dec, charset_q.buf))
+		if (convert_to_utf8(mi, dec, charset_q.buf)) {
+			strbuf_release(dec);
+			free(dec);
 			goto release_return;
+		}
 
 		strbuf_addbuf(&outbuf, dec);
 		strbuf_release(dec);

base-commit: 6f84262c44a89851c3ae5a6e4c1a9d06b2068d75
-- 
gitgitgadget

^ permalink raw reply related	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2025-05-13 13:42 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-05-08 13:38 [PATCH] decode_header: fix pointential memory leak if decode_header failed Lidong Yan via GitGitGadget
2025-05-08 22:16 ` Junio C Hamano
2025-05-09  1:51   ` lidongyan
2025-05-11 16:14 ` [PATCH v2] mailinfo: fix pointential memory leak if `decode_header` failed Lidong Yan via GitGitGadget
2025-05-12 14:12   ` Junio C Hamano
2025-05-12 16:17   ` [PATCH v3] " Lidong Yan via GitGitGadget
2025-05-12 19:32     ` Junio C Hamano
2025-05-13  2:49     ` [PATCH v4] " Lidong Yan via GitGitGadget
2025-05-13 13:34       ` Junio C Hamano
2025-05-13 13:42         ` lidongyan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).