Fix some null derefs on io.write when no files opened

- Add missing wB in w?
- Make sys/duktape.sh happy for OSX
This commit is contained in:
pancake 2015-03-17 20:27:59 +01:00
parent bd58fe2450
commit 103ab99dc9
3 changed files with 20 additions and 8 deletions

View File

@ -130,7 +130,9 @@ static void cmd_write_value (RCore *core, const char *input) {
case '8': type = 8; break;
}
off = r_num_math (core->num, input+2);
r_io_use_desc (core->io, core->file->desc);
if (core->file) {
r_io_use_desc (core->io, core->file->desc);
}
r_io_seek (core->io, core->offset, R_IO_SEEK_SET);
if (type == 0)
type = (off&UT64_32U)? 8: 4;
@ -183,6 +185,7 @@ static int cmd_write(void *data, const char *input) {
"waf"," file","assemble file and write bytes",
"wA"," r 0","alter/modify opcode at current seek (see wA?)",
"wb"," 010203","fill current block with cyclic hexpairs",
"wB","[-]0xVALUE","set or unset bits with given value",
"wc","","list all write changes",
"wc","[ir*?]","write cache undo/commit/reset/list (io.cache)",
"wd"," [off] [n]","duplicate N bytes from offset at current seek (memcpy) (see y?)",

View File

@ -653,16 +653,21 @@ R_API int r_io_write(RIO *io, const ut8 *buf, int len) {
ret = -1;
}
} else {
ret = write (io->desc->fd, buf, len);
if (io->desc) {
ret = write (io->desc->fd, buf, len);
} else ret = -1;
}
if (ret == -1) {
if (io->cached != 2) {
eprintf ("r_io_write: cannot write on fd %d\n", io->desc->fd);
eprintf ("r_io_write: cannot write on fd %d\n",
io->desc? io->desc->fd: -1);
r_io_cache_invalidate (io, io->off, io->off+1);
}
} else {
r_io_map_write_update (io, io->desc->fd, io->off, ret);
io->off += ret;
if (io->desc) {
r_io_map_write_update (io, io->desc->fd, io->off, ret);
io->off += ret;
}
}
free (data);
return ret;

View File

@ -5,6 +5,10 @@ cd `dirname $PWD/$0`
./clone-r2-bindings.sh
cd ..
# workaround for osx
if [ -f /usr/lib/pkgconfig/r_util.pc ]; then
export PKG_CONFIG_PATH=/usr/lib/pkgconfig
fi
[ -z "${PREFIX}" ] && PREFIX=/usr
ID=`id -u`
[ -n "${NOSUDO}" ] && SUDO=
@ -12,11 +16,11 @@ ID=`id -u`
export DESTDIR
cd radare2-bindings
./configure --prefix=/usr --enable=duktape
./configure --prefix=/usr --enable=duktape || exit 1
cd libr/lang/p
make clean
make
rm ~/.config/radare2/plugins/lang_duktape.*
make || exit 1
rm -f ~/.config/radare2/plugins/lang_duktape.*
if [ "$1" != '--no-install' ]; then
if [ "$ID" = 0 ]; then
${SUDO} make install DESTDIR=${DESTDIR}