Skip to content

Commit

Permalink
Fix null derefs in the RBin.io plugin ##bin
Browse files Browse the repository at this point in the history
  • Loading branch information
radare authored and trufae committed Dec 21, 2024
1 parent ebe352c commit bb40b09
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 14 deletions.
24 changes: 10 additions & 14 deletions libr/bin/p/bin_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@ static char *iocmd(RBinFile *bf, const char *s) {
}

static RBinInfo *info(RBinFile *bf) {
char *res = iocmd (bf, "i");
eprintf ("-->(i) %s\n", res);
free (res);
free (iocmd (bf, "i"));
RBinInfo *ret = NULL;
if (!(ret = R_NEW0 (RBinInfo))) {
return NULL;
Expand Down Expand Up @@ -68,9 +66,7 @@ static void addsym(RList *ret, const char *name, ut64 addr) {
#endif

static RList *symbols(RBinFile *bf) {
char *res = iocmd (bf, "is");
eprintf ("-->(is) %s\n", res);
free (res);
free (iocmd (bf, "is"));
RList *ret = r_list_newf (free);
#if 0
addsym (ret, "rom_start", r_read_be32 (&hdr.RomStart));
Expand All @@ -79,9 +75,7 @@ static RList *symbols(RBinFile *bf) {
}

static RList *sections(RBinFile *bf) {
char *res = iocmd (bf, "iS");
eprintf ("-->(iS) %s\n", res);
free (res);
free (iocmd (bf, "iS"));
RList *ret = r_list_new ();
#if 0
RBinSection *ptr;
Expand Down Expand Up @@ -127,11 +121,13 @@ static RList *sections(RBinFile *bf) {
static RList *entries(RBinFile *bf) {
RList *ret = r_list_newf (free);
char *res = iocmd (bf, "ie");
ut64 entry0 = r_num_get (NULL, res);
free (res);
RBinAddr *ptr = R_NEW0 (RBinAddr);
ptr->paddr = ptr->vaddr = entry0;
r_list_append (ret, ptr);
if (res) {
ut64 entry0 = r_num_get (NULL, res);
free (res);
RBinAddr *ptr = R_NEW0 (RBinAddr);
ptr->paddr = ptr->vaddr = entry0;
r_list_append (ret, ptr);
}
return ret;
}

Expand Down
20 changes: 20 additions & 0 deletions test/db/cmd/cmd_ih
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ EXPECT=<<EOF
'fs+header
'f header.ELF 1 0x00000000
'f header.ELF.value 1 0x464c457f
Cd4 @ 0x0
pf.ELF x
'f header.Type 1 0x00000010
'f header.Type.value 1 0x00000002
Expand All @@ -56,17 +57,22 @@ pf.Type w
pf.Machine w
'f header.Version 1 0x00000014
'f header.Version.value 1 0x00000001
Cd4 @ 0x14
pf.Version x
'f header.EntryPoint 1 0x00000018
'f header.EntryPoint.value 1 0x08048300
Cd4 @ 0x18
pf.EntryPoint x
'f header.PhOff 1 0x0000001c
'f header.PhOff.value 1 0x00000034
Cd4 @ 0x1c
pf.PhOff x
'f header.ShOff 1 0x00000020
'f header.ShOff.value 1 0x000007cc
Cd4 @ 0x20
pf.ShOff x
'f header.Flags 1 0x00000024
Cd4 @ 0x24
pf.Flags x
'f header.EhSize 1 0x00000028
'f header.EhSize.value 1 0x00000034
Expand Down Expand Up @@ -99,6 +105,7 @@ EXPECT=<<EOF
"name": "ELF",
"vaddr": 0,
"paddr": 0,
"size": 4,
"value": 1179403647,
"format": "x",
"pf": [
Expand All @@ -113,6 +120,7 @@ EXPECT=<<EOF
"name": "Type",
"vaddr": 16,
"paddr": 16,
"size": 2,
"value": 2,
"format": "w",
"pf": [
Expand All @@ -127,6 +135,7 @@ EXPECT=<<EOF
"name": "Machine",
"vaddr": 18,
"paddr": 18,
"size": 2,
"value": 3,
"format": "w",
"pf": [
Expand All @@ -141,6 +150,7 @@ EXPECT=<<EOF
"name": "Version",
"vaddr": 20,
"paddr": 20,
"size": 4,
"value": 1,
"format": "x",
"pf": [
Expand All @@ -155,6 +165,7 @@ EXPECT=<<EOF
"name": "EntryPoint",
"vaddr": 24,
"paddr": 24,
"size": 4,
"value": 134513408,
"format": "x",
"pf": [
Expand All @@ -169,6 +180,7 @@ EXPECT=<<EOF
"name": "PhOff",
"vaddr": 28,
"paddr": 28,
"size": 4,
"value": 52,
"format": "x",
"pf": [
Expand All @@ -183,6 +195,7 @@ EXPECT=<<EOF
"name": "ShOff",
"vaddr": 32,
"paddr": 32,
"size": 4,
"value": 1996,
"format": "x",
"pf": [
Expand All @@ -197,6 +210,7 @@ EXPECT=<<EOF
"name": "Flags",
"vaddr": 36,
"paddr": 36,
"size": 4,
"format": "x",
"pf": [
{
Expand All @@ -210,6 +224,7 @@ EXPECT=<<EOF
"name": "EhSize",
"vaddr": 40,
"paddr": 40,
"size": 2,
"value": 52,
"format": "w",
"pf": [
Expand All @@ -224,6 +239,7 @@ EXPECT=<<EOF
"name": "PhentSize",
"vaddr": 42,
"paddr": 42,
"size": 2,
"value": 32,
"format": "w",
"pf": [
Expand All @@ -238,6 +254,7 @@ EXPECT=<<EOF
"name": "PhNum",
"vaddr": 44,
"paddr": 44,
"size": 2,
"value": 8,
"format": "w",
"pf": [
Expand All @@ -252,6 +269,7 @@ EXPECT=<<EOF
"name": "ShentSize",
"vaddr": 46,
"paddr": 46,
"size": 2,
"value": 40,
"format": "w",
"pf": [
Expand All @@ -266,6 +284,7 @@ EXPECT=<<EOF
"name": "ShNum",
"vaddr": 48,
"paddr": 48,
"size": 2,
"value": 30,
"format": "w",
"pf": [
Expand All @@ -280,6 +299,7 @@ EXPECT=<<EOF
"name": "ShrStrndx",
"vaddr": 50,
"paddr": 50,
"size": 2,
"value": 27,
"format": "w",
"pf": [
Expand Down
1 change: 1 addition & 0 deletions test/db/formats/mach0/headers
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ EXPECT=<<EOF
"name": "header",
"vaddr": 4294967296,
"paddr": 0,
"size": 1,
"comment": "mach0_header",
"format": "mach0_header",
"pf": [
Expand Down

0 comments on commit bb40b09

Please sign in to comment.