[Forensics-changes] [yara] 96/407: Implement yr_calloc() and switch yr_malloc() back.
Hilko Bengen
bengen at moszumanska.debian.org
Sat Jul 1 10:28:14 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 bf5a1e47a99a0b42a65d5d28e139af0db5d5f853
Author: Wesley Shields <wxs at atarininja.org>
Date: Fri Oct 10 12:55:01 2014 -0400
Implement yr_calloc() and switch yr_malloc() back.
Implement a yr_calloc() which uses calloc() internally. In the WIN32 case it
just calls yr_malloc() which passes the HEAP_ZERO_MEMORY flag already.
Make yr_malloc() use malloc() internally.
Switch the places in the pe module which need zero'ed memory to using the
new yr_calloc().
---
libyara/include/yara/mem.h | 4 ++++
libyara/mem.c | 15 ++++++++++++++-
libyara/modules/pe.c | 10 +++++-----
3 files changed, 23 insertions(+), 6 deletions(-)
diff --git a/libyara/include/yara/mem.h b/libyara/include/yara/mem.h
index 9c843af..92abfb1 100644
--- a/libyara/include/yara/mem.h
+++ b/libyara/include/yara/mem.h
@@ -32,6 +32,10 @@ limitations under the License.
#else
+void* yr_calloc(
+ size_t count,
+ size_t size);
+
void* yr_malloc(
size_t size);
diff --git a/libyara/mem.c b/libyara/mem.c
index 78f5347..98ce2d0 100644
--- a/libyara/mem.c
+++ b/libyara/mem.c
@@ -45,6 +45,13 @@ int yr_heap_free()
}
+// Call yr_malloc(), which does HEAP_ZERO_MEMORY.
+void* yr_calloc(size_t count, size_t size)
+{
+ return yr_malloc(count * size);
+}
+
+
void* yr_malloc(size_t size)
{
return (void*) HeapAlloc(hHeap, HEAP_ZERO_MEMORY, size);
@@ -94,9 +101,15 @@ int yr_heap_free()
}
+void* yr_calloc(size_t count, size_t size)
+{
+ return calloc(count, size);
+}
+
+
void* yr_malloc(size_t size)
{
- return calloc(1, size);
+ return malloc(size);
}
diff --git a/libyara/modules/pe.c b/libyara/modules/pe.c
index 1e140c7..41aa153 100644
--- a/libyara/modules/pe.c
+++ b/libyara/modules/pe.c
@@ -2487,7 +2487,7 @@ PIMPORT_LIST parse_imports(PE* pe)
if (offset > 0 && offset <= pe->data_size)
{
- new_dll_node = (PIMPORT_LIST) yr_malloc(sizeof(IMPORT_LIST));
+ new_dll_node = (PIMPORT_LIST) yr_calloc(1, sizeof(IMPORT_LIST));
if (!new_dll_node)
return NULL;
@@ -2533,7 +2533,7 @@ PIMPORT_LIST parse_imports(PE* pe)
if (size == (pe->data + pe->data_size) - import->Name)
return NULL;
- new_func_node = (PIMPORT_FUNC_LIST) yr_malloc(sizeof(IMPORT_FUNC_LIST));
+ new_func_node = (PIMPORT_FUNC_LIST) yr_calloc(1, sizeof(IMPORT_FUNC_LIST));
if (!new_func_node)
return NULL;
@@ -2552,7 +2552,7 @@ PIMPORT_LIST parse_imports(PE* pe)
{
// Exported by ordinal.
ordinal = thunks64->u1.Ordinal & 0xFFFF;
- new_func_node = (PIMPORT_FUNC_LIST) yr_malloc(sizeof(IMPORT_FUNC_LIST));
+ new_func_node = (PIMPORT_FUNC_LIST) yr_calloc(1, sizeof(IMPORT_FUNC_LIST));
if (!new_func_node)
return NULL;
@@ -2600,7 +2600,7 @@ PIMPORT_LIST parse_imports(PE* pe)
if (size == (pe->data + pe->data_size) - import->Name)
return NULL;
- new_func_node = (PIMPORT_FUNC_LIST) yr_malloc(sizeof(IMPORT_FUNC_LIST));
+ new_func_node = (PIMPORT_FUNC_LIST) yr_calloc(1, sizeof(IMPORT_FUNC_LIST));
if (!new_func_node)
return NULL;
@@ -2619,7 +2619,7 @@ PIMPORT_LIST parse_imports(PE* pe)
{
// Exported by ordinal.
ordinal = thunks32->u1.Ordinal & 0xFFFF;
- new_func_node = (PIMPORT_FUNC_LIST) yr_malloc(sizeof(IMPORT_FUNC_LIST));
+ new_func_node = (PIMPORT_FUNC_LIST) yr_calloc(1, sizeof(IMPORT_FUNC_LIST));
if (!new_func_node)
return NULL;
--
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