summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--fuzzy.c37
1 files changed, 20 insertions, 17 deletions
diff --git a/fuzzy.c b/fuzzy.c
index 71dedf2..d359b30 100644
--- a/fuzzy.c
+++ b/fuzzy.c
@@ -228,7 +228,7 @@ static int ssdeep_engine(struct ssdeep_context *self,
return 0;
}
-static void ssdeep_digest(const struct ssdeep_context *self,
+static int ssdeep_digest(const struct ssdeep_context *self,
/*@out@*/ char *result) {
unsigned int bs = self->start_blocksize;
uint32_t h = roll_sum(&self->roll);
@@ -256,9 +256,8 @@ static void ssdeep_digest(const struct ssdeep_context *self,
assert(!(bs > MIN_BLOCKSIZE && bh->dlen < SPAMSUM_LENGTH / 2));
i = snprintf(result, (size_t)remain, "%u:", bs);
- /* In theory snprintf can fail. It is unclear how though, so we assume
- * that it doesn't for simplicity. */
- assert(i > 0);
+ if(i <= 0)
+ return -1;
assert(i < remain);
remain -= i;
result += i;
@@ -296,6 +295,7 @@ static void ssdeep_digest(const struct ssdeep_context *self,
--remain;
}
*result = '\0';
+ return 0;
}
static void ssdeep_free(/*@only@*/ struct ssdeep_context *self) {
@@ -312,21 +312,24 @@ static void ssdeep_free(/*@only@*/ struct ssdeep_context *self) {
int fuzzy_hash_buf(const unsigned char *buf, uint32_t buf_len,
/*@out@*/ char *result) {
struct ssdeep_context *ctx;
+ int ret = -1;
if(NULL == (ctx = ssdeep_new()))
return -1;
- if(ssdeep_engine(ctx, buf, buf_len) < 0) {
- ssdeep_free(ctx);
- return -1;
- }
- ssdeep_digest(ctx, result);
+ if(ssdeep_engine(ctx, buf, buf_len) < 0)
+ goto out;
+ if(ssdeep_digest(ctx, result) < 0)
+ goto out;
+ ret = 0;
+out:
ssdeep_free(ctx);
- return 0;
+ return ret;
}
int fuzzy_hash_stream(FILE *handle, /*@out@*/ char *result) {
struct ssdeep_context *ctx;
unsigned char buffer[4096];
size_t n;
+ int ret = -1;
if(NULL == (ctx = ssdeep_new()))
return -1;
for(;;) {
@@ -334,16 +337,16 @@ int fuzzy_hash_stream(FILE *handle, /*@out@*/ char *result) {
if(0 == n)
break;
if(ssdeep_engine(ctx, buffer, n) < 0)
- goto errout;
+ goto out;
}
if(ferror(handle) != 0)
- goto errout;
- ssdeep_digest(ctx, result);
- ssdeep_free(ctx);
- return 0;
-errout:
+ goto out;
+ if(ssdeep_digest(ctx, result) < 0)
+ goto out;
+ ret = 0;
+out:
ssdeep_free(ctx);
- return -1;
+ return ret;
}
#ifdef S_SPLINT_S