Browse code

Fix for errors on YARA rules when hex constants have odd lengths.

Steven Morgan authored on 2015/02/24 07:17:08
Showing 3 changed files
... ...
@@ -203,6 +203,30 @@ int cli_hex2num(const char *hex)
203 203
     return ret;
204 204
 }
205 205
 
206
+int cli_xtoi(const char *hex)
207
+{
208
+    int len, val, i;
209
+    char * hexbuf;
210
+
211
+    len = strlen(hex);
212
+
213
+    if(len % 2 == 0)
214
+        return cli_hex2num(hex);
215
+        
216
+    hexbuf = cli_calloc(len+2, sizeof(char));
217
+    if (hexbuf == NULL) {
218
+        cli_errmsg("cli_xtoi(): cli_malloc fails.\n");
219
+        return -1;
220
+    }
221
+    
222
+    for(i = 0; i < len; i++)
223
+        hexbuf[i+1] = hex[i];
224
+    val = cli_hex2num(hexbuf);
225
+    free(hexbuf);
226
+    return val;
227
+}
228
+
229
+
206 230
 char *cli_str2hex(const char *string, unsigned int len)
207 231
 {
208 232
 	char *hexstr;
... ...
@@ -44,6 +44,7 @@ uint16_t *cli_hex2ui(const char *hex);
44 44
 int  cli_hex2str_to(const char *hex, char *ptr, size_t len);
45 45
 char *cli_hex2str(const char *hex);
46 46
 int cli_hex2num(const char *hex);
47
+int cli_xtoi(const char *hex);
47 48
 char *cli_str2hex(const char *string, unsigned int len);
48 49
 char *cli_utf16toascii(const char *str, unsigned int length);
49 50
 char *cli_strtokbuf(const char *input, int fieldno, const char *delim, char *output);
... ...
@@ -463,12 +463,8 @@ struct RE {
463 463
 #define yr_malloc cli_malloc
464 464
 #define yr_realloc cli_realloc
465 465
 #define yr_free free
466
-#define xtoi cli_hex2num
466
+#define xtoi cli_xtoi
467 467
 #define strlcpy cli_strlcpy
468
-#ifndef HAVE_STRLCAT
469
-/* below is danger-defeats the purpose of strlcat. we need a cli_strlcat for this ... */
470
-#define strlcat(d, s, l) strcat((d), (s))
471
-#endif
472 468
 
473 469
 /* YARA-defined structure replacements for ClamAV */
474 470
 struct _yc_rule {