Fix #19964 - show relro:no even if no dyn section is found ##bin

This commit is contained in:
pancake 2023-06-03 21:45:32 +02:00
parent fecabf315f
commit 6ed6b591d4
7 changed files with 54 additions and 25 deletions

View File

@ -326,3 +326,4 @@ Are you still watching?
Starting application, this might take some time...
Do you want to restart to install these updates now or try tonight?
Updates available
This binary has not been analyzed. Would you like to analyze it now?

View File

@ -517,23 +517,6 @@ static Elf_(Phdr) *get_dynamic_segment(ELFOBJ *eo) {
return NULL;
}
static void init_dynamic_section_sdb(ELFOBJ *eo, Elf_(Addr) strtabaddr, size_t strsize) {
int r = Elf_(has_relro) (eo);
switch (r) {
case R_ELF_FULL_RELRO:
sdb_set (eo->kv, "elf.relro", "full", 0);
break;
case R_ELF_PART_RELRO:
sdb_set (eo->kv, "elf.relro", "partial", 0);
break;
default:
sdb_set (eo->kv, "elf.relro", "no", 0);
break;
}
sdb_num_set (eo->kv, "elf_strtab.offset", strtabaddr, 0);
sdb_num_set (eo->kv, "elf_strtab.size", strsize, 0);
}
static void set_default_value_dynamic_info(ELFOBJ *eo) {
eo->dyn_info.dt_pltrelsz = 0;
eo->dyn_info.dt_pltgot = R_BIN_ELF_ADDR_MAX;
@ -724,23 +707,27 @@ static int init_dynamic_section(ELFOBJ *eo) {
if (!strtabaddr) {
R_LOG_DEBUG ("DT_STRTAB not found or invalid");
}
eprintf ("err\n");
return false;
}
char *strtab = calloc (1, strsize + 1);
if (!strtab) {
eprintf ("some\n");
return false;
}
int r = r_buf_read_at (eo->b, strtabaddr, (ut8 *)strtab, strsize);
if (r != strsize) {
free (strtab);
eprintf ("early\n");
return false;
}
eo->strtab = strtab;
eo->strtab_size = strsize;
init_dynamic_section_sdb (eo, strtabaddr, strsize);
sdb_num_set (eo->kv, "elf_strtab.offset", strtabaddr, 0);
sdb_num_set (eo->kv, "elf_strtab.size", strsize, 0);
return true;
}
@ -1534,6 +1521,21 @@ static bool init_dynstr(ELFOBJ *eo) {
static const RVector *_load_elf_sections(ELFOBJ *eo);
static void relro_insdb(ELFOBJ *eo) {
int r = Elf_(has_relro) (eo);
switch (r) {
case R_ELF_FULL_RELRO:
sdb_set (eo->kv, "elf.relro", "full", 0);
break;
case R_ELF_PART_RELRO:
sdb_set (eo->kv, "elf.relro", "partial", 0);
break;
default:
sdb_set (eo->kv, "elf.relro", "no", 0);
break;
}
}
static bool elf_init(ELFOBJ *eo) {
// eo is not an ELF
if (!init_ehdr (eo)) {
@ -1557,6 +1559,7 @@ static bool elf_init(ELFOBJ *eo) {
R_LOG_DEBUG ("Cannot initialize dynamic section");
}
}
relro_insdb (eo);
eo->imports_by_ord_size = 0;
eo->imports_by_ord = NULL;

View File

@ -1035,9 +1035,11 @@ static int bin_info(RCore *r, PJ *pj, int mode, ut64 laddr) {
pair_bool (pj, "pic", info->has_pi);
pair_bool (pj, "relocs", R_BIN_DBG_RELOCS & info->dbg_info);
Sdb *sdb_info = sdb_ns (obj->kv, "info", false);
tmp_buf = sdb_get (sdb_info, "elf.relro", 0);
if (tmp_buf) {
pair_str (pj, "relro", tmp_buf);
if (sdb_info) {
tmp_buf = sdb_get (sdb_info, "elf.relro", 0);
if (R_STR_ISNOTEMPTY (tmp_buf)) {
pair_str (pj, "relro", tmp_buf);
}
free (tmp_buf);
}
pair_str (pj, "rpath", info->rpath);

View File

@ -98,10 +98,8 @@ static RCoreHelpMessage help_msg_CS = {
};
static RCoreHelpMessage help_msg_Cs = {
"Usage:", "Cs[ga-*.] [size] [@addr]", "",
"NOTE:", " size", "1 unit in bytes == width in bytes of smallest possible char in encoding,",
"", "", " so ascii/latin1/utf8 = 1, utf16le = 2",
" Cz", " [size] [@addr]", "ditto",
"Usage:", "Cs[ga-*.] ([size]) [@addr]", "",
"Cz", " [size] [@addr]", "ditto",
"Cs", " [size] @addr", "add string (guess latin1/utf16le)",
"Cs", "", "list all strings in human friendly form",
"Cs*", "", "list all strings in r2 commands",

23
test/db/formats/elf/relro Normal file
View File

@ -0,0 +1,23 @@
NAME=relro partial
FILE=bins/elf/relro/true32
CMDS=ij~{bin.relro}
EXPECT=<<EOF
partial
EOF
RUN
NAME=relro no
FILE=bins/elf/relro/top
CMDS=ij~{bin.relro}
EXPECT=<<EOF
no
EOF
RUN
NAME=relro full
FILE=bins/elf/relro/netifd
CMDS=ij~{bin.relro}
EXPECT=<<EOF
full
EOF
RUN

View File

@ -462,6 +462,7 @@ nx false
os linux
pic false
relocs true
relro no
rpath NONE
sanitize false
static true

View File

@ -45,6 +45,7 @@ nx false
os linux
pic false
relocs true
relro no
rpath NONE
sanitize false
static true