mirror of
https://github.com/radareorg/radare2.git
synced 2024-12-04 03:11:28 +00:00
* Fix segfault in malloc:// IO backend
* Catch error in core to avoid future issues
This commit is contained in:
parent
f0cca138db
commit
ca8a2a9280
@ -75,12 +75,12 @@ R_API int r_core_seek(RCore *core, ut64 addr, int rb) {
|
|||||||
core->offset = old;
|
core->offset = old;
|
||||||
eprintf ("Cannot read block at 0x%08"PFMT64x"\n", addr);
|
eprintf ("Cannot read block at 0x%08"PFMT64x"\n", addr);
|
||||||
} else
|
} else
|
||||||
if (ret != core->blocksize) {
|
if (ret <= core->blocksize) {
|
||||||
if (core->ffio) {
|
if (core->ffio) {
|
||||||
memset (core->block, 0xff, core->blocksize);
|
memset (core->block, 0xff, core->blocksize);
|
||||||
core->offset = addr;
|
core->offset = addr;
|
||||||
} else memset (core->block+ret, 0xff, core->blocksize-ret);
|
} else memset (core->block+ret, 0xff, core->blocksize-ret);
|
||||||
}
|
} else eprintf ("Error: IO backend error\n");
|
||||||
}
|
}
|
||||||
return (ret==-1)?R_FALSE:R_TRUE;
|
return (ret==-1)?R_FALSE:R_TRUE;
|
||||||
}
|
}
|
||||||
|
@ -13,18 +13,16 @@ static unsigned int malloc_bufsz = 0;
|
|||||||
// XXX shitty vars -- should be state
|
// XXX shitty vars -- should be state
|
||||||
static ut64 malloc_seek = 0;
|
static ut64 malloc_seek = 0;
|
||||||
|
|
||||||
static int __write(struct r_io_t *io, int fd, const ut8 *buf, int count)
|
static int __write(struct r_io_t *io, int fd, const ut8 *buf, int count) {
|
||||||
{
|
|
||||||
if (malloc_buf == NULL)
|
if (malloc_buf == NULL)
|
||||||
return 0;
|
return 0;
|
||||||
return (ssize_t)memcpy(malloc_buf+io->off, buf, count);
|
memcpy (malloc_buf+io->off, buf, count);
|
||||||
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int __read(struct r_io_t *io, int fd, ut8 *buf, int count)
|
static int __read(struct r_io_t *io, int fd, ut8 *buf, int count) {
|
||||||
{
|
|
||||||
if (malloc_buf == NULL)
|
if (malloc_buf == NULL)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (malloc_seek + count > malloc_bufsz) {
|
if (malloc_seek + count > malloc_bufsz) {
|
||||||
//config.seek = 0; // ugly hack
|
//config.seek = 0; // ugly hack
|
||||||
//count = config.seek+count-config.size;
|
//count = config.seek+count-config.size;
|
||||||
@ -32,12 +30,11 @@ static int __read(struct r_io_t *io, int fd, ut8 *buf, int count)
|
|||||||
}
|
}
|
||||||
if (malloc_seek + count > malloc_bufsz)
|
if (malloc_seek + count > malloc_bufsz)
|
||||||
malloc_seek = malloc_bufsz;
|
malloc_seek = malloc_bufsz;
|
||||||
|
memcpy (buf, malloc_buf+malloc_seek, count);
|
||||||
return (ssize_t)memcpy(buf, malloc_buf+malloc_seek, count);
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int __close(struct r_io_t *io, int fd)
|
static int __close(struct r_io_t *io, int fd) {
|
||||||
{
|
|
||||||
if (malloc_buf == NULL)
|
if (malloc_buf == NULL)
|
||||||
return -1;
|
return -1;
|
||||||
free(malloc_buf);
|
free(malloc_buf);
|
||||||
@ -46,9 +43,8 @@ static int __close(struct r_io_t *io, int fd)
|
|||||||
}
|
}
|
||||||
|
|
||||||
extern ut64 posix_lseek(int fildes, ut64 offset, int whence);
|
extern ut64 posix_lseek(int fildes, ut64 offset, int whence);
|
||||||
static ut64 __lseek(struct r_io_t *io, int fildes, ut64 offset, int whence)
|
static ut64 __lseek(struct r_io_t *io, int fildes, ut64 offset, int whence) {
|
||||||
{
|
switch (whence) {
|
||||||
switch(whence) {
|
|
||||||
case SEEK_SET:
|
case SEEK_SET:
|
||||||
malloc_seek = offset;
|
malloc_seek = offset;
|
||||||
break;
|
break;
|
||||||
@ -62,13 +58,11 @@ static ut64 __lseek(struct r_io_t *io, int fildes, ut64 offset, int whence)
|
|||||||
return malloc_seek;
|
return malloc_seek;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int __plugin_open(struct r_io_t *io, const char *pathname)
|
static int __plugin_open(struct r_io_t *io, const char *pathname) {
|
||||||
{
|
|
||||||
return (!memcmp(pathname, "malloc://", 9));
|
return (!memcmp(pathname, "malloc://", 9));
|
||||||
}
|
}
|
||||||
|
|
||||||
static int __open(struct r_io_t *io, const char *pathname, int flags, int mode)
|
static int __open(struct r_io_t *io, const char *pathname, int flags, int mode) {
|
||||||
{
|
|
||||||
char buf[1024];
|
char buf[1024];
|
||||||
char *ptr = buf;
|
char *ptr = buf;
|
||||||
|
|
||||||
@ -91,13 +85,11 @@ static int __open(struct r_io_t *io, const char *pathname, int flags, int mode)
|
|||||||
return malloc_fd;
|
return malloc_fd;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int __init(struct r_io_t *io)
|
static int __init(struct r_io_t *io) {
|
||||||
{
|
|
||||||
return R_TRUE;
|
return R_TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int __system(struct r_io_t *io, int fd, const char *cmd)
|
static int __system(struct r_io_t *io, int fd, const char *cmd) {
|
||||||
{
|
|
||||||
/* */
|
/* */
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user