Skip to content

Commit

Permalink
Revert previous commit and fix it properly.
Browse files Browse the repository at this point in the history
Turns out checking for the underflow and returning NULL there is not a good idea
because NULL is used to indicate that no such object exists in the hash table,
and we don't want to hijack that to mean error. This was ultimately what was
causing a valid import to be unrecognized, which is why the tests were failing.

Instead of checking for the underflow I'm now just checking if the sized string
length is zero or if the strlen() of the c_string is zero and erroring out
early.

While here, add a test for this.
  • Loading branch information
wxsBSD committed Oct 7, 2016
1 parent ad6c274 commit cfbfe09
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 13 deletions.
3 changes: 0 additions & 3 deletions libyara/hash.c
Expand Up @@ -180,9 +180,6 @@ YR_API void* yr_hash_table_lookup_raw_key(
YR_HASH_TABLE_ENTRY* entry;
uint32_t bucket_index;

if (key_length == 0)
return NULL;

bucket_index = hash(0, key, key_length);

if (ns != NULL)
Expand Down
11 changes: 1 addition & 10 deletions libyara/parser.c
Expand Up @@ -970,7 +970,7 @@ int yr_parser_reduce_import(

char* name;

if (module_name->length == 0)
if (module_name->length == 0 || strlen(module_name->c_string) == 0)
{
compiler->last_result = ERROR_UNKNOWN_MODULE;
yr_compiler_set_error_extra_info(compiler, "");
Expand All @@ -983,15 +983,6 @@ int yr_parser_reduce_import(
module_name->c_string,
compiler->current_namespace->name);

// if unable to lookup module, error

if (module_structure == NULL)
{
yr_compiler_set_error_extra_info(compiler, module_name->c_string);
compiler->last_result = ERROR_UNKNOWN_MODULE;
return compiler->last_result;
}

// if module already imported, do nothing

if (module_structure != NULL)
Expand Down
3 changes: 3 additions & 0 deletions tests/test-rules.c
Expand Up @@ -236,6 +236,9 @@ static void test_syntax()
{
assert_syntax_error(
"rule test { strings: $a = \"a\" $a = \"a\" condition: all of them }");

assert_syntax_error(
"import \"\x00\" rule test { condition: false }");
}


Expand Down

0 comments on commit cfbfe09

Please sign in to comment.