Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent assert in MSVC debug version of isprint() #2062

Merged
merged 1 commit into from
Apr 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading