fix mem errors

This commit is contained in:
Freya Murphy 2024-09-22 16:44:54 -04:00
parent 85471efb4c
commit bf39d3283b
Signed by: freya
GPG key ID: 744AB800E383AE52
3 changed files with 11 additions and 0 deletions

View file

@ -399,6 +399,10 @@ static int relocate_instruction_rela(struct linker *linker,
/// get the segment that the symbol is in /// get the segment that the symbol is in
struct segment_table_entry *ent; struct segment_table_entry *ent;
const char *segname = seg->obj->shstrtab->data + B32(shdr->sh_name); const char *segname = seg->obj->shstrtab->data + B32(shdr->sh_name);
if (B32(shdr->sh_name) >= seg->obj->shstrtab->len) {
ERROR("relocation segment name out of bounds");
return M_ERROR;
}
if (segtab_get(&linker->segments, &ent, segname)) { if (segtab_get(&linker->segments, &ent, segname)) {
ERROR("could not locate segment for relocation"); ERROR("could not locate segment for relocation");
return M_ERROR; return M_ERROR;

View file

@ -43,6 +43,11 @@ static int load_shdr(struct object *obj, struct segment *seg, size_t index)
} }
seg->name = &obj->shstrtab->data[name]; seg->name = &obj->shstrtab->data[name];
if (seg->phdr->p_filesz != hdr->sh_size) {
ERROR("segment phdr and shdr file sizes to not match");
return M_ERROR;
}
// map bytes // map bytes
uint32_t len = B32(hdr->sh_size); uint32_t len = B32(hdr->sh_size);
uint32_t off = B32(hdr->sh_offset); uint32_t off = B32(hdr->sh_offset);

View file

@ -121,12 +121,14 @@ int segtab_ent_push(struct segment_table_entry *ent, struct segment *seg)
if (first->align != seg->align) { if (first->align != seg->align) {
ERROR("segment '%s' doest not have matching alignment", ERROR("segment '%s' doest not have matching alignment",
ent->name); ent->name);
return M_ERROR;
} }
if (first->read != seg->read || if (first->read != seg->read ||
first->write != seg->write || first->write != seg->write ||
first->execute != seg->execute) { first->execute != seg->execute) {
ERROR("segment '%s' doest not have matching RWX", ERROR("segment '%s' doest not have matching RWX",
ent->name); ent->name);
return M_ERROR;
} }
} else { } else {
ent->off = seg->new_off; ent->off = seg->new_off;