{"thread":{"id":"47019","subject":"[PATCH] path: use xmalloc in add_to_trie","startedAt":"2017-10-24T15:15:30Z","lastAt":"2017-10-24T19:27:06Z","messageCount":3,"participants":["Andrey Okoshkin","Stefan Beller","Jeff King"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"330914","messageId":"e63c2208-900e-138a-a13c-fecf9403e0b8@samsung.com","threadId":"47019","inReplyTo":"CGME20171024151508epcas2p4d9455e93e2e19bfb118b485d4ce14922@epcas2p4.samsung.com","subject":"[PATCH] path: use xmalloc in add_to_trie","fromName":"Andrey Okoshkin","fromEmail":"a.okoshkin@samsung.com","sentAt":"2017-10-24T15:15:05Z","receivedAt":"2017-10-24T15:15:30Z","isPatch":true,"sender":{"key":"a.okoshkin@samsung.com","avatar":"https://avatars.githubusercontent.com/u/10993050?v=4"},"body":"Add usage of xmalloc() instead of malloc() in add_to_trie() as xmalloc wraps\nand checks memory allocation result.\n\nSigned-off-by: Andrey Okoshkin <a.okoshkin@samsung.com>\n---\nHello,\nI'm not sure but it looks like there is a missing check of the malloc result.\nmemcpy() may crash with SIGSEGV due to the memory allocation failure.\nmake_trie_node() uses xmalloc() and xcalloc() - so I believe add_to_trie()\nalso should use it.\n\nBest regards,\nAndrey\n\n path.c | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n\ndiff --git a/path.c b/path.c\nindex 335d4dd87..69b23ef17 100644\n--- a/path.c\n+++ b/path.c\n@@ -191,7 +191,7 @@ static void *add_to_trie(struct trie *root, const char *key, void *value)\n \t\t * Split this node: child will contain this node's\n \t\t * existing children.\n \t\t */\n-\t\tchild = malloc(sizeof(*child));\n+\t\tchild = xmalloc(sizeof(*child));\n \t\tmemcpy(child->children, root->children, sizeof(root->children));\n \n \t\tchild->len = root->len - i - 1;\n-- \n2.14.3\n"},{"id":"330922","messageId":"CAGZ79kZM_hVi8BeTmL5u_QK5+=1g3gcPsccEe1AJVpDLUWz_9Q@mail.gmail.com","threadId":"47019","inReplyTo":"e63c2208-900e-138a-a13c-fecf9403e0b8@samsung.com","subject":"Re: [PATCH] path: use xmalloc in add_to_trie","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2017-10-24T16:13:28Z","receivedAt":"2017-10-24T16:13:37Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"On Tue, Oct 24, 2017 at 8:15 AM, Andrey Okoshkin <a.okoshkin@samsung.com> wrote:\n> Add usage of xmalloc() instead of malloc() in add_to_trie() as xmalloc wraps\n> and checks memory allocation result.\n>\n> Signed-off-by: Andrey Okoshkin <a.okoshkin@samsung.com>\n> ---\n> Hello,\n> I'm not sure but it looks like there is a missing check of the malloc result.\n> memcpy() may crash with SIGSEGV due to the memory allocation failure.\n> make_trie_node() uses xmalloc() and xcalloc() - so I believe add_to_trie()\n> also should use it.\n\nGood catch! Thanks for spotting.\n\nTrying to find similar occurrences via git grep \"= malloc\" did not\nyield other places that need the same fix.\n\nThanks,\nStefan\n"},{"id":"330956","messageId":"20171024192658.4rvxvb34y64lt2tc@sigill.intra.peff.net","threadId":"47019","inReplyTo":"CAGZ79kZM_hVi8BeTmL5u_QK5+=1g3gcPsccEe1AJVpDLUWz_9Q@mail.gmail.com","subject":"Re: [PATCH] path: use xmalloc in add_to_trie","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2017-10-24T19:26:59Z","receivedAt":"2017-10-24T19:27:06Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Tue, Oct 24, 2017 at 09:13:28AM -0700, Stefan Beller wrote:\n\n> On Tue, Oct 24, 2017 at 8:15 AM, Andrey Okoshkin <a.okoshkin@samsung.com> wrote:\n> > Add usage of xmalloc() instead of malloc() in add_to_trie() as xmalloc wraps\n> > and checks memory allocation result.\n> >\n> > Signed-off-by: Andrey Okoshkin <a.okoshkin@samsung.com>\n> > ---\n> > Hello,\n> > I'm not sure but it looks like there is a missing check of the malloc result.\n> > memcpy() may crash with SIGSEGV due to the memory allocation failure.\n> > make_trie_node() uses xmalloc() and xcalloc() - so I believe add_to_trie()\n> > also should use it.\n> \n> Good catch! Thanks for spotting.\n> \n> Trying to find similar occurrences via git grep \"= malloc\" did not\n> yield other places that need the same fix.\n\nDon't forget realloc and calloc (though I don't think there are any\ncases that need touching there; just a hint for anybody doing auditing).\n\n-Peff\n"}]}