From f52b631568bf967902a1d40e6ac73d404960abad Mon Sep 17 00:00:00 2001 From: alvarofe Date: Sun, 12 Feb 2017 13:05:47 +0100 Subject: [PATCH] Fix #6715 - NULL dereference --- libr/bin/dbginfo.c | 4 +++- libr/util/buf.c | 9 ++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/libr/bin/dbginfo.c b/libr/bin/dbginfo.c index 53f3669ee8..07f84babe7 100644 --- a/libr/bin/dbginfo.c +++ b/libr/bin/dbginfo.c @@ -24,7 +24,9 @@ R_API char *r_bin_addr2text(RBin *bin, ut64 addr, int origin) { int line; char *out = NULL, *out2 = NULL; char *file_nopath = NULL; - + if (!bin || !bin->cur) { + return NULL; + } { char *key = r_str_newf ("0x%"PFMT64x, addr); char *file_line = sdb_get (bin->cur->sdb_addrinfo, key, 0); diff --git a/libr/util/buf.c b/libr/util/buf.c index 52c2ae26b9..baace3f664 100644 --- a/libr/util/buf.c +++ b/libr/util/buf.c @@ -282,10 +282,13 @@ R_API int r_buf_set_bits(RBuffer *b, int bitoff, int bitsize, ut64 value) { } R_API int r_buf_set_bytes(RBuffer *b, const ut8 *buf, ut64 length) { - if (length <= 0 || !buf) return false; - free (b->buf); - if (!(b->buf = malloc (length))) + if (length <= 0 || !buf) { return false; + } + free (b->buf); + if (!(b->buf = malloc (length))) { + return false; + } memmove (b->buf, buf, length); b->length = length;