Fix segmentation fault if a NOBITS section is specified as a source section
This commit is contained in:
parent
5b86194734
commit
e09a07b3d3
@ -423,8 +423,16 @@ int elf_patch_compute_crc_over_section(elfpatch_handle_t *ep, const char *sectio
|
|||||||
}
|
}
|
||||||
|
|
||||||
print_debug("Section data length: %lu\n", data->d_size);
|
print_debug("Section data length: %lu\n", data->d_size);
|
||||||
if (!data->d_size)
|
if (!data->d_size) {
|
||||||
print_err("Section %s contains no data.\n", section);
|
print_err("Section %s contains no data.\n", section);
|
||||||
|
return -2;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* NOBIT sections have a length but no data in the file. Abort in this case */
|
||||||
|
if (!data->d_buf) {
|
||||||
|
print_err("Section %s does not contain loadable data.\n", section);
|
||||||
|
return -2;
|
||||||
|
}
|
||||||
|
|
||||||
/* If big endian or granularity is byte, simply compute CRC. No reordering is necessary */
|
/* If big endian or granularity is byte, simply compute CRC. No reordering is necessary */
|
||||||
if (!little_endian || granularity == GRANULARITY_BYTE) {
|
if (!little_endian || granularity == GRANULARITY_BYTE) {
|
||||||
|
@ -407,12 +407,14 @@ int main(int argc, char **argv)
|
|||||||
/* Check if all sections are present */
|
/* Check if all sections are present */
|
||||||
if (check_all_sections_present(ep, cmd_opts.section_list)) {
|
if (check_all_sections_present(ep, cmd_opts.section_list)) {
|
||||||
ret = -2;
|
ret = -2;
|
||||||
goto free_cmds;
|
goto ret_close_elf;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Compute CRCs over sections */
|
/* Compute CRCs over sections */
|
||||||
crcs = (uint32_t *)malloc(sl_list_length(cmd_opts.section_list) * sizeof(uint32_t));
|
crcs = (uint32_t *)malloc(sl_list_length(cmd_opts.section_list) * sizeof(uint32_t));
|
||||||
compute_crcs(ep, cmd_opts.section_list, &cmd_opts, crcs);
|
if (compute_crcs(ep, cmd_opts.section_list, &cmd_opts, crcs)) {
|
||||||
|
goto ret_close_elf;
|
||||||
|
}
|
||||||
|
|
||||||
if (reporting_get_verbosity()) {
|
if (reporting_get_verbosity()) {
|
||||||
print_crcs(cmd_opts.section_list, crcs);
|
print_crcs(cmd_opts.section_list, crcs);
|
||||||
@ -427,6 +429,7 @@ int main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ret_close_elf:
|
||||||
elf_patch_close_and_free(ep);
|
elf_patch_close_and_free(ep);
|
||||||
|
|
||||||
free_cmds:
|
free_cmds:
|
||||||
|
Loading…
Reference in New Issue
Block a user