From 27c93f95a71ae55914628f273ec8e48dcad70e9e Mon Sep 17 00:00:00 2001 From: Ruslan Kuprieiev Date: Thu, 15 Jun 2017 22:29:49 +0300 Subject: [PATCH] regparse: check malloc return value Unchecked return value of xmalloc may result in 'Undefined behaviour' when its result is passed to xmemcpy. Id: 19 Signed-off-by: Ruslan Kuprieiev --- src/regparse.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/regparse.c b/src/regparse.c index 8153513..c29c5fb 100644 --- a/src/regparse.c +++ b/src/regparse.c @@ -1010,14 +1010,15 @@ scan_env_add_mem_entry(ScanEnv* env) if (IS_NULL(env->mem_nodes_dynamic)) { alloc = INIT_SCANENV_MEMNODES_ALLOC_SIZE; p = (Node** )xmalloc(sizeof(Node*) * alloc); + CHECK_NULL_RETURN_MEMERR(p); xmemcpy(p, env->mem_nodes_static, sizeof(Node*) * SCANENV_MEMNODES_SIZE); } else { alloc = env->mem_alloc * 2; p = (Node** )xrealloc(env->mem_nodes_dynamic, sizeof(Node*) * alloc); + CHECK_NULL_RETURN_MEMERR(p); } - CHECK_NULL_RETURN_MEMERR(p); for (i = env->num_mem + 1; i < alloc; i++) p[i] = NULL_NODE; -- 2.40.0