Fix some covs

This commit is contained in:
Álvaro Felipe Melchor 2015-10-29 20:02:13 +01:00 committed by pancake
parent ec2ac9c640
commit 5543f73cb1
8 changed files with 54 additions and 42 deletions

View File

@ -40,8 +40,9 @@ struct r_bin_dyldcache_lib_t *r_bin_dyldcache_extract(struct r_bin_dyldcache_obj
return NULL;
}
curoffset = bin->hdr.startaddr + idx * 32;
if (curoffset+8 >= bin->size) {
if (curoffset + 8 >= bin->size) {
perror ("oob thing");
free (ret);
return NULL;
}
libla = *(ut64*)(bin->b->buf + curoffset);
@ -142,16 +143,14 @@ struct r_bin_dyldcache_lib_t *r_bin_dyldcache_extract(struct r_bin_dyldcache_obj
/* Fill r_bin_dyldcache_lib_t ret */
ret->b = dbuf;
libname = (char*)(bin->b->buf+libpath);
strncpy (ret->path, libname, sizeof (ret->path)-1);
strncpy (ret->path, libname, sizeof (ret->path) - 1);
ret->size = libsz;
return ret;
}
void* r_bin_dyldcache_free(struct r_bin_dyldcache_obj_t* bin) {
if (!bin)
return NULL;
if (bin->b)
r_buf_free (bin->b);
if (!bin) return NULL;
if (bin->b) r_buf_free (bin->b);
free(bin);
return NULL;
}
@ -163,16 +162,16 @@ struct r_bin_dyldcache_obj_t* r_bin_dyldcache_new(const char* file) {
return NULL;
memset (bin, 0, sizeof (struct r_bin_dyldcache_obj_t));
bin->file = file;
if (!(buf = (ut8*)r_file_slurp(file, &bin->size)))
return r_bin_dyldcache_free(bin);
if (!(buf = (ut8*)r_file_slurp (file, &bin->size)))
return r_bin_dyldcache_free (bin);
bin->b = r_buf_new();
if (!r_buf_set_bytes(bin->b, buf, bin->size)) {
if (!r_buf_set_bytes (bin->b, buf, bin->size)) {
free (buf);
return r_bin_dyldcache_free(bin);
return r_bin_dyldcache_free (bin);
}
free (buf);
if (!r_bin_dyldcache_init(bin))
return r_bin_dyldcache_free(bin);
if (!r_bin_dyldcache_init (bin))
return r_bin_dyldcache_free (bin);
return bin;
}
@ -182,11 +181,11 @@ struct r_bin_dyldcache_obj_t* r_bin_dyldcache_from_bytes_new(const ut8* buf, ut6
return NULL;
memset (bin, 0, sizeof (struct r_bin_dyldcache_obj_t));
if (!buf)
return r_bin_dyldcache_free(bin);
return r_bin_dyldcache_free (bin);
bin->b = r_buf_new();
if (!r_buf_set_bytes(bin->b, buf, size))
return r_bin_dyldcache_free(bin);
if (!r_bin_dyldcache_init(bin))
return r_bin_dyldcache_free(bin);
if (!r_buf_set_bytes (bin->b, buf, size))
return r_bin_dyldcache_free (bin);
if (!r_bin_dyldcache_init (bin))
return r_bin_dyldcache_free (bin);
return bin;
}

View File

@ -887,8 +887,8 @@ static int cmd_thread(void *data, const char *input) {
"&", " &&", "run all tasks in background",
"&&", "", "run all pendings tasks (and join threads)",
"&&&", "", "run all pendings tasks until ^C",
"","","TODO: last command should honor asm.bits",
"","","WARN: this feature is very experimental. Use it with caution",
"","","TODO: last command should honor asm.bits",
"","","WARN: this feature is very experimental. Use it with caution",
NULL};
// TODO: integrate with =h& and bg anal/string/searchs/..
r_core_cmd_help (core, help_msg);
@ -1064,6 +1064,7 @@ R_API int r_core_cmd_pipe(RCore *core, char *radare_cmd, char *shell_cmd) {
child = r_sys_fork ();
if (child == -1) {
eprintf ("Cannot fork\n");
close (stdout_fd);
} else if (child) {
dup2 (fds[1], 1);
close (fds[1]);
@ -1733,7 +1734,7 @@ R_API int r_core_cmd_foreach3(RCore *core, const char *cmd, char *each) {
case 'c':
switch (each[1]) {
case 'a': // call
break;
break;
default:
r_meta_list_cb (core->anal, R_META_TYPE_COMMENT, 0, foreach_comment, (void*)cmd);
break;
@ -1793,7 +1794,7 @@ R_API int r_core_cmd_foreach3(RCore *core, const char *cmd, char *each) {
break;
case 's':
// symbols
{
{
RBinSymbol *sym;
ut64 offorig = core->offset;
list = r_bin_get_symbols (core->bin);

View File

@ -204,17 +204,16 @@ static void cmd_write_value (RCore *core, const char *input) {
static bool cmd_wf(RCore *core, const char *input) {
ut8 *buf;
int size;
const char *arg = input + ((input[1] == ' ')? 2: 1);
const char *arg = input + ((input[1] == ' ') ? 2 : 1);
int wseek = r_config_get_i (core->config, "cfg.wseek");
char *p, *a = r_str_chop (strdup (arg));
// XXX: file names cannot contain spaces
p = strchr (a, ' ');
if (p) {
*p++ = 0;
}
if (*arg=='?' || !*arg) {
if (p) *p++ = 0;
if (*arg =='?' || !*arg) {
eprintf ("Usage: wf [file] ([size] ([offset]))\n");
} else
}
if (!strcmp (arg, "-")) {
char *out = r_core_editor (core, NULL, NULL);
if (out) {
@ -222,17 +221,18 @@ static bool cmd_wf(RCore *core, const char *input) {
(ut8*)out, strlen (out));
free (out);
}
} else
}
if ((buf = (ut8*) r_file_slurp (a, &size))) {
int u_size = size;
int u_offset = 0;
u_size = r_num_math (core->num, p);
if (u_size<1) u_size = size;
if (u_size < 1) u_size = size;
if (p) {
*p++ = 0;
u_offset = r_num_math (core->num, p);
if (u_offset > size) {
eprintf ("Invalid offset\n");
free (buf);
return false;
}
}
@ -241,7 +241,9 @@ static bool cmd_wf(RCore *core, const char *input) {
WSEEK (core, size);
free (buf);
r_core_block_read (core, 0);
} else eprintf ("Cannot open file '%s'\n", arg);
} else {
eprintf ("Cannot open file '%s'\n", arg);
}
return true;
}

View File

@ -386,9 +386,10 @@ static int r_core_file_do_load_for_io_plugin (RCore *r, ut64 baseaddr, ut64 load
if (plugin && !strcmp (plugin->name, "any") ) {
RBinObject *obj = r_bin_get_object (r->bin);
RBinInfo * info = obj ? obj->info : NULL;
if (!info) return false;
// set use of raw strings
r_core_bin_set_arch_bits (r, binfile->file,
info->arch, info->bits);
r_core_bin_set_arch_bits (r, binfile->file,
info->arch, info->bits);
r_config_set_i (r->config, "io.va", false);
// r_config_set (r->config, "bin.rawstr", "true");
// get bin.minstr
@ -397,6 +398,7 @@ static int r_core_file_do_load_for_io_plugin (RCore *r, ut64 baseaddr, ut64 load
} else if (binfile) {
RBinObject *obj = r_bin_get_object (r->bin);
RBinInfo * info = obj ? obj->info : NULL;
if (!info) return false;
if (plugin && strcmp (plugin->name, "any") && info) {
r_core_bin_set_arch_bits (r, binfile->file,
info->arch, info->bits);

View File

@ -1642,6 +1642,8 @@ static int get_cgnodes(RAGraph *g, RCore *core, RAnalFunction *fcn) {
RAnalRef *ref;
char *title, *body;
if (!f) return false;
r_core_seek (core, f->addr, 1);
title = get_title (fcn->addr);
@ -2171,6 +2173,7 @@ static int agraph_refresh(struct agraph_refresh_data *grd) {
if (!acur || strcmp (acur->title, title) != 0) {
r_core_cmd0 (core, "sr pc");
}
free (title);
g->is_instep = false;
}

View File

@ -715,7 +715,7 @@ static void rcc_next(REgg *egg) {
int i;
if (setenviron) {
elem[elem_n-1] = 0;
elem[elem_n - 1] = 0;
r_sys_setenv (setenviron, elem);
R_FREE (setenviron);
return;
@ -742,7 +742,9 @@ static void rcc_next(REgg *egg) {
r_egg_lang_parsechar (egg, *p);
free (q);
line = oline;
} else eprintf ("Cannot find '%s'\n", path);
} else {
eprintf ("Cannot find '%s'\n", path);
}
free (path);
return;
}
@ -768,6 +770,7 @@ static void rcc_next(REgg *egg) {
//ocn = ptr+1; // what is the point of this?
}
ocn = skipspaces (callname);
if (!ocn) return;
str = r_egg_mkvar (egg, buf, ocn, 0);
if (!str) {
eprintf ("Cannot mkvar\n");
@ -775,10 +778,9 @@ static void rcc_next(REgg *egg) {
}
if (*ocn=='.')
e->call (egg, str, 1);
else
if (!strcmp (str, "while")) {
char var[128];
if (lastctxdelta>=0)
if (lastctxdelta >= 0)
exit (eprintf ("ERROR: Unsupported while syntax\n"));
sprintf (var, "__begin_%d_%d_%d\n", nfunctions, CTX, nestedi[CTX-1]);
e->while_end (egg, var); //get_frame_label (1));
@ -800,7 +802,7 @@ static void rcc_next(REgg *egg) {
#endif
nargs = 0;
} else {
for (i=0; i<nsyscalls; i++) {
for (i = 0; i < nsyscalls; i++) {
if (!strcmp (str, syscalls[i].name)) {
p = syscallbody;
e->comment (egg, "set syscall args");
@ -824,7 +826,7 @@ static void rcc_next(REgg *egg) {
}
}
if (docall)
for (i=0; i<ninlines; i++) {
for (i = 0; i < ninlines; i++) {
if (!strcmp (str, inlines[i].name)) {
p = inlines[i].body;
docall = 0;
@ -841,7 +843,7 @@ static void rcc_next(REgg *egg) {
e->call (egg, str, 0);
}
}
if (nargs>0)
if (nargs > 0)
e->restore_stack (egg, nargs*e->size);
if (ocn) { // Used to call .var0()
/* XXX: Probably buggy and wrong */

View File

@ -124,7 +124,7 @@ R_API ut64 r_reg_set_bvalue(RReg *reg, RRegItem *item, const char *str) {
ut64 num = UT64_MAX;
if (item && item->flags && str) {
num = r_str_bits_from_string (str, item->flags);
if (num == UT64_MAX)
if (num == UT64_MAX)
num = r_num_math (NULL, str);
r_reg_set_value (reg, item, num);
}
@ -147,7 +147,7 @@ R_API R_HEAP char *r_reg_get_bvalue(RReg *reg, RRegItem *item) {
/* packed registers */
// packbits can be 8, 16, 32 or 64
// result value is always casted into ut64
// TODO: use item->packed_size
// TODO: use item->packed_size
R_API ut64 r_reg_get_pack(RReg *reg, RRegItem *item, int packidx, int packbits) {
int packbytes, packmod;
ut64 ret = 0LL;

View File

@ -277,7 +277,10 @@ R_API char * convert_string (const char * bytes, ut32 len) {
memset (cpy_buffer, 0, str_sz);
while (idx < len && pos < len) {
if (dso_json_char_needs_hexing (bytes[idx])) {
if (pos + 2 < len) return NULL;
if (pos + 2 < len) {
free (cpy_buffer);
return NULL;
}
sprintf (cpy_buffer+pos, "\\x%02x", bytes[idx]);
pos += 4;
} else {