From 56dd308d7457bac5c0a0707caaaac3ad64e39925 Mon Sep 17 00:00:00 2001 From: GustavoLCR Date: Fri, 11 Jan 2019 03:20:14 -0300 Subject: [PATCH] Fix segfault and add warning --- libr/bin/bin.c | 4 ++++ libr/util/buf.c | 5 ++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/libr/bin/bin.c b/libr/bin/bin.c index 4ae5744c77..01936f575d 100644 --- a/libr/bin/bin.c +++ b/libr/bin/bin.c @@ -1232,6 +1232,10 @@ R_API RBuffer *r_bin_package(RBin *bin, const char *type, const char *file, RLis ut32 num; ut8 *num8 = (ut8*)# RBuffer *buf = r_buf_new_file (file, true); + if (!buf) { + eprintf ("Cannot open file %s - Permission Denied.\n", file); + return NULL; + } r_buf_write_at (buf, 0, (const ut8*)"\xca\xfe\xba\xbe", 4); int count = r_list_length (files); diff --git a/libr/util/buf.c b/libr/util/buf.c index 6df6212ea7..10ea6afcda 100644 --- a/libr/util/buf.c +++ b/libr/util/buf.c @@ -786,10 +786,9 @@ R_API int r_buf_fread_at (RBuffer *b, ut64 addr, ut8 *buf, const char *fmt, int //ret 0 or -1 if failed; ret copied length if success R_API int r_buf_write_at(RBuffer *b, ut64 addr, const ut8 *buf, int len) { + r_return_val_if_fail (b && buf && len > 0, 0); + RIOBind *iob = b->iob; - if (!b || !buf || len < 1) { - return 0; - } ut64 start = addr - b->base + b->offset; ut64 effective_size = r_buf_size (b); int real_len = len;