about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorJohn Hernandez <129467592+H3rnand3zzz@users.noreply.github.com>2023-04-13 15:26:19 +0200
committerJohn Hernandez <129467592+H3rnand3zzz@users.noreply.github.com>2023-04-13 17:17:25 +0200
commit899b26b3bce7bc7575be79df0cb9462c9e17623a (patch)
tree22da9767f0121cbdfb49e138b2cefa3d5f5f391b
parent5e8f1f9c853eff2fe49cc7f1dadb285b3c337c18 (diff)
downloadprofani-tty-899b26b3bce7bc7575be79df0cb9462c9e17623a.tar.gz
Cleanup p_ox_gpg_decrypt
In OX implementation gpgme's buffer remains untouched, thus not leading to the crash.

But code can be shorter and more concise.
-rw-r--r--src/pgp/ox.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/src/pgp/ox.c b/src/pgp/ox.c
index 71fa6c8c..4d42a2a7 100644
--- a/src/pgp/ox.c
+++ b/src/pgp/ox.c
@@ -419,10 +419,12 @@ p_ox_gpg_decrypt(char* base64)
 
     size_t len;
     char* plain_str = gpgme_data_release_and_get_mem(plain, &len);
-    char* result = malloc(len + 1);
-    memcpy(result, plain_str, len);
-    result[len] = '\0';
-    gpgme_free(plain_str);
+    char* result = NULL;
+    if (plain_str) {
+        result = strndup(plain_str, len);
+        gpgme_free(plain_str);
+    }
+
     return result;
 }