Simplify code in pe_parse_debug_directory
@@ -285,6 +285,7 @@ static void pe_parse_debug_directory(
int64_t pcv_hdr_offset;
int i, dcount;
size_t pdb_str_len;
+ char* pdb_str = NULL;
data_dir = pe_get_directory_entry(
pe, IMAGE_DIRECTORY_ENTRY_DEBUG);
@@ -333,33 +334,25 @@ static void pe_parse_debug_directory(
{
PCV_INFO_PDB20 pdb20 = (PCV_INFO_PDB20) cv_hdr;
- if (!struct_fits_in_pe(pe, pdb20, CV_INFO_PDB20))
- break;
-
- pdb_str_len = strnlen((char *)(pdb20->PdbFileName),
- yr_min(available_space(pe, pdb20->PdbFileName), MAX_PATH * sizeof(char)));
-
- if (pdb_str_len && pdb_str_len < MAX_PATH)
- {
- set_sized_string((char *)(pdb20->PdbFileName), pdb_str_len,
- pe->object, "pdb");
- break;
- }
+ if (struct_fits_in_pe(pe, pdb20, CV_INFO_PDB20))
+ pdb_str = (char*) (pdb20->PdbFileName);
}
else if (yr_le32toh(cv_hdr->dwSignature) == CVINFO_PDB70_CVSIGNATURE)
{
PCV_INFO_PDB70 pdb70 = (PCV_INFO_PDB70) cv_hdr;
- if (!struct_fits_in_pe(pe, pdb70, CV_INFO_PDB70))
- break;
+ if (struct_fits_in_pe(pe, pdb70, CV_INFO_PDB70))
+ pdb_str = (char*) (pdb70->PdbFileName);
+ }
- pdb_str_len = strnlen((char *)(pdb70->PdbFileName),
- yr_min(available_space(pe, pdb70->PdbFileName), MAX_PATH * sizeof(char)));
+ if (pdb_str != NULL)
+ {
+ pdb_str_len = strnlen(
+ pdb_str, yr_min(available_space(pe, pdb_str), MAX_PATH));
- if (pdb_str_len && pdb_str_len < MAX_PATH)
+ if (pdb_str_len > 0 && pdb_str_len < MAX_PATH)
{
- set_sized_string((char *)(pdb70->PdbFileName), pdb_str_len,
- pe->object, "pdb");
+ set_sized_string(pdb_str, pdb_str_len, pe->object, "pdb");
break;
}
}
