Fix some memleaks, warnings and null derefs pointed out by clang analyzer

This commit is contained in:
pancake 2017-07-10 11:20:03 +02:00
parent 931aa1e285
commit 1b6cfb68bd
9 changed files with 39 additions and 31 deletions

View File

@ -406,6 +406,10 @@ static ut8 *slurp(RCore **c, const char *file, int *sz) {
if (!*c) {
*c = opencore (NULL);
}
if (!*c) {
eprintf ("opencore failed\n");
return NULL;
}
io = (*c)->io;
d = r_io_open (io, file, 0, 0);
if (!d) {

View File

@ -622,6 +622,9 @@ int main(int argc, char **argv) {
algobit = r_hash_name_to_bits (algo);
if (algobit == 0) {
eprintf ("Invalid algorithm. See -E, -D maybe?\n");
if (str != hashstr) {
free (str);
}
return 1;
}
for (i = 1; i < R_HASH_ALL; i <<= 1) {
@ -636,7 +639,9 @@ int main(int argc, char **argv) {
}
}
if (_s) {
free (str);
if (str != hashstr) {
free (str);
}
free (s.buf);
}
return ret;

View File

@ -4,6 +4,7 @@
typedef void (*RAnalEsilPin)(RAnal *a);
#if 0
// TODO: those hardcoded functions should go
/* default pins from libc */
static void pin_strlen(RAnal *a) {
@ -21,6 +22,7 @@ static void pin_write(RAnal *a) {
// set a0 to the result of write;
eprintf ("esilpin: write\n");
}
#endif
/* pin api */

View File

@ -426,6 +426,9 @@ static bool parseOperands(char* str, ArmOp *op) {
char *x;
int imm_count = 0;
int mem_opt = 0;
if (!token) {
return false;
}
while (token[0] != '\0') {
op->operands[operand].type = ARM_NOTYPE;

View File

@ -10,6 +10,9 @@
#include <dalvik/opcode.h>
static int dalvik_disassemble (RAsm *a, RAsmOp *op, const ut8 *buf, int len) {
if (!a || !op || !buf || len < 1) {
return -1;
}
int vA, vB, vC, payload = 0, i = (int) buf? buf[0]: 0;
int size = dalvik_opcodes[i].len;
char str[1024], *strasm;

View File

@ -244,13 +244,15 @@ R_API char *r_bin_demangle_objc(RBinFile *binfile, const char *sym) {
args = strstr (clas, "__");
if (!args) {
free (clas);
free (name);
if (name != clas) {
free (name);
}
return NULL;
}
*args = 0;
free (name);
name = strdup (args + 2);
if (!name){
free (args);
if (!name) {
free (clas);
return NULL;
}
@ -261,8 +263,11 @@ R_API char *r_bin_demangle_objc(RBinFile *binfile, const char *sym) {
nargs++;
}
}
if (sym[1] == 'i') type = "public";
else if (sym[1] == 'c') type = "static";
if (sym[1] == 'i') {
type = "public";
} else if (sym[1] == 'c') {
type = "static";
}
}
if (type) {
if (!strcmp (type, "field")) {

View File

@ -18,6 +18,7 @@
#if _MSC_VER
#include <process.h>
#endif
R_API bool r_file_truncate (const char *filename, ut64 newsize) {
int fd;
if (r_file_is_directory (filename)) {
@ -183,15 +184,10 @@ R_API char *r_file_abspath(const char *file) {
ret = strdup (file);
}
#if __UNIX__
{
char *resolved_path = calloc(4096, 1); // TODO: use MAXPATH
char *abspath = realpath (ret, resolved_path);
if (abspath) {
free (ret);
ret = abspath;
} else {
free (resolved_path);
}
char *abspath = realpath (ret, NULL);
if (abspath) {
free (ret);
ret = abspath;
}
#endif
return ret;

View File

@ -71,14 +71,10 @@ RASN1String *r_asn1_stringify_string (const ut8 *buffer, ut32 length) {
}
RASN1String *r_asn1_stringify_utctime (const ut8 *buffer, ut32 length) {
char* str;
char str[24];
if (!buffer || length != 13 || buffer[12] != 'Z') {
return NULL;
}
str = (char*) malloc (24);
if (!buffer || !length) {
return NULL;
}
str[0] = buffer[4];
str[1] = buffer[5];
@ -105,19 +101,14 @@ RASN1String *r_asn1_stringify_utctime (const ut8 *buffer, ut32 length) {
str[22] = 'T';
str[23] = '\0';
return r_asn1_create_string (str, true, 24);
return r_asn1_create_string (str, true, sizeof (str));
}
RASN1String *r_asn1_stringify_time (const ut8 *buffer, ut32 length) {
char* str;
char str[24];
if (!buffer || length != 15 || buffer[14] != 'Z') {
return NULL;
}
str = (char*) malloc (24);
if (!buffer || !length) {
return NULL;
}
str[0] = buffer[6];
str[1] = buffer[7];
@ -144,7 +135,7 @@ RASN1String *r_asn1_stringify_time (const ut8 *buffer, ut32 length) {
str[22] = 'T';
str[23] = '\0';
return r_asn1_create_string (str, true, 24);
return r_asn1_create_string (str, true, sizeof (str));
}
RASN1String *r_asn1_stringify_bits (const ut8 *buffer, ut32 length) {

View File

@ -1953,13 +1953,12 @@ ST_FUNC void unary(void)
if (s->v == tok)
break;
}
if (!s)
if (!s) {
tcc_error("field not found: %s", get_tok_str(tok & ~SYM_FIELD, NULL));
}
/* add field offset to pointer */
vtop->type = char_pointer_type; /* change type to 'char *' */
if (s) {
vpushi(s->c);
}
/* change type to field type, and set to lvalue */
vtop->type = s->type;
vtop->type.t |= qualifiers;