assert(callstack);
assert(maps);
+ char *hash_str_full = NULL;
+
EVP_MD_CTX *ctx = EVP_MD_CTX_create();
const EVP_MD *md = EVP_sha256();
- EVP_DigestInit_ex(ctx, md, NULL);
+
+ if (!EVP_DigestInit_ex(ctx, md, NULL)) {
+ _E("Unable to initialize hashing module");
+ goto out;
+ }
for (size_t i = 0; i < callstack->elems; i++) {
// We won't be able to substract the start address so we skip
continue;
}
uintptr_t addr = callstack->proc[i].addr + callstack->proc[i].module_offset - m_node->startaddr;
- EVP_DigestUpdate(ctx, &addr, sizeof(addr));
+ if (!EVP_DigestUpdate(ctx, &addr, sizeof(addr))) {
+ _E("Unable to compute hash");
+ goto out;
+ }
}
unsigned char hash[SHA256_DIGEST_LENGTH];
- EVP_DigestFinal_ex(ctx, hash, 0);
- EVP_MD_CTX_destroy(ctx);
+ if (!EVP_DigestFinal_ex(ctx, hash, 0)) {
+ _E("Unable to compute hash");
+ goto out;
+ }
char hash_str[SHA256_DIGEST_LENGTH*2+1];
snprintf(&hash_str[i*2], 2 + 1, "%02x", hash[i]);
static const char *hash_desc = "STACK_SHA256";
- char *hash_str_full;
if (asprintf(&hash_str_full, "%s=%s", hash_desc, hash_str) == -1 || hash_str_full == NULL) {
_E("Hash saving error: %m");
- return;
+ goto out;
}
_I("%s", hash_str_full);
json_object_object_add(jobj, K_NATIVE_HASH, json_object_new_string(hash_str));
fprintf(stdout, "%s\n", hash_str_full);
+
+out:
+ if (ctx)
+ EVP_MD_CTX_destroy(ctx);
free(hash_str_full);
}