crash-stack: Check return of EVP_*() calls 04/297304/5
authorKarol Lewandowski <k.lewandowsk@samsung.com>
Wed, 16 Aug 2023 12:39:46 +0000 (14:39 +0200)
committerKarol Lewandowski <k.lewandowsk@samsung.com>
Thu, 17 Aug 2023 09:22:50 +0000 (11:22 +0200)
Change-Id: Idb2f43986986fd11f696962d17599304dc10c417

packaging/crash-worker.spec
src/crash-stack/crash-stack.c

index a3376c7..6e32831 100644 (file)
@@ -16,7 +16,7 @@
 
 Name:           crash-worker
 Summary:        Coredump handler and report generator for Tizen
-Version:        8.0.1
+Version:        8.0.2
 Release:        1
 Group:          Framework/system
 License:        MIT
index 64b9505..9a7f518 100644 (file)
@@ -220,9 +220,15 @@ static void __print_hash(Callstack *callstack, json_object *jobj, struct addr_no
        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
@@ -245,12 +251,17 @@ static void __print_hash(Callstack *callstack, json_object *jobj, struct addr_no
                        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];
 
@@ -258,15 +269,18 @@ static void __print_hash(Callstack *callstack, json_object *jobj, struct addr_no
                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);
 }