Fix #559 - Fix segfault (workarounds)

This commit is contained in:
pancake 2014-01-21 15:40:10 +01:00
parent 4f73ee605b
commit 48273ec2ed
6 changed files with 26 additions and 21 deletions

View File

@ -38,7 +38,7 @@ Assemble opcodes with the 'a' and 'A' keys in visual mode which are hooks for th
Find expanded AES keys in memory with /a command
Find wide-char strings with /w <string> command
Enable ascii-art jump lines in disassembly with asm.lines. asm.linesout and asm.linestyle may interest you too
Control the signal handlers of the child process with the '!signal' command
Control the signal handlers of the child process with the 'dk' command
Get a free shell with 'rasc -i x86.linux.binsh -X'
Interpret your own radare scripts with '. <path-to-your-script>'. Similar to the bash source alias command.
Most of commands accept an '?' as suffix. Use it to understand how they work :)

View File

@ -1,14 +1,14 @@
/* radare - LGPL - Copyright 2011-2013 - earada, pancake */
/* radare - LGPL - Copyright 2011-2014 - earada, pancake */
#include <r_core.h>
R_API void r_core_bin_set_by_fd (RCore *core, ut64 bin_fd) {
RListIter *iter;
RBinFile *binfile = NULL, *tmp_binfile;
RBinFile *bf;
r_list_foreach (core->bin->binfiles, iter, tmp_binfile) {
if (tmp_binfile && tmp_binfile->fd == bin_fd) {
core->bin->cur = tmp_binfile;
r_list_foreach (core->bin->binfiles, iter, bf) {
if (bf && bf->fd == bin_fd) {
core->bin->cur = bf;
break;
}
}

View File

@ -363,14 +363,14 @@ R_API void r_core_file_free(RCoreFile *cf) {
//if (cf->map) free(cf->map);
free (cf->filename);
free (cf->uri);
// XXX: already done by someone else :)
r_io_desc_free (cf->fd);
cf->fd = NULL;
cf->map = NULL;
cf->filename = NULL;
cf->uri = NULL;
free(cf);
// XXX avoid segfault
// free (cf);
}
cf = NULL;
}
@ -417,8 +417,11 @@ R_API int r_core_file_close_fd(RCore *core, int fd) {
if (file->fd->fd == fd) {
r_io_close (core->io, file->fd);
r_list_delete (core->files, iter);
//r_io_raise (core->io, fd);
#if 0
if (r_list_empty (core->files))
core->file = NULL;
#endif
return R_TRUE;
}
}

View File

@ -82,9 +82,9 @@ R_API BfvmCPU *bfvm_free(BfvmCPU *c) {
R_API ut8 *bfvm_get_ptr_at(BfvmCPU *c, ut64 at) {
if (at >= c->base) at -= c->base;
if (at<0) at = c->circular? c->size-2: 0;
//if (at<0) at = c->circular? c->size-2: 0;
else if (at >= c->size) at = c->circular? 0: c->size-1;
if (at<0) return c->mem;
//if (at<0) return c->mem;
return c->mem+at;
}
@ -203,12 +203,12 @@ R_API int bfvm_step(BfvmCPU *c, int over) {
case ']':
if (bfvm_get (c) != 0) {
do {
c->eip--;
/* control underflow */
if (c->eip<0) {
if (c->eip < (c->eip-1)) {
c->eip = 0;
break;
}
c->eip--;
} while (bfvm_op (c)!='[');
}
break;

View File

@ -1,10 +1,10 @@
/* radare - LGPL - Copyright 2008-2013 - pancake */
/* radare - LGPL - Copyright 2008-2014 - pancake */
#include "r_io.h"
#include "r_util.h"
#include <stdio.h>
R_LIB_VERSION(r_io);
R_LIB_VERSION (r_io);
// TODO: R_API int r_io_fetch(struct r_io_t *io, ut8 *buf, int len)
// --- check for EXEC perms in section (use cached read to accelerate)
@ -24,12 +24,12 @@ R_API RIO *r_io_new() {
io->plugin = NULL;
io->raised = -1;
io->off = 0;
r_io_cache_init (io);
r_io_map_init (io);
r_io_section_init (io);
r_io_plugin_init (io);
r_io_desc_init (io);
r_io_undo_init (io);
r_io_cache_init (io);
r_io_plugin_init (io);
r_io_section_init (io);
return io;
}
@ -43,7 +43,7 @@ R_API int r_io_is_listener(RIO *io) {
return R_FALSE;
}
R_API RBuffer *r_io_read_buf(struct r_io_t *io, ut64 addr, int len) {
R_API RBuffer *r_io_read_buf(RIO *io, ut64 addr, int len) {
RBuffer *b = R_NEW (RBuffer);
b->buf = malloc (len);
len = r_io_read_at (io, addr, b->buf, len);
@ -51,7 +51,7 @@ R_API RBuffer *r_io_read_buf(struct r_io_t *io, ut64 addr, int len) {
return b;
}
R_API int r_io_write_buf(struct r_io_t *io, struct r_buf_t *b) {
R_API int r_io_write_buf(RIO *io, struct r_buf_t *b) {
return r_io_write_at (io, b->base, b->buf, b->length);
}

View File

@ -59,8 +59,10 @@ static int __close(RIODesc *fd) {
return 0;
}
static ut64 __lseek(struct r_io_t *io, RIODesc *fd, ut64 offset, int whence) {
static ut64 __lseek(RIO* io, RIODesc *fd, ut64 offset, int whence) {
ut64 r_offset = offset;
if (!fd->data)
return offset;
switch (whence) {
case SEEK_SET:
r_offset = (offset <= RIOMALLOC_SZ (fd)) ? offset : RIOMALLOC_SZ (fd);