Skip to content

Commit

Permalink
Fix bug when section's name is IMAGE_SIZEOF_SHORT_NAME long
Browse files Browse the repository at this point in the history
In those cases the name doesn't end in a null character and the section name reported by PE module contains spurious characters. This could also cause a buffer overrun.
  • Loading branch information
plusvic committed Jul 30, 2015
1 parent 89d44ff commit 6ad1182
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion libyara/modules/pe.c
Original file line number Diff line number Diff line change
Expand Up @@ -1304,7 +1304,12 @@ void pe_parse_header(
if (!struct_fits_in_pe(pe, section, IMAGE_SECTION_HEADER))
break;

strlcpy(section_name, (char*) section->Name, IMAGE_SIZEOF_SHORT_NAME + 1);
int n = 0;

for (; n < IMAGE_SIZEOF_SHORT_NAME && section->Name[n]; n++)
section_name[n] = section->Name[n];

section_name[n] = '\0';

set_string(
section_name,
Expand Down

0 comments on commit 6ad1182

Please sign in to comment.