[Forensics-changes] [yara] 342/407: fix: check return values of memory allocation functions
Hilko Bengen
bengen at moszumanska.debian.org
Sat Jul 1 10:28:43 UTC 2017
This is an automated email from the git hooks/post-receive script.
bengen pushed a commit to annotated tag v3.3.0
in repository yara.
commit 6daa52814b0729a2db0b8ba84048364eb5a86e53
Author: pozdnychev <guillaume at bk.ru>
Date: Mon Jan 19 16:04:13 2015 +0100
fix: check return values of memory allocation functions
---
libyara/atoms.c | 8 ++++++++
libyara/modules/pe.c | 10 ++++++++--
2 files changed, 16 insertions(+), 2 deletions(-)
diff --git a/libyara/atoms.c b/libyara/atoms.c
index 60ea9ae..ed7625d 100644
--- a/libyara/atoms.c
+++ b/libyara/atoms.c
@@ -193,6 +193,9 @@ ATOM_TREE_NODE* _yr_atoms_tree_node_create(
ATOM_TREE_NODE* new_node;
new_node = (ATOM_TREE_NODE*) yr_malloc(sizeof(ATOM_TREE_NODE));
+ if (! new_node)
+ return NULL;
+
new_node->type = type;
new_node->atom_length = 0;
new_node->next_sibling = NULL;
@@ -347,6 +350,8 @@ int _yr_atoms_choose(
case ATOM_TREE_LEAF:
item = (YR_ATOM_LIST_ITEM*) yr_malloc(sizeof(YR_ATOM_LIST_ITEM));
+ if (! item)
+ return 0;
for (i = 0; i < node->atom_length; i++)
item->atom[i] = node->atom[i];
@@ -973,6 +978,9 @@ int yr_atoms_extract_from_re(
int min_atom_quality = 0;
+ if (! atom_tree)
+ return ERROR_INSUFICIENT_MEMORY;
+
atom_tree->root_node = _yr_atoms_tree_node_create(ATOM_TREE_OR);;
atom_tree->current_leaf = NULL;
diff --git a/libyara/modules/pe.c b/libyara/modules/pe.c
index b6e809e..ee34bc8 100644
--- a/libyara/modules/pe.c
+++ b/libyara/modules/pe.c
@@ -287,7 +287,6 @@ void pe_parse_rich_signature(
return;
}
-
PIMAGE_DATA_DIRECTORY pe_get_directory_entry(
PE* pe,
int entry)
@@ -1290,6 +1289,9 @@ define_function(imphash)
// Allocate a new string to hold the dll name.
char* dll_name = (char *) yr_malloc(dll_name_len + 1);
+ if (! dll_name)
+ return ERROR_INSUFICIENT_MEMORY;
+
strlcpy(dll_name, dll->name, dll_name_len + 1);
func = dll->functions;
@@ -1304,7 +1306,10 @@ define_function(imphash)
char* final_name = (char*) yr_malloc(final_name_len + 1);
if (final_name == NULL)
- break;
+ {
+ yr_free(dll_name);
+ break;
+ }
sprintf(final_name, first ? "%s.%s": ",%s.%s", dll_name, func->name);
@@ -1322,6 +1327,7 @@ define_function(imphash)
}
yr_free(dll_name);
+
dll = dll->next;
}
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/forensics/yara.git
More information about the forensics-changes
mailing list