[Forensics-changes] [yara] 99/415: Fix issue 20, small speed improvement

Hilko Bengen bengen at moszumanska.debian.org
Thu Apr 3 05:42:50 UTC 2014


This is an automated email from the git hooks/post-receive script.

bengen pushed a commit to branch debian
in repository yara.

commit 3184788ccfb5113c6370866681770d55e4e3a4ce
Author: Victor M. Alvarez <plusvic at gmail.com>
Date:   Wed Jun 29 10:14:44 2011 +0000

    Fix issue 20, small speed improvement
---
 libyara/scan.c | 25 +++++++++++++++++++++----
 1 file changed, 21 insertions(+), 4 deletions(-)

diff --git a/libyara/scan.c b/libyara/scan.c
index 8c8d946..c68306c 100644
--- a/libyara/scan.c
+++ b/libyara/scan.c
@@ -623,6 +623,7 @@ inline int string_match(unsigned char* buffer, size_t buffer_size, STRING* strin
 	int i, len;
 	int is_wide_char;
 	
+	unsigned char tmp_buffer[512];
 	unsigned char* tmp;
 	
 	if (IS_HEX(string))
@@ -635,13 +636,25 @@ inline int string_match(unsigned char* buffer, size_t buffer_size, STRING* strin
 		{
 			i = 0;
 			
-			while(i < buffer_size - 1 && isalphanum[buffer[i]] && buffer[i + 1] == 0)
+			while(  i < buffer_size - 1 && 
+			        buffer[i] >= 32 &&        // buffer[i] is a ... 
+			        buffer[i] <= 126 &&       // ... printable character
+			        buffer[i + 1] == 0)
 			{
 				i += 2;
 			}
 						
 			len = i/2;
-			tmp = yr_malloc(len);
+						
+			if (len > sizeof(tmp_buffer))
+			{
+			    tmp = yr_malloc(len);
+            }
+            else 
+            {
+                tmp = tmp_buffer;
+            }
+            
             i = 0;
 			
 			if (tmp != NULL)
@@ -653,8 +666,12 @@ inline int string_match(unsigned char* buffer, size_t buffer_size, STRING* strin
 				}
 								
 				match = regexp_match(tmp, len, string->string, string->length, string->re, (negative_size > 2));
-			
-				yr_free(tmp);			
+			    
+			    if (len > sizeof(tmp_buffer))
+			    {
+				    yr_free(tmp);			
+				} 
+				    
 				return match * 2;
 			}
 			

-- 
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