fix r_cons_get_buffer to avoid return trash

This commit is contained in:
Álvaro Felipe Melchor 2016-11-18 12:59:27 +01:00
parent 91b67d90b6
commit e14b2a37d6
3 changed files with 15 additions and 6 deletions

View File

@ -428,7 +428,8 @@ R_API void r_cons_reset() {
}
R_API const char *r_cons_get_buffer() {
return I.buffer;
//check len otherwise it will return trash
return I.buffer_len? I.buffer : NULL;
}
R_API void r_cons_filter() {

View File

@ -2434,10 +2434,15 @@ R_API int r_core_cmd_foreach(RCore *core, const char *cmd, char *each) {
continue;
}
if (r_str_glob (flag->name, word)) {
char *buf = NULL;
const char *tmp = NULL;
r_core_seek (core, flag->offset, 1);
r_cons_push ();
r_core_cmd (core, cmd, 0);
char *buf = strdup (r_cons_get_buffer ());
tmp = r_cons_get_buffer ();
if (tmp) {
buf = tmp? strdup (tmp): NULL;
}
r_cons_pop ();
r_cons_strcat (buf);
free (buf);

View File

@ -332,18 +332,21 @@ static int cmd_zign(void *data, const char *input) {
eprintf("No functions found, please run some analysis before.\n");
return false;
}
if (!(it = r_list_find (core->anal->fcns, (const void *)core->offset, (RListComparator)fcn_offset_cmp))) {
if (!(it = r_list_find (
core->anal->fcns,
(const void *)core->offset,
(RListComparator)fcn_offset_cmp))) {
return false;
}
fcni = (RAnalFunction*)it->data;
if (r_cons_singleton ()->breaked)
if (r_cons_singleton ()->breaked) {
break;
}
len = r_anal_fcn_realsize (fcni);
if (!(buf = malloc (len))) {
return false;
}
if (r_io_read_at (core->io, fcni->addr, buf,
len) == len) {
if (r_io_read_at (core->io, fcni->addr, buf, len) == len) {
si = r_sign_check (core->sign, buf, len);
if (si) {
old_fs = core->flags->space_idx;