Fix the DEX crash regression with invalid method names (#7635)

This commit is contained in:
radare 2017-05-30 15:44:57 +02:00 committed by GitHub
parent 7d1273d09e
commit f0e1d77a40
2 changed files with 11 additions and 8 deletions

View File

@ -1,4 +1,4 @@
/* radare - LGPL - Copyright 2009-2016 - pancake */
/* radare - LGPL - Copyright 2009-2017 - pancake, h4ng3r */
#include <r_types.h>
#include <r_util.h>

View File

@ -37,8 +37,9 @@ static char *getstr(RBinDexObj *bin, int idx) {
ut8 buf[6];
ut64 len;
int uleblen;
if (!bin || idx < 0 || idx >= bin->header.strings_size ||
!bin->strings) {
// null terminate the buf wtf
bin->b->buf[bin->b->length - 1] = 0;
if (!bin || idx < 0 || idx >= bin->header.strings_size || !bin->strings) {
return "";
}
if (bin->strings[idx] >= bin->size) {
@ -54,10 +55,14 @@ static char *getstr(RBinDexObj *bin, int idx) {
if (!len || len >= bin->size) {
return "";
}
char* ptr = (char*) r_buf_get_at(bin->b, bin->strings[idx] + uleblen, NULL);
char* ptr = (char*) r_buf_get_at (bin->b, bin->strings[idx] + uleblen, NULL);
if (!ptr) {
return "";
}
if (len != strlen (ptr)) {
eprintf ("WARNING: Invalid string for index %d\n", idx);
return "";
}
return ptr;
}
@ -339,8 +344,7 @@ static void dex_parse_debug_item(RBinFile *binfile, RBinDexObj *bin,
return;
}
struct dex_debug_local_t *debug_locals = calloc(sizeof (struct dex_debug_local_t),regsz+1);
memset (debug_locals, 0, sizeof (struct dex_debug_local_t) * regsz);
struct dex_debug_local_t *debug_locals = calloc (sizeof (struct dex_debug_local_t), regsz + 1);
if (!(MA & 0x0008)) {
debug_locals[argReg].name = "this";
debug_locals[argReg].descriptor = r_str_newf("%s;", class_name);
@ -1628,11 +1632,10 @@ static RList* imports(RBinFile *arch) {
}
static RList *methods(RBinFile *arch) {
RBinDexObj *bin;
if (!arch || !arch->o || !arch->o->bin_obj) {
return NULL;
}
bin = (RBinDexObj*) arch->o->bin_obj;
RBinDexObj *bin = (RBinDexObj*) arch->o->bin_obj;
if (!bin->methods_list) {
dex_loadcode (arch, bin);
}