* [PATCH] am: check return value of resolve_refdup before using hash
@ 2017-05-06 17:13 René Scharfe
2017-05-09 3:58 ` Jeff King
0 siblings, 1 reply; 2+ messages in thread
From: René Scharfe @ 2017-05-06 17:13 UTC (permalink / raw)
To: Git List; +Cc: Junio C Hamano
If resolve_refdup() fails it returns NULL and possibly leaves its hash
output parameter untouched. Make sure to use it only if the function
succeeded, in order to avoid accessing uninitialized memory.
Signed-off-by: Rene Scharfe <l.s.r@web.de>
---
builtin/am.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/builtin/am.c b/builtin/am.c
index a95dd8b4e6..2c52c820aa 100644
--- a/builtin/am.c
+++ b/builtin/am.c
@@ -2156,7 +2156,7 @@ static void am_abort(struct am_state *state)
am_rerere_clear();
curr_branch = resolve_refdup("HEAD", 0, curr_head.hash, NULL);
- has_curr_head = !is_null_oid(&curr_head);
+ has_curr_head = curr_branch && !is_null_oid(&curr_head);
if (!has_curr_head)
hashcpy(curr_head.hash, EMPTY_TREE_SHA1_BIN);
--
2.12.2
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] am: check return value of resolve_refdup before using hash
2017-05-06 17:13 [PATCH] am: check return value of resolve_refdup before using hash René Scharfe
@ 2017-05-09 3:58 ` Jeff King
0 siblings, 0 replies; 2+ messages in thread
From: Jeff King @ 2017-05-09 3:58 UTC (permalink / raw)
To: René Scharfe; +Cc: Git List, Junio C Hamano
On Sat, May 06, 2017 at 07:13:56PM +0200, René Scharfe wrote:
> If resolve_refdup() fails it returns NULL and possibly leaves its hash
> output parameter untouched. Make sure to use it only if the function
> succeeded, in order to avoid accessing uninitialized memory.
>
> Signed-off-by: Rene Scharfe <l.s.r@web.de>
> ---
> builtin/am.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/builtin/am.c b/builtin/am.c
> index a95dd8b4e6..2c52c820aa 100644
> --- a/builtin/am.c
> +++ b/builtin/am.c
> @@ -2156,7 +2156,7 @@ static void am_abort(struct am_state *state)
> am_rerere_clear();
>
> curr_branch = resolve_refdup("HEAD", 0, curr_head.hash, NULL);
> - has_curr_head = !is_null_oid(&curr_head);
> + has_curr_head = curr_branch && !is_null_oid(&curr_head);
> if (!has_curr_head)
> hashcpy(curr_head.hash, EMPTY_TREE_SHA1_BIN);
This one looks good to me (and no interesting ripple effects from
handling the error correctly :) ).
-Peff
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2017-05-09 3:58 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-05-06 17:13 [PATCH] am: check return value of resolve_refdup before using hash René Scharfe
2017-05-09 3:58 ` Jeff King
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
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 read-only IMAP folder(s) and NNTP newsgroup(s).