Skip to content

Commit

Permalink
Compare fewer bytes in section name
Browse files Browse the repository at this point in the history
Only compare the bytes that were provided in `name`, instead of fixed 8.

There are a couple of problems with this, however:
- Theoretically, a section that starts with `.text`, but that isn't
  `.text` we need, can exist before the expected one. This change will
  break this use case. But it's incredibly unlikely, so whatever.
- A `.text` whose name doesn't start with `.text` won't be found this
  way. But it wouldn't normally, anyway. Until someone with such a
  binary appears, I choose to do nothing.

Closes #5
  • Loading branch information
Lahvuun committed Jul 24, 2022
1 parent e0fb2c6 commit 099616d
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ bool string_to_uint32(const char *s, int base, uint32_t *value_out)

bool find_section_info(const char *name, FILE *f, size_t *position_out, size_t *size_out)
{
assert(strlen(name) < 9);
size_t name_length = strlen(name);
assert(name_length < 9);

struct dos_header dos_header = { 0 };
if (!seek_and_read_bytes((uint8_t *)&dos_header, sizeof(dos_header), IMAGE_BASE, f)) {
Expand Down Expand Up @@ -153,7 +154,7 @@ bool find_section_info(const char *name, FILE *f, size_t *position_out, size_t *
return false;
}

if (!strncmp(name, section_header.name, sizeof(section_header.name))) {
if (!strncmp(name, section_header.name, name_length)) {
*size_out = section_header.virtual_size;
*position_out = IMAGE_BASE + section_header.virtual_address;

Expand Down

0 comments on commit 099616d

Please sign in to comment.