librz/bin/{coff,ecoff}: fix various Coverity issues (#6023)

* Fix Coverity issues on ecoff
* Fix Alpha bitness
* Fix memleak in coff.c
* Fix tests
This commit is contained in:
Giovanni 2026-03-13 00:44:59 +08:00 committed by GitHub
parent e0068f5433
commit d2494fac4a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 10 additions and 11 deletions

View file

@ -475,7 +475,7 @@ RzAnalysisPlugin rz_analysis_plugin_alpha_cs = {
.desc = "DEC Alpha Capstone-based disassembler", .desc = "DEC Alpha Capstone-based disassembler",
.license = "LGPL3", .license = "LGPL3",
.arch = "alpha", .arch = "alpha",
.bits = 64, .bits = 32 | 64,
.get_reg_profile = get_reg_profile, .get_reg_profile = get_reg_profile,
.archinfo = archinfo, .archinfo = archinfo,
.op = rz_analysis_alpha_op, .op = rz_analysis_alpha_op,

View file

@ -106,7 +106,7 @@ RzAsmPlugin rz_asm_plugin_alpha_cs = {
.desc = "DEC Alpha Capstone-based disassembler", .desc = "DEC Alpha Capstone-based disassembler",
.license = "LGPL3", .license = "LGPL3",
.arch = "alpha", .arch = "alpha",
.bits = 64, .bits = 32 | 64,
.endian = RZ_SYS_ENDIAN_LITTLE | RZ_SYS_ENDIAN_BIG, .endian = RZ_SYS_ENDIAN_LITTLE | RZ_SYS_ENDIAN_BIG,
.disassemble = &disassemble, .disassemble = &disassemble,
.init = &init, .init = &init,

View file

@ -344,6 +344,7 @@ RZ_API struct rz_bin_coff_obj *rz_bin_coff_new_buf(RzBuffer *buf) {
if (!coff_guess_endianness(buf, &obj->big_endian)) { if (!coff_guess_endianness(buf, &obj->big_endian)) {
RZ_LOG_ERROR("failed to guess magic & endianness\n"); RZ_LOG_ERROR("failed to guess magic & endianness\n");
rz_bin_coff_free(obj);
return NULL; return NULL;
} else if (!bin_coff_init_hdr(buf, obj, &offset)) { } else if (!bin_coff_init_hdr(buf, obj, &offset)) {
RZ_LOG_ERROR("failed to init hdr\n"); RZ_LOG_ERROR("failed to init hdr\n");

View file

@ -308,8 +308,6 @@ static bool ecoff_parse_symbols_32(RzBuffer *buffer, ECoff_32 *ecoff) {
return ecoff_parse_old_symbols(buffer, ecoff); return ecoff_parse_old_symbols(buffer, ecoff);
} }
return ecoff_parse_local_symbols_32(buffer, ecoff);
return ecoff_parse_local_symbols_32(buffer, ecoff) && return ecoff_parse_local_symbols_32(buffer, ecoff) &&
ecoff_parse_external_symbols_32(buffer, ecoff) && ecoff_parse_external_symbols_32(buffer, ecoff) &&
ecoff_parse_file_descriptor_entries_32(buffer, ecoff) && ecoff_parse_file_descriptor_entries_32(buffer, ecoff) &&
@ -420,9 +418,9 @@ fail:
static ut32 ecoff_section_flags_to_perms(ut64 s_flags) { static ut32 ecoff_section_flags_to_perms(ut64 s_flags) {
ut32 perms = 0; ut32 perms = 0;
if (s_flags & ECOFF_SECTION_TYPE_REG) { if (s_flags == ECOFF_SECTION_TYPE_REG) {
// Regular section: allocated, relocated, loaded. // Regular section: allocated, relocated, loaded.
perms |= RZ_PERM_RWX; return RZ_PERM_RWX;
} }
if (s_flags & ECOFF_SECTION_TYPE_TEXT) { if (s_flags & ECOFF_SECTION_TYPE_TEXT) {
// Text section // Text section

View file

@ -4,7 +4,7 @@ CMDS=aL
EXPECT=<<EOF EXPECT=<<EOF
_dAeI 8 16 6502 LGPL3 6502/NES/C64/Tamagotchi/T-1000 CPU _dAeI 8 16 6502 LGPL3 6502/NES/C64/Tamagotchi/T-1000 CPU
adAeI 8 8051 PD Intel 8051 disassembler adAeI 8 8051 PD Intel 8051 disassembler
_dA__ 64 alpha LGPL3 DEC Alpha Capstone-based disassembler _dA__ 32 64 alpha LGPL3 DEC Alpha Capstone-based disassembler
_dA__ 32 amd29k LGPL3 AMD 29k RISC disassembler (by deroad) _dA__ 32 amd29k LGPL3 AMD 29k RISC disassembler (by deroad)
_dA__ 16 32 arc GPL3 Argonaut RISC Core _dA__ 16 32 arc GPL3 Argonaut RISC Core
adAeI 16 32 64 arm BSD ARM Capstone-based disassembler adAeI 16 32 64 arm BSD ARM Capstone-based disassembler

File diff suppressed because one or more lines are too long