More coverities fixed

This commit is contained in:
pancake 2017-04-05 10:59:37 +02:00
parent 07e75df74c
commit 01477c74f0
8 changed files with 43 additions and 36 deletions

View File

@ -1,4 +1,4 @@
/* radare - LGPL - Copyright 2009-2016 - pancake */
/* radare - LGPL - Copyright 2009-2017 - pancake */
#include <stdio.h>
#include <stdlib.h>
@ -161,7 +161,7 @@ static int rafind_open(char *file) {
curfile = file;
r_search_begin (rs);
r_io_seek (io, from, R_IO_SEEK_SET);
(void) r_io_seek (io, from, R_IO_SEEK_SET);
//printf("; %s 0x%08"PFMT64x"-0x%08"PFMT64x"\n", file, from, to);
for (cur = from; !last && cur < to; cur += bsize) {
if ((cur + bsize) > to) {

View File

@ -3906,12 +3906,14 @@ print_insn_coprocessor (bfd_vma pc,
func (stream, "[%s", arm_regnames [(given >> 16) & 0xf]);
#if 0
if (multiplier > 1)
{
value_in_comment = offset * multiplier;
if (NEGATIVE_BIT_SET)
value_in_comment = - value_in_comment;
value_in_comment = -value_in_comment;
}
#endif
if (offset)
{

View File

@ -531,8 +531,9 @@ static int cmd_open(void *data, const char *input) {
ut64 ba = 0L;
ut64 ma = 0L;
char *fn = strdup (input + (isn? 2:1));
if (!*fn) {
if (!fn || !*fn) {
eprintf ("Usage: on [file]\n");
free (fn);
break;
}
ptr = strchr (fn, ' ');

View File

@ -2777,6 +2777,7 @@ reread:
eprintf ("Cannot open '%s'\n", arg);
}
}
free (arg);
} else {
eprintf ("Usage: /f [file] ([offset] ([size]))\n");
}

View File

@ -533,8 +533,9 @@ R_API int r_io_read_at(RIO *io, ut64 addr, ut8 *buf, int len) {
ut64 o = r_io_section_maddr_to_vaddr (io, addr + w);
if (o == UT64_MAX) {
ut64 o = r_io_section_vaddr_to_maddr_try (io, addr + w);
if (o == UT64_MAX)
if (o == UT64_MAX) {
memset (buf + w, io->Oxff, l);
}
}
break;
}
@ -620,11 +621,14 @@ R_API int r_io_extend(RIO *io, ut64 size) {
}
buffer = malloc (tmp_size);
if (!buffer) {
return false;
}
// shift the bytes over by size
r_io_seek (io, curr_off, R_IO_SEEK_SET);
(void) r_io_seek (io, curr_off, R_IO_SEEK_SET);
r_io_read (io, buffer, tmp_size);
// move/write the bytes
r_io_seek (io, curr_off + size, R_IO_SEEK_SET);
(void) r_io_seek (io, curr_off + size, R_IO_SEEK_SET);
r_io_write (io, buffer, tmp_size);
// zero out new bytes
if (cur_size < size) {
@ -632,17 +636,17 @@ R_API int r_io_extend(RIO *io, ut64 size) {
buffer = malloc (size);
}
memset (buffer, 0, size);
r_io_seek (io, curr_off, R_IO_SEEK_SET);
(void) r_io_seek (io, curr_off, R_IO_SEEK_SET);
r_io_write (io, buffer, size);
// reset the cursor
r_io_seek (io, curr_off, R_IO_SEEK_SET);
(void) r_io_seek (io, curr_off, R_IO_SEEK_SET);
free (buffer);
return true;
}
R_API int r_io_extend_at(RIO *io, ut64 addr, ut64 size) {
if (!size) return false;
r_io_seek (io, addr, R_IO_SEEK_SET);
(void) r_io_seek (io, addr, R_IO_SEEK_SET);
return r_io_extend (io, size);
}
@ -1071,6 +1075,9 @@ static ut8 *r_io_desc_read(RIO *io, RIODesc *desc, ut64 *out_sz) {
*out_sz = io->maxalloc;
}
buf = malloc (*out_sz + 1);
if (!buf) {
return NULL;
}
buf[*out_sz] = 0;
if (!buf) {
if (*out_sz > R_IO_MAX_ALLOC) {
@ -1147,24 +1154,16 @@ if (hasperm) {
if (io->debug) {
// TODO check debug maps here
return true;
} else {
if (io_sectonly) {
if (r_list_empty (io->sections)) {
return true;
}
return (r_io_map_exists_for_offset (io, offset) ||
r_io_section_exists_for_vaddr (io, offset, hasperm));
} else {
if (!io_va) {
if (!io_va && r_io_map_exists_for_offset (io, offset)) {
return true;
}
}
return r_io_section_exists_for_vaddr (io, offset, hasperm);
//return (offset < r_io_size (io));
}
}
eprintf ("r_io_is_valid_offset: io->va is %i\n", io->va);
r_sys_backtrace ();
return R_FAIL;
if (io_sectonly) {
if (r_list_empty (io->sections)) {
return true;
}
return (r_io_map_exists_for_offset (io, offset) ||
r_io_section_exists_for_vaddr (io, offset, hasperm));
}
if (!io_va && r_io_map_exists_for_offset (io, offset)) {
return true;
}
return r_io_section_exists_for_vaddr (io, offset, hasperm);
}

View File

@ -314,17 +314,17 @@ R_API ut64 r_io_map_select_current_fd(RIO *io, ut64 off, int fd) {
}
}
if (done == 0) {
r_io_seek (io, -1, R_IO_SEEK_SET);
(void) r_io_seek (io, -1, R_IO_SEEK_SET);
return paddr;
}
if (fd == -1) {
r_io_seek (io, off, R_IO_SEEK_SET);
(void) r_io_seek (io, off, R_IO_SEEK_SET);
return off;
}
if (io->debug) { /* HACK */
r_io_seek (io, off, R_IO_SEEK_SET);
} else {
r_io_seek (io, paddr, R_IO_SEEK_SET);
(void) r_io_seek (io, off, R_IO_SEEK_SET);
} else {
(void) r_io_seek (io, paddr, R_IO_SEEK_SET);
}
return paddr;
}

View File

@ -197,7 +197,7 @@ R_API int r_io_pread (RIO *io, ut64 paddr, ut8 *buf, int len) {
}
return R_FAIL;
}
r_io_seek (io, paddr, R_IO_SEEK_SET);
(void) r_io_seek (io, paddr, R_IO_SEEK_SET);
if (io->buffer_enabled){
#if VIO_DEBUG
read_from = "buffer";
@ -306,7 +306,7 @@ R_API int r_io_pwrite (RIO *io, ut64 paddr, const ut8 *buf, int len)
}
if ((UT64_MAX - len) < paddr) //prevent overflows
len = UT64_MAX - paddr;
r_io_seek (io, paddr, R_IO_SEEK_SET);
(void) r_io_seek (io, paddr, R_IO_SEEK_SET);
if (io->desc && io->desc->plugin && io->desc->plugin->write) {
#if VIO_DEBUG
written_to = io->desc->plugin->name;

View File

@ -1761,6 +1761,10 @@ R_API char* r_print_colorize_opcode(RPrint *print, char *p, const char *reg, con
if (print->flags & R_PRINT_FLAGS_SECSUB) {
RIOSection *s = print->iob.section_vget (print->iob.io, r_num_get (NULL, p + i));
if (s) {
if (strlen (s->name) + j + 1 >= COLORIZE_BUFSIZE) {
eprintf ("stop before overflow\n");
break;
}
strcpy (o + j, s->name);
j += strlen (o + j);
strcpy (o + j, ".");