Skip to content

Commit

Permalink
Fix null derefs
Browse files Browse the repository at this point in the history
  • Loading branch information
radare committed Jan 24, 2019
1 parent 3cff12a commit 5466457
Showing 1 changed file with 21 additions and 15 deletions.
36 changes: 21 additions & 15 deletions libr/bin/bfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -869,23 +869,29 @@ R_API int r_bin_file_hash(RBin *bin, ut64 limit, const char *file) {
eprintf ("Cannot compute hash\n");
return -1;
}
// XXX should use io api not raw file slurping
buf = r_file_slurp (file, &buf_len);
ctx = r_hash_new (false, R_HASH_MD5 | R_HASH_SHA1);
if (!buf) {
return false;
}
if (buf) {
ctx = r_hash_new (false, R_HASH_MD5 | R_HASH_SHA1);
#define BLK_SIZE_OFF 1024
for (i = 0; i < buf_len; i += BLK_SIZE_OFF) {
(void)r_hash_do_md5 (ctx, &buf[i], R_MIN (buf_len-i, BLK_SIZE_OFF));
(void)r_hash_do_sha1 (ctx, &buf[i], R_MIN (buf_len-i, BLK_SIZE_OFF));
}
r_hash_do_end (ctx, R_HASH_MD5);
p = hash;
r_hex_bin2str (ctx->digest, R_HASH_SIZE_MD5, p);
o->info->hashes = r_strbuf_new ("");
r_strbuf_appendf (o->info->hashes, "md5 %s", hash);
r_hash_do_end (ctx, R_HASH_SHA1);
p = hash;
r_hex_bin2str (ctx->digest, R_HASH_SIZE_SHA1, p);
r_strbuf_appendf (o->info->hashes, "\nsha1 %s", hash);
r_hash_free (ctx);
for (i = 0; i < buf_len; i += BLK_SIZE_OFF) {
(void)r_hash_do_md5 (ctx, &buf[i], R_MIN (buf_len-i, BLK_SIZE_OFF));
(void)r_hash_do_sha1 (ctx, &buf[i], R_MIN (buf_len-i, BLK_SIZE_OFF));
}
r_hash_do_end (ctx, R_HASH_MD5);
p = hash;
r_hex_bin2str (ctx->digest, R_HASH_SIZE_MD5, p);
o->info->hashes = r_strbuf_new ("");
r_strbuf_appendf (o->info->hashes, "md5 %s", hash);
r_hash_do_end (ctx, R_HASH_SHA1);
p = hash;
r_hex_bin2str (ctx->digest, R_HASH_SIZE_SHA1, p);
r_strbuf_appendf (o->info->hashes, "\nsha1 %s", hash);
r_hash_free (ctx);
}
free (buf);
return true;
}

0 comments on commit 5466457

Please sign in to comment.