[Forensics-changes] [yara] 221/407: Avoid segfault when yr_re_finalize is called before yr_re_initialize

Hilko Bengen bengen at moszumanska.debian.org
Sat Jul 1 10:28:28 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 2aeb1679e8f4287e8975841995c9ef67c445d078
Author: Victor M. Alvarez <plusvic at gmail.com>
Date:   Fri Nov 21 14:32:10 2014 +0100

    Avoid segfault when yr_re_finalize is called before yr_re_initialize
---
 libyara/re.c | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/libyara/re.c b/libyara/re.c
index f418e87..2959bf5 100644
--- a/libyara/re.c
+++ b/libyara/re.c
@@ -87,9 +87,9 @@ typedef struct _RE_THREAD_STORAGE
 
 
 #ifdef _WIN32
-DWORD thread_storage_key;
+DWORD thread_storage_key = INVALID_HANDLE_VALUE;
 #else
-pthread_key_t thread_storage_key;
+pthread_key_t thread_storage_key = 0;
 #endif
 
 //
@@ -121,8 +121,10 @@ int yr_re_finalize(void)
 {
   #ifdef _WIN32
   TlsFree(thread_storage_key);
+  thread_storage_key = INVALID_HANDLE_VALUE;
   #else
   pthread_key_delete(thread_storage_key);
+  thread_storage_key = 0;
   #endif
 
   return ERROR_SUCCESS;
@@ -142,9 +144,15 @@ int yr_re_finalize_thread(void)
   RE_THREAD_STORAGE* storage;
 
   #ifdef _WIN32
-  storage = (RE_THREAD_STORAGE*) TlsGetValue(thread_storage_key);
+  if (thread_storage_key != INVALID_HANDLE_VALUE)
+    storage = (RE_THREAD_STORAGE*) TlsGetValue(thread_storage_key);
+  else
+    return ERROR_SUCCESS;
   #else
-  storage = (RE_THREAD_STORAGE*) pthread_getspecific(thread_storage_key);
+  if (thread_storage_key != 0)
+    storage = (RE_THREAD_STORAGE*) pthread_getspecific(thread_storage_key);
+  else
+    return ERROR_SUCCESS;
   #endif
 
   if (storage != 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