* [PATCH] path: use xmalloc in add_to_trie [not found] <CGME20171024151508epcas2p4d9455e93e2e19bfb118b485d4ce14922@epcas2p4.samsung.com> @ 2017-10-24 15:15 ` Andrey Okoshkin 2017-10-24 16:13 ` Stefan Beller 0 siblings, 1 reply; 3+ messages in thread From: Andrey Okoshkin @ 2017-10-24 15:15 UTC (permalink / raw) To: git; +Cc: dturner, Jeff King, Junio C Hamano Add usage of xmalloc() instead of malloc() in add_to_trie() as xmalloc wraps and checks memory allocation result. Signed-off-by: Andrey Okoshkin <a.okoshkin@samsung.com> --- Hello, I'm not sure but it looks like there is a missing check of the malloc result. memcpy() may crash with SIGSEGV due to the memory allocation failure. make_trie_node() uses xmalloc() and xcalloc() - so I believe add_to_trie() also should use it. Best regards, Andrey path.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/path.c b/path.c index 335d4dd87..69b23ef17 100644 --- a/path.c +++ b/path.c @@ -191,7 +191,7 @@ static void *add_to_trie(struct trie *root, const char *key, void *value) * Split this node: child will contain this node's * existing children. */ - child = malloc(sizeof(*child)); + child = xmalloc(sizeof(*child)); memcpy(child->children, root->children, sizeof(root->children)); child->len = root->len - i - 1; -- 2.14.3 ^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] path: use xmalloc in add_to_trie 2017-10-24 15:15 ` [PATCH] path: use xmalloc in add_to_trie Andrey Okoshkin @ 2017-10-24 16:13 ` Stefan Beller 2017-10-24 19:26 ` Jeff King 0 siblings, 1 reply; 3+ messages in thread From: Stefan Beller @ 2017-10-24 16:13 UTC (permalink / raw) To: Andrey Okoshkin Cc: git@vger.kernel.org, David Turner, Jeff King, Junio C Hamano On Tue, Oct 24, 2017 at 8:15 AM, Andrey Okoshkin <a.okoshkin@samsung.com> wrote: > Add usage of xmalloc() instead of malloc() in add_to_trie() as xmalloc wraps > and checks memory allocation result. > > Signed-off-by: Andrey Okoshkin <a.okoshkin@samsung.com> > --- > Hello, > I'm not sure but it looks like there is a missing check of the malloc result. > memcpy() may crash with SIGSEGV due to the memory allocation failure. > make_trie_node() uses xmalloc() and xcalloc() - so I believe add_to_trie() > also should use it. Good catch! Thanks for spotting. Trying to find similar occurrences via git grep "= malloc" did not yield other places that need the same fix. Thanks, Stefan ^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] path: use xmalloc in add_to_trie 2017-10-24 16:13 ` Stefan Beller @ 2017-10-24 19:26 ` Jeff King 0 siblings, 0 replies; 3+ messages in thread From: Jeff King @ 2017-10-24 19:26 UTC (permalink / raw) To: Stefan Beller Cc: Andrey Okoshkin, git@vger.kernel.org, David Turner, Junio C Hamano On Tue, Oct 24, 2017 at 09:13:28AM -0700, Stefan Beller wrote: > On Tue, Oct 24, 2017 at 8:15 AM, Andrey Okoshkin <a.okoshkin@samsung.com> wrote: > > Add usage of xmalloc() instead of malloc() in add_to_trie() as xmalloc wraps > > and checks memory allocation result. > > > > Signed-off-by: Andrey Okoshkin <a.okoshkin@samsung.com> > > --- > > Hello, > > I'm not sure but it looks like there is a missing check of the malloc result. > > memcpy() may crash with SIGSEGV due to the memory allocation failure. > > make_trie_node() uses xmalloc() and xcalloc() - so I believe add_to_trie() > > also should use it. > > Good catch! Thanks for spotting. > > Trying to find similar occurrences via git grep "= malloc" did not > yield other places that need the same fix. Don't forget realloc and calloc (though I don't think there are any cases that need touching there; just a hint for anybody doing auditing). -Peff ^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2017-10-24 19:27 UTC | newest] Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- [not found] <CGME20171024151508epcas2p4d9455e93e2e19bfb118b485d4ce14922@epcas2p4.samsung.com> 2017-10-24 15:15 ` [PATCH] path: use xmalloc in add_to_trie Andrey Okoshkin 2017-10-24 16:13 ` Stefan Beller 2017-10-24 19:26 ` 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).