mirror of
https://github.com/radareorg/radare2.git
synced 2025-01-19 12:22:43 +00:00
Fix #552 - Segfault with negative rahash2 -i
This commit is contained in:
parent
ec016d8cc5
commit
f48b810989
@ -1,4 +1,4 @@
|
||||
/* radare - LGPL - Copyright 2009-2013 - pancake */
|
||||
/* radare - LGPL - Copyright 2009-2014 - pancake */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
@ -69,7 +69,10 @@ static void do_hash_print(RHash *ctx, int hash, int dlen, int rad) {
|
||||
}
|
||||
|
||||
static int do_hash_internal(RHash *ctx, int hash, const ut8 *buf, int len, int rad, int print) {
|
||||
int dlen = r_hash_calculate (ctx, hash, buf, len);
|
||||
int dlen;
|
||||
if (len<1)
|
||||
return 0;
|
||||
dlen = r_hash_calculate (ctx, hash, buf, len);
|
||||
if (!dlen) return 0;
|
||||
if (!print) return 1;
|
||||
if (hash == R_HASH_ENTROPY) {
|
||||
@ -133,7 +136,7 @@ static int do_hash(const char *file, const char *algo, RIO *io, int bsize, int r
|
||||
r_io_read_at (io, j, buf, bsize);
|
||||
do_hash_internal (ctx,
|
||||
hashbit, buf, ((j+bsize)<fsize)?
|
||||
bsize: (fsize-j), rad, 0);
|
||||
bsize: (bsize>j)?(fsize-j):0, rad, 0);
|
||||
}
|
||||
if (s.buf && !s.prefix) {
|
||||
do_hash_internal (ctx,
|
||||
@ -221,7 +224,12 @@ int main(int argc, char **argv) {
|
||||
while ((c = getopt (argc, argv, "rva:i:S:s:b:nBhf:t:kLq")) != -1) {
|
||||
switch (c) {
|
||||
case 'q': quiet = 1; break;
|
||||
case 'i': iterations = atoi (optarg); break;
|
||||
case 'i': iterations = atoi (optarg);
|
||||
if (iterations<1) {
|
||||
eprintf ("error: -i argument must be positive\n");
|
||||
return 1;
|
||||
}
|
||||
break;
|
||||
case 'S': seed = optarg; break;
|
||||
case 'n': numblocks = 1; break;
|
||||
case 'L': algolist (); return 0;
|
||||
|
@ -13,7 +13,9 @@ static int bitnum(int bit) {
|
||||
|
||||
/* TODO: do it more beautiful with structs and not spaguetis */
|
||||
/* TODO: find a better method name */
|
||||
R_API int r_hash_calculate(RHash *ctx, int algobit, const ut8 *buf, ut32 len) {
|
||||
R_API int r_hash_calculate(RHash *ctx, int algobit, const ut8 *buf, int len) {
|
||||
if (len<0)
|
||||
return 0;
|
||||
if (algobit & R_HASH_MD4) {
|
||||
r_hash_do_md4 (ctx, buf, len);
|
||||
return R_HASH_SIZE_MD4;
|
||||
|
@ -40,7 +40,9 @@ R_API void r_hash_free(RHash *ctx) {
|
||||
free (ctx);
|
||||
}
|
||||
|
||||
R_API ut8 *r_hash_do_md5(RHash *ctx, const ut8 *input, ut32 len) {
|
||||
R_API ut8 *r_hash_do_md5(RHash *ctx, const ut8 *input, int len) {
|
||||
if (len<0)
|
||||
return NULL;
|
||||
if (ctx->rst)
|
||||
MD5Init (&ctx->md5);
|
||||
if (len>0)
|
||||
@ -50,7 +52,9 @@ R_API ut8 *r_hash_do_md5(RHash *ctx, const ut8 *input, ut32 len) {
|
||||
return ctx->digest;
|
||||
}
|
||||
|
||||
R_API ut8 *r_hash_do_sha1(RHash *ctx, const ut8 *input, ut32 len) {
|
||||
R_API ut8 *r_hash_do_sha1(RHash *ctx, const ut8 *input, int len) {
|
||||
if (len<0)
|
||||
return NULL;
|
||||
if (ctx->rst)
|
||||
SHA1_Init (&ctx->sha1);
|
||||
SHA1_Update (&ctx->sha1, input, len);
|
||||
@ -59,12 +63,14 @@ R_API ut8 *r_hash_do_sha1(RHash *ctx, const ut8 *input, ut32 len) {
|
||||
return ctx->digest;
|
||||
}
|
||||
|
||||
R_API ut8 *r_hash_do_md4(RHash *ctx, const ut8 *input, ut32 len) {
|
||||
R_API ut8 *r_hash_do_md4(RHash *ctx, const ut8 *input, int len) {
|
||||
if (len<0) return NULL;
|
||||
mdfour (ctx->digest, input, len);
|
||||
return ctx->digest;
|
||||
}
|
||||
|
||||
R_API ut8 *r_hash_do_sha256(RHash *ctx, const ut8 *input, ut32 len) {
|
||||
R_API ut8 *r_hash_do_sha256(RHash *ctx, const ut8 *input, int len) {
|
||||
if (len<0) return NULL;
|
||||
if (ctx->rst)
|
||||
SHA256_Init (&ctx->sha256);
|
||||
SHA256_Update (&ctx->sha256, input, len);
|
||||
@ -73,7 +79,8 @@ R_API ut8 *r_hash_do_sha256(RHash *ctx, const ut8 *input, ut32 len) {
|
||||
return ctx->digest;
|
||||
}
|
||||
|
||||
R_API ut8 *r_hash_do_sha384(RHash *ctx, const ut8 *input, ut32 len) {
|
||||
R_API ut8 *r_hash_do_sha384(RHash *ctx, const ut8 *input, int len) {
|
||||
if (len<0) return NULL;
|
||||
if (ctx->rst)
|
||||
SHA384_Init (&ctx->sha384);
|
||||
SHA384_Update (&ctx->sha384, input, len);
|
||||
@ -82,7 +89,8 @@ R_API ut8 *r_hash_do_sha384(RHash *ctx, const ut8 *input, ut32 len) {
|
||||
return ctx->digest;
|
||||
}
|
||||
|
||||
R_API ut8 *r_hash_do_sha512(RHash *ctx, const ut8 *input, ut32 len) {
|
||||
R_API ut8 *r_hash_do_sha512(RHash *ctx, const ut8 *input, int len) {
|
||||
if (len<0) return NULL;
|
||||
if (ctx->rst)
|
||||
SHA512_Init (&ctx->sha512);
|
||||
SHA512_Update (&ctx->sha512, input, len);
|
||||
|
@ -95,19 +95,19 @@ R_API RHash *r_hash_new(int rst, int flags);
|
||||
R_API void r_hash_free(RHash *ctx);
|
||||
|
||||
/* methods */
|
||||
R_API ut8 *r_hash_do_md4(RHash *ctx, const ut8 *input, ut32 len);
|
||||
R_API ut8 *r_hash_do_md5(RHash *ctx, const ut8 *input, ut32 len);
|
||||
R_API ut8 *r_hash_do_sha1(RHash *ctx, const ut8 *input, ut32 len);
|
||||
R_API ut8 *r_hash_do_sha256(RHash *ctx, const ut8 *input, ut32 len);
|
||||
R_API ut8 *r_hash_do_sha384(RHash *ctx, const ut8 *input, ut32 len);
|
||||
R_API ut8 *r_hash_do_sha512(RHash *ctx, const ut8 *input, ut32 len);
|
||||
R_API ut8 *r_hash_do_xxhash(RHash *ctx, const ut8 *input, ut32 len);
|
||||
R_API ut8 *r_hash_do_md4(RHash *ctx, const ut8 *input, int len);
|
||||
R_API ut8 *r_hash_do_md5(RHash *ctx, const ut8 *input, int len);
|
||||
R_API ut8 *r_hash_do_sha1(RHash *ctx, const ut8 *input, int len);
|
||||
R_API ut8 *r_hash_do_sha256(RHash *ctx, const ut8 *input, int len);
|
||||
R_API ut8 *r_hash_do_sha384(RHash *ctx, const ut8 *input, int len);
|
||||
R_API ut8 *r_hash_do_sha512(RHash *ctx, const ut8 *input, int len);
|
||||
R_API ut8 *r_hash_do_xxhash(RHash *ctx, const ut8 *input, int len);
|
||||
|
||||
/* static methods */
|
||||
R_API const char *r_hash_name(ut64 bit);
|
||||
R_API ut64 r_hash_name_to_bits(const char *name);
|
||||
R_API int r_hash_size(int bit);
|
||||
R_API int r_hash_calculate(RHash *ctx, int algobit, const ut8 *input, ut32 len);
|
||||
R_API int r_hash_calculate(RHash *ctx, int algobit, const ut8 *input, int len);
|
||||
|
||||
/* checksums */
|
||||
/* XXX : crc16 should use 0 as arg0 by default */
|
||||
|
Loading…
x
Reference in New Issue
Block a user