Skip to content

Commit

Permalink
Prevent assert in MSVC debug version of isprint() (#2062)
Browse files Browse the repository at this point in the history
  • Loading branch information
Demonslay335 authored Apr 5, 2024
1 parent fedee98 commit 2a9bc0d
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions libyara/modules/pe/pe.c
Original file line number Diff line number Diff line change
Expand Up @@ -2006,15 +2006,19 @@ const char* pe_get_section_full_name(
// Check string
for (uint64_t len = 0; fits_in_pe(pe, string, len + 1); len++)
{
// Prevent sign extension to 32-bits on bytes > 0x7F
// The result negative integer would cause assert in MSVC debug version of isprint()
unsigned int one_char = (unsigned char)(string[len]);

// Valid string
if (string[len] == 0)
if (one_char == 0)
{
*section_full_name_length = len;
return string;
}

// string contain unprintable character
if (!isprint(string[len]))
if (!isprint(one_char))
return NULL;
}

Expand Down

0 comments on commit 2a9bc0d

Please sign in to comment.