about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorMichael Vetter <jubalh@iodoru.org>2023-04-14 13:14:01 +0200
committerGitHub <noreply@github.com>2023-04-14 13:14:01 +0200
commita99a4fad3ecb1d7641f4b8f971838c7be1c16074 (patch)
tree19afcfd1024e8251563bd86ca3dad986daa1bcca
parentebec68821fa816ca181892919bd878e69d35810d (diff)
parent899b26b3bce7bc7575be79df0cb9462c9e17623a (diff)
downloadprofani-tty-a99a4fad3ecb1d7641f4b8f971838c7be1c16074.tar.gz
Merge pull request #1823 from H3rnand3zzz/fix/msg-crash
Fix memory corruption crash
-rw-r--r--src/pgp/gpg.c5
-rw-r--r--src/pgp/ox.c10
2 files changed, 8 insertions, 7 deletions
diff --git a/src/pgp/gpg.c b/src/pgp/gpg.c
index 8762660d..3ef69c1d 100644
--- a/src/pgp/gpg.c
+++ b/src/pgp/gpg.c
@@ -721,10 +721,9 @@ p_gpg_decrypt(const char* const cipher)
     char* plain_str = gpgme_data_release_and_get_mem(plain_data, &len);
     char* result = NULL;
     if (plain_str) {
-        plain_str[len] = 0;
-        result = g_strdup(plain_str);
+        result = strndup(plain_str, len);
+        gpgme_free(plain_str);
     }
-    gpgme_free(plain_str);
 
     if (passphrase_attempt) {
         passphrase = strdup(passphrase_attempt);
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;
 }