Fix latest 26 COVs

This commit is contained in:
pancake 2016-06-14 23:42:40 +02:00
parent 7fa01a72ed
commit e032a48cbe
6 changed files with 101 additions and 62 deletions

View File

@ -1105,10 +1105,10 @@ SETNP/SETPO - Set if No Parity / Set if Parity Odd (386+)
ut8 rm_byte = 0x40;
int argk = (*arg == '[');
ut64 t;
if (*arg2 == '-') {
if (arg2 && *arg2 == '-') {
N = -1;
// Don't modify arg2 here as sign is needed further down
t = r_num_math (NULL, arg2+1);
t = r_num_math (NULL, arg2 + 1);
} else {
t = r_num_math (NULL, arg2);
}

View File

@ -4213,14 +4213,18 @@ static int cmd_anal_all(RCore *core, const char *input) {
break;
}
case 'e': // "aae"
{
char *len = strdup (input + 1);
char *addr = (len && *len) ? strchr (len + 1, ' ') : NULL;
if (addr) {
*addr++ = 0;
if (input[1] == ' ') {
char *len = strdup (input + 2);
if (len) {
char *addr = strchr (len, ' ');
if (addr) {
*addr++ = 0;
}
r_core_anal_esil (core, len, addr);
free (len);
}
r_core_anal_esil (core, len, addr);
free (len);
} else {
r_core_anal_esil (core, "$SS", NULL);
}
break;
case 'r':

View File

@ -574,9 +574,11 @@ void r_comment_vars (RCore *core, const char *input) {
//TODO enable base64 and make it the default for C*
RAnalFunction *fcn = r_anal_get_fcn_in (core->anal, core->offset, 0);
int idx;
char *name;
char *oldcomment;
char *oname = NULL, *name = NULL;
char *oldcomment = NULL;
char *heap_comment = NULL;
RAnalVar *var;
if (input[1] == '?') {
r_comment_var_help (core, input[0]);
return;
@ -585,7 +587,7 @@ void r_comment_vars (RCore *core, const char *input) {
eprintf ("Cant find function here\n");
return;
}
name = strdup (input + 2);
oname = name = strdup (input + 2);
while (*name == ' ') {
name++;
}
@ -610,13 +612,14 @@ void r_comment_vars (RCore *core, const char *input) {
}
break;
case ' ': {
//TODO check that idx exist
// TODO check that idx exist
char *comment = strstr (name, " ");
if (comment && *comment) {
*comment ++=0;
}
if (!strncmp (comment, "base64:", 7)) {
comment = (char *)sdb_decode (comment + 7, NULL);
heap_comment = (char *)sdb_decode (comment + 7, NULL);
comment = heap_comment;
}
var = r_anal_var_get_byname (core->anal, fcn, input[0], name);
if (var) {
@ -627,24 +630,26 @@ void r_comment_vars (RCore *core, const char *input) {
idx = -(int) r_num_get (NULL, name+1);
} else {
eprintf ("cant find variable named `%s`\n",name);
free (heap_comment);
break;
}
if (!r_anal_var_get (core->anal, fcn->addr, input[0],1 ,idx)) {
eprintf ("cant find variable at given offset\n");
break;
}
oldcomment = r_meta_get_var_comment (core->anal, input[0], idx, fcn->addr);
if (oldcomment) {
if (!comment || !*comment) {
r_cons_printf ("%s\n", oldcomment);
break;
}
char *text = r_str_newf ("%s\n%s", oldcomment, comment);
r_meta_set_var_comment (core->anal, input[0], idx, fcn->addr, text);
free (text);
} else {
r_meta_set_var_comment (core->anal, input[0], idx, fcn->addr, comment);
oldcomment = r_meta_get_var_comment (core->anal, input[0], idx, fcn->addr);
if (oldcomment) {
if (comment && *comment) {
char *text = r_str_newf ("%s\n%s", oldcomment, comment);
r_meta_set_var_comment (core->anal, input[0], idx, fcn->addr, text);
free (text);
} else {
r_cons_printf ("%s\n", oldcomment);
}
} else {
r_meta_set_var_comment (core->anal, input[0], idx, fcn->addr, comment);
}
}
free (heap_comment);
}
break;
case '-':
@ -684,6 +689,7 @@ void r_comment_vars (RCore *core, const char *input) {
}
break;
}
free (oname);
}
static int cmd_meta(void *data, const char *input) {

View File

@ -767,7 +767,9 @@ static RList *r_debug_native_map_get (RDebug *dbg) {
region[1] = region2[1] = 'x';
#if __KFBSD__
list = r_debug_native_sysctl_map (dbg);
if (list != NULL) return list;
if (list) {
return list;
}
snprintf (path, sizeof (path), "/proc/%d/map", dbg->pid);
#else
snprintf (path, sizeof (path), "/proc/%d/maps", dbg->pid);
@ -791,30 +793,32 @@ static RList *r_debug_native_map_get (RDebug *dbg) {
if (!fgets (line, sizeof (line), fd))
break;
/* kill the newline if we got one */
line_len = strlen(line);
line_len = strlen (line);
if (line[line_len - 1] == '\n') {
line[line_len - 1] = '\0';
line_len--;
}
/* maps files should not have empty lines */
if (line_len == 0)
if (line_len == 0) {
break;
}
#if __KFBSD__
// 0x8070000 0x8072000 2 0 0xc1fde948 rw- 1 0 0x2180 COW NC vnode /usr/bin/gcc
if (sscanf (line, "%s %s %d %d 0x%s %3s %d %d",
&region[2], &region2[2], &ign, &ign,
unkstr, perms, &ign, &ign) != 8) {
eprintf ("%s: Unable to parse \"%s\"\n", __func__, path);
r_list_free (list);
return NULL;
}
/* snag the file name */
pos_c = strchr (line, '/');
if (pos_c)
if (pos_c) {
strncpy (name, pos_c, sizeof (name) - 1);
else
} else {
name[0] = '\0';
}
#else
// 7fc8124c4000-7fc81278d000 r--p 00000000 fc:00 17043921 /usr/lib/locale/locale-archive
i = sscanf (line, "%s %s %*s %*s %*s %[^\n]", &region[2], perms, name);
@ -823,6 +827,7 @@ static RList *r_debug_native_map_get (RDebug *dbg) {
} else if (i != 3) {
eprintf ("%s: Unable to parse \"%s\"\n", __func__, path);
eprintf ("%s: problematic line: %s\n", __func__, line);
r_list_free (list);
return NULL;
}
@ -853,8 +858,9 @@ static RList *r_debug_native_map_get (RDebug *dbg) {
}
map = r_debug_map_new (name, map_start, map_end, perm, 0);
if (!map)
if (!map) {
break;
}
map->file = strdup (name);
r_list_append (list, map);
}

View File

@ -23,12 +23,12 @@ typedef Elf32_Nhdr elf_nhdr_t;
typedef ut64 elf_offset_t;
#endif
#define fmt_addr "%08lx-%08lx"
#define ELF_HDR_SIZE sizeof(elf_hdr_t)
#define fmt_addr "%08lx-%08lx"
#define ELF_HDR_SIZE sizeof(elf_hdr_t)
/*Some fields from note section must be padded to 4 or 8 bytes*/
#define round_up(a) ((((a) + (4) - (1)) / (4)) * (4))
#define sizeof_round_up(b) round_up(sizeof(b))
#define round_up(a) ((((a) + (4) - (1)) / (4)) * (4))
#define sizeof_round_up(b) round_up(sizeof(b))
static map_file_t mapping_file = { 0, 0 };
static note_info_t note_info[NT_LENGHT_T];
@ -184,17 +184,17 @@ static proc_per_thread_t *get_proc_thread_content (int pid, int tid) {
p_sighold[temp_p_sighold - p_sighold - 1] = '\0';
t->sigpend = atoi (p_sigpend);
t->sighold = atoi (p_sighold);
free (buff);
return t;
}
static prstatus_t *linux_get_prstatus(int pid, int tid, proc_content_t *proc_data, short int signr) {
elf_gregset_t regs;
prstatus_t *p = R_NEW0 (prstatus_t);
prstatus_t *p;
proc_data->per_thread = get_proc_thread_content (pid, tid);
if (!proc_data->per_thread) return NULL;
p = R_NEW0 (prstatus_t);
if (!p) return NULL;
p->pr_cursig = p->pr_info.si_signo = signr;
p->pr_pid = proc_data->per_process->pid;
@ -215,6 +215,7 @@ static prstatus_t *linux_get_prstatus(int pid, int tid, proc_content_t *proc_dat
if (ptrace (PTRACE_GETREGS, tid, NULL, &regs) < 0) {
perror ("PTRACE_GETREGS");
free (proc_data->per_thread);
free (p);
return NULL;
}
memcpy (p->pr_reg, &regs, sizeof (regs));
@ -224,7 +225,6 @@ static prstatus_t *linux_get_prstatus(int pid, int tid, proc_content_t *proc_dat
static elf_fpregset_t *linux_get_fp_regset(int pid) {
elf_fpregset_t *p = R_NEW0 (elf_fpregset_t);
if (p) {
if (ptrace (PTRACE_GETFPREGS, pid, NULL, p) < 0) {
perror ("PTRACE_GETFPREGS");
@ -505,7 +505,9 @@ static linux_map_entry_t *linux_get_mapped_files(RDebug *dbg, ut8 filter_flags)
R_FREE (file);
ret = r_debug_map_sync (dbg);
if (!ret) return NULL;
if (!ret) {
goto error;
}
r_list_foreach (dbg->maps, iter, map) {
linux_map_entry_t *pmentry = R_NEW0 (linux_map_entry_t);
if (!pmentry) goto error;
@ -828,20 +830,30 @@ static proc_per_process_t *get_proc_process_content (RDebug *dbg) {
return NULL;
}
temp_p_uid = strstr (buff, "Uid:");
temp_p_gid = strstr (buff, "Gid:");
/* Uid */
while (!isdigit (*temp_p_uid++)) {}
p_uid = temp_p_uid - 1;
while (isdigit (*temp_p_uid++)) {}
p_uid[temp_p_uid - p_uid - 1] = '\0';
/* Gid */
while (!isdigit (*temp_p_gid++)) {}
p_gid = temp_p_gid - 1;
while (isdigit (*temp_p_gid++)) {}
p_gid[temp_p_gid - p_gid - 1] = '\0';
temp_p_uid = strstr (buff, "Uid:");
if (temp_p_uid) {
while (!isdigit (*temp_p_uid++)) {}
p_uid = temp_p_uid - 1;
while (isdigit (*temp_p_uid++)) {}
p_uid[temp_p_uid - p_uid - 1] = '\0';
} else {
p_uid = 0;
}
p->uid = atoi (p_uid);
/* Gid */
temp_p_gid = strstr (buff, "Gid:");
if (temp_p_uid) {
while (!isdigit (*temp_p_gid++)) {}
p_gid = temp_p_gid - 1;
while (isdigit (*temp_p_gid++)) {}
p_gid[temp_p_gid - p_gid - 1] = '\0';
} else {
p_gid = 0;
}
p->gid = atoi (p_gid);
free (buff);
/* Check the coredump_filter value if we have*/
@ -961,9 +973,10 @@ void write_note_hdr (note_type_t type, ut8 **note_data) {
note_type = NT_X86_XSTATE;
nhdr.n_descsz = note_info[type].size;
break;
case NT_LENGHT_T:
/* TODO: not yet implemented */
break;
default:
/* shouldnt happen */
memset (*note_data, 0, size_note_hdr);
return;
}
nhdr.n_type = note_type;
@ -981,7 +994,8 @@ static int *get_unique_thread_id (RDebug *dbg, int n_threads) {
RListIter *it;
RList *list;
RDebugPid *th;
int *thread_id, i = 0;
int *thread_id = NULL;
int i = 0;
bool found = false;
if (dbg->h) {
@ -1204,8 +1218,8 @@ static ut8 *build_note_section(RDebug *dbg, elf_proc_note_t *elf_proc_note, proc
note_data += note_info[type].size_roundedup;
detach_threads (dbg, thread_id, elf_proc_note->n_threads);
free (thread_id);
return pnote_data;
fail:
free (elf_proc_note->thread_note->siginfo);
free (elf_proc_note->thread_note->prstatus);
@ -1216,6 +1230,7 @@ fail:
free (elf_proc_note->thread_note->xsave_data);
free (pnote_data);
free (maps_data);
free (thread_id);
return NULL;
}
@ -1323,6 +1338,7 @@ bool linux_generate_corefile (RDebug *dbg, RBuffer *dest) {
}
proc_data = R_NEW0 (proc_content_t);
if (!proc_data) {
free (elf_proc_note);
return false;
}
proc_data->per_process = get_proc_process_content (dbg);
@ -1385,6 +1401,7 @@ bool linux_generate_corefile (RDebug *dbg, RBuffer *dest) {
cleanup:
may_clean_all (elf_proc_note, proc_data, elf_hdr);
free (shdr_pxnum);
free (note_data);
return !error;
}
#endif

View File

@ -338,9 +338,11 @@ static RIODesc *r_io_zip_open(RIO *io, const char *file, int rw, int mode) {
if (!strcmp (name, chkstr)) {
zip_filename = r_str_newf ("//%s", chkstr);
free (chkstr);
free (bin_name);
break;
}
free (chkstr);
free (bin_name);
}
}
}
@ -373,6 +375,7 @@ static RIODesc *r_io_zip_open(RIO *io, const char *file, int rw, int mode) {
ZIP_CREATE, mode, rw);
} else {
filename_in_zipfile = r_str_newf ("%s", zip_filename);
free (zip_filename);
zip_filename = strdup (pikaboo + 3);
if (!strcmp (zip_filename, filename_in_zipfile)) {
//R_FREE (zip_filename);
@ -406,8 +409,7 @@ static RIODesc *r_io_zip_open(RIO *io, const char *file, int rw, int mode) {
}
r_list_free (files);
}
free (zip_uri);
return res;
goto done;
}
//eprintf("After parsing the given uri: %s\n", file);
//eprintf("Zip filename the given uri: %s\n", zip_filename);
@ -417,8 +419,9 @@ static RIODesc *r_io_zip_open(RIO *io, const char *file, int rw, int mode) {
filename_in_zipfile, ZIP_CREATE, mode, rw);
if (zfo) {
if (zfo->entry == -1)
if (zfo->entry == -1) {
eprintf ("Warning: File did not exist, creating a new one.\n");
}
zfo->io_backref = io;
res = r_io_desc_new (&r_io_plugin_zip, zfo->fd,
zfo->name, rw, mode, zfo);
@ -431,8 +434,10 @@ static RIODesc *r_io_zip_open(RIO *io, const char *file, int rw, int mode) {
r_io_desc_free (res);
res = NULL;
}
free (zip_uri);
done:
free (filename_in_zipfile);
free (zip_filename);
free (zip_uri);
return res;
}
@ -440,8 +445,9 @@ static ut64 r_io_zip_lseek(RIO *io, RIODesc *fd, ut64 offset, int whence) {
RIOZipFileObj *zfo;
ut64 seek_val = 0;
if (!fd || !fd->data)
if (!fd || !fd->data) {
return -1;
}
zfo = fd->data;
seek_val = zfo->b->cur;