{"thread":{"id":"45889","subject":"[PATCH] am: check return value of resolve_refdup before using hash","startedAt":"2017-05-06T17:14:21Z","lastAt":"2017-05-09T03:58:19Z","messageCount":2,"participants":["René Scharfe","Jeff King"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"318933","messageId":"f0ca65bf-aaf9-2cd6-1deb-c55c9e7a8fa3@web.de","threadId":"45889","inReplyTo":null,"subject":"[PATCH] am: check return value of resolve_refdup before using hash","fromName":"René Scharfe","fromEmail":"l.s.r@web.de","sentAt":"2017-05-06T17:13:56Z","receivedAt":"2017-05-06T17:14:21Z","isPatch":true,"sender":{"key":"l.s.r@web.de","avatar":"https://avatars.githubusercontent.com/u/26122331?v=4"},"body":"If resolve_refdup() fails it returns NULL and possibly leaves its hash\noutput parameter untouched.  Make sure to use it only if the function\nsucceeded, in order to avoid accessing uninitialized memory.\n\nSigned-off-by: Rene Scharfe <l.s.r@web.de>\n---\n builtin/am.c | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n\ndiff --git a/builtin/am.c b/builtin/am.c\nindex a95dd8b4e6..2c52c820aa 100644\n--- a/builtin/am.c\n+++ b/builtin/am.c\n@@ -2156,7 +2156,7 @@ static void am_abort(struct am_state *state)\n \tam_rerere_clear();\n \n \tcurr_branch = resolve_refdup(\"HEAD\", 0, curr_head.hash, NULL);\n-\thas_curr_head = !is_null_oid(&curr_head);\n+\thas_curr_head = curr_branch && !is_null_oid(&curr_head);\n \tif (!has_curr_head)\n \t\thashcpy(curr_head.hash, EMPTY_TREE_SHA1_BIN);\n \n-- \n2.12.2\n\n"},{"id":"319160","messageId":"20170509035807.2q7bzhu7cs4fcqkb@sigill.intra.peff.net","threadId":"45889","inReplyTo":"f0ca65bf-aaf9-2cd6-1deb-c55c9e7a8fa3@web.de","subject":"Re: [PATCH] am: check return value of resolve_refdup before using hash","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2017-05-09T03:58:07Z","receivedAt":"2017-05-09T03:58:19Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Sat, May 06, 2017 at 07:13:56PM +0200, René Scharfe wrote:\n\n> If resolve_refdup() fails it returns NULL and possibly leaves its hash\n> output parameter untouched.  Make sure to use it only if the function\n> succeeded, in order to avoid accessing uninitialized memory.\n> \n> Signed-off-by: Rene Scharfe <l.s.r@web.de>\n> ---\n>  builtin/am.c | 2 +-\n>  1 file changed, 1 insertion(+), 1 deletion(-)\n> \n> diff --git a/builtin/am.c b/builtin/am.c\n> index a95dd8b4e6..2c52c820aa 100644\n> --- a/builtin/am.c\n> +++ b/builtin/am.c\n> @@ -2156,7 +2156,7 @@ static void am_abort(struct am_state *state)\n>  \tam_rerere_clear();\n>  \n>  \tcurr_branch = resolve_refdup(\"HEAD\", 0, curr_head.hash, NULL);\n> -\thas_curr_head = !is_null_oid(&curr_head);\n> +\thas_curr_head = curr_branch && !is_null_oid(&curr_head);\n>  \tif (!has_curr_head)\n>  \t\thashcpy(curr_head.hash, EMPTY_TREE_SHA1_BIN);\n\nThis one looks good to me (and no interesting ripple effects from\nhandling the error correctly :) ).\n\n-Peff\n"}]}