Fix a bunch of covs

This commit is contained in:
pancake 2017-04-11 09:57:46 +02:00
parent 28ac810724
commit d8db741a9c
4 changed files with 49 additions and 72 deletions

View File

@ -291,16 +291,16 @@ static void radare2_rc(RCore *r) {
eprintf ("USER CONFIG loaded from %s\n", homerc);
}
r_core_cmd_file (r, homerc);
free (homerc);
}
free (homerc);
homerc = r_str_home (".config/radare2/radare2rc");
if (homerc && r_file_is_regular (homerc)) {
if (has_debug) {
eprintf ("USER CONFIG loaded from %s\n", homerc);
}
r_core_cmd_file (r, homerc);
free (homerc);
}
free (homerc);
homerc = r_str_home (".config/radare2/radare2rc.d");
if (homerc) {
if (r_file_is_directory (homerc)) {

View File

@ -227,6 +227,7 @@ static int internal_esil_mem_read(RAnalEsil *esil, ut64 addr, ut8 *buf, int len)
}
return esil->anal->iob.read_at (esil->anal->iob.io, addr, buf, len);
}
static int internal_esil_mem_read_no_null(RAnalEsil *esil, ut64 addr, ut8 *buf, int len) {
if (!esil || !esil->anal || !esil->anal->iob.io || !addr) {
return 0;
@ -1543,7 +1544,7 @@ static int esil_deceq(RAnalEsil *esil) {
static int esil_poke_n(RAnalEsil *esil, int bits) {
ut64 bitmask = genmask (bits - 1);
ut64 num, addr;
ut8 b[8];
ut8 b[8] = {0};
ut64 n;
char *dst = r_anal_esil_pop (esil);
char *src = r_anal_esil_pop (esil);

View File

@ -235,7 +235,6 @@ static RList *r_bin_wasm_get_type_entries (RBinWasmObj *bin, RBinWasmSection *se
}
static RList *r_bin_wasm_get_import_entries (RBinWasmObj *bin, RBinWasmSection *sec) {
RList *ret = NULL;
RBinWasmImportEntry *ptr = NULL;
@ -249,67 +248,66 @@ static RList *r_bin_wasm_get_import_entries (RBinWasmObj *bin, RBinWasmSection *
ut32 i = 0, r = 0;
while (i < len && r < count) {
if (!(ptr = R_NEW0 (RBinWasmImportEntry))) {
return ret;
}
if (!(consume_u32 (buf + i, buf + len, &ptr->module_len, &i))) {
free (ptr);
return ret;
goto culvert;
}
if (!(consume_str (buf + i, buf + len, ptr->module_len,
ptr->module_str, &i))) {
free (ptr);
return ret;
if (!(consume_str (buf + i, buf + len, ptr->module_len, ptr->module_str, &i))) {
goto culvert;
}
if (!(consume_u32 (buf + i, buf + len, &ptr->field_len, &i))) {
free (ptr);
return ret;
goto culvert;
}
if (!(consume_str (buf + i, buf + len, ptr->field_len, ptr->field_str, &i))) {
free (ptr);
return ret;
goto culvert;
}
if (!(consume_u8 (buf + i, buf + len, &ptr->kind, &i))) {
free (ptr);
return ret;
goto culvert;
}
switch (ptr->kind) {
case 0: // Function
if (!(consume_u32 (buf + i, buf + len, &ptr->type_f, &i))) return 0;
if (!(consume_u32 (buf + i, buf + len, &ptr->type_f, &i))) {
goto sewer;
}
break;
case 1: // Table
if (!(consume_u8 (buf + i, buf + len, (ut8*)&ptr->type_t.elem_type, &i))) return 0; // varint7
if (!(consume_limits (buf + i, buf + len, &ptr->type_t.limits, &i))) return 0;
if (!(consume_u8 (buf + i, buf + len, (ut8*)&ptr->type_t.elem_type, &i))) {
goto sewer; // varint7
}
if (!(consume_limits (buf + i, buf + len, &ptr->type_t.limits, &i))) {
goto sewer;
}
break;
case 2: // Memory
if (!(consume_limits (buf + i, buf + len, &ptr->type_m.limits, &i))) return 0;
if (!(consume_limits (buf + i, buf + len, &ptr->type_m.limits, &i))) {
goto sewer;
}
break;
case 3: // Global
if (!(consume_u8 (buf + i, buf + len, (ut8*)&ptr->type_g.content_type, &i))) return 0; // varint7
if (!(consume_u8 (buf + i, buf + len, (ut8*)&ptr->type_g.mutability, &i))) return 0; // varuint1
if (!(consume_u8 (buf + i, buf + len, (ut8*)&ptr->type_g.content_type, &i))) {
goto sewer; // varint7
}
if (!(consume_u8 (buf + i, buf + len, (ut8*)&ptr->type_g.mutability, &i))) {
goto sewer; // varuint1
}
break;
default:
return 0;
goto sewer;
}
r_list_append (ret, ptr);
r += 1;
r++;
}
return ret;
sewer:
ret = NULL;
culvert:
free (ptr);
return ret;
}
static RList *r_bin_wasm_get_export_entries (RBinWasmObj *bin, RBinWasmSection *sec) {
RList *ret = NULL;
RBinWasmExportEntry *ptr = NULL;
@ -323,7 +321,6 @@ static RList *r_bin_wasm_get_export_entries (RBinWasmObj *bin, RBinWasmSection *
ut32 i = 0, r = 0;
while (i < len && r < count) {
if (!(ptr = R_NEW0 (RBinWasmExportEntry))) {
return ret;
}
@ -349,16 +346,12 @@ static RList *r_bin_wasm_get_export_entries (RBinWasmObj *bin, RBinWasmSection *
}
r_list_append (ret, ptr);
r += 1;
r++;
}
return ret;
}
static RList *r_bin_wasm_get_code_entries (RBinWasmObj *bin, RBinWasmSection *sec) {
RList *ret = NULL;
RBinWasmCodeEntry *ptr = NULL;
@ -667,9 +660,9 @@ static RList *r_bin_wasm_get_element_entries (RBinWasmObj *bin, RBinWasmSection
return ret;
}
// Public functions
RBinWasmObj *r_bin_wasm_init (RBinFile *arch) {
RBinWasmObj *bin = R_NEW0 (RBinWasmObj);
if (!bin) {
return NULL;
@ -681,6 +674,7 @@ RBinWasmObj *r_bin_wasm_init (RBinFile *arch) {
bin->size = (ut32)arch->buf->length;
if (!r_buf_set_bytes (bin->buf, arch->buf->buf, bin->size)) {
r_bin_wasm_destroy (arch);
free (bin);
return NULL;
}
@ -692,7 +686,7 @@ RBinWasmObj *r_bin_wasm_init (RBinFile *arch) {
bin->g_imports = r_bin_wasm_get_imports (bin);
bin->g_exports = r_bin_wasm_get_exports (bin);
bin->g_tables = r_bin_wasm_get_tables (bin);
bin->g_memories= r_bin_wasm_get_memories (bin);
bin->g_memories = r_bin_wasm_get_memories (bin);
bin->g_globals = r_bin_wasm_get_globals (bin);
bin->g_codes = r_bin_wasm_get_codes (bin);
bin->g_datas = r_bin_wasm_get_datas (bin);
@ -701,11 +695,9 @@ RBinWasmObj *r_bin_wasm_init (RBinFile *arch) {
bin->entrypoint = r_bin_wasm_get_entrypoint (bin);
return bin;
}
void r_bin_wasm_destroy (RBinFile *arch) {
RBinWasmObj *bin;
if (!arch || !arch->o || !arch->o->bin_obj) {
@ -733,7 +725,6 @@ void r_bin_wasm_destroy (RBinFile *arch) {
}
RList *r_bin_wasm_get_sections (RBinWasmObj *bin) {
RList *ret = NULL;
RBinWasmSection *ptr = NULL;
@ -884,73 +875,57 @@ RList *r_bin_wasm_get_sections (RBinWasmObj *bin) {
}
ut32 r_bin_wasm_get_entrypoint (RBinWasmObj *bin) {
RList *secs = NULL;
RBinWasmStartEntry *start = NULL;
RBinWasmSection *sec = NULL;
RBinWasmCodeEntry *func = NULL;
if (!bin || !bin->g_sections) {
return 0x0;
return 0;
}
if (bin->entrypoint) {
return bin->entrypoint;
}
if (bin->g_start) {
start = bin->g_start;
} else if (!(secs = r_bin_wasm_get_sections_by_id (bin->g_sections,
R_BIN_WASM_SECTION_START))) {
return 0x0;
} else if (!(secs = r_bin_wasm_get_sections_by_id (bin->g_sections, R_BIN_WASM_SECTION_START))) {
return 0;
} else if (!(sec = (RBinWasmSection*) r_list_first (secs))) {
return 0x0;
return 0;
} else {
start = r_bin_wasm_get_start (bin, sec);
bin->g_start = start;
}
if (!start) {
return 0x0;
return 0;
}
// FIX: entrypoint can be also an import
func = r_list_get_n (r_bin_wasm_get_codes (bin), start->index);
if (!func) {
return 0x0;
}
return (ut32)func->code;
return (ut32)func? func->code: 0;
}
RList *r_bin_wasm_get_imports (RBinWasmObj *bin) {
RBinWasmSection *import = NULL;
RList *imports = NULL;
if (!bin || !bin->g_sections) {
return NULL;
}
if (bin->g_imports) {
return bin->g_imports;
}
if (!(imports = r_bin_wasm_get_sections_by_id (bin->g_sections,
R_BIN_WASM_SECTION_IMPORT))) {
return r_list_new();
}
// support for multiple import sections against spec
if (!(import = (RBinWasmSection*) r_list_first (imports))) {
return r_list_new();
}
bin->g_imports = r_bin_wasm_get_import_entries (bin, import);
return bin->g_imports;
return bin->g_imports = r_bin_wasm_get_import_entries (bin, import);
}
RList *r_bin_wasm_get_exports (RBinWasmObj *bin) {
@ -1012,7 +987,6 @@ RList *r_bin_wasm_get_types (RBinWasmObj *bin) {
}
RList *r_bin_wasm_get_tables (RBinWasmObj *bin) {
RBinWasmSection *table = NULL;
RList *tables = NULL;
@ -1031,11 +1005,13 @@ RList *r_bin_wasm_get_tables (RBinWasmObj *bin) {
// support for multiple export sections against spec
if (!(table = (RBinWasmSection*) r_list_first (tables))) {
r_list_free (tables);
return r_list_new();
}
bin->g_tables = r_bin_wasm_get_table_entries (bin, table);
r_list_free (tables);
return bin->g_tables;
}

View File

@ -2606,7 +2606,7 @@ reread:
char *p, *str;
strstart = 2 + json + ignorecase;
len = strlen (input + strstart);
str = malloc ((len + 1) * 2);
str = calloc ((len + 1), 2);
for (p2 = input + strstart, p = str; *p2; p += 2, p2++) {
if (ignorecase) {
p[0] = tolower ((const ut8) *p2);