diff options
author | sinanmohd <sinan@sinanmohd.com> | 2024-04-11 10:16:31 +0530 |
---|---|---|
committer | sinanmohd <sinan@sinanmohd.com> | 2024-04-11 10:20:26 +0530 |
commit | e500683defefac1370e86cbf52552f404a0eae24 (patch) | |
tree | 9b611cb7b8d595400c758765965db3d34b3f59dc | |
parent | f742dcd82123f180d04b5282402c3e06d3e8a3d1 (diff) |
libnpass/gpg: make key a NULL-terminated array
GPGME_DEBUG to the rescue. this bug caused pass gen and add to fail when
building with gcc and optimization set to anything other than 0.
https://www.gnupg.org/documentation/manuals/gpgme/Encrypting-a-Plaintext.html
> Function: gpgme_error_t gpgme_op_encrypt ...
> ...
> recp must be a NULL-terminated array of keys
-rw-r--r-- | src/libnpass/gpg.c | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/src/libnpass/gpg.c b/src/libnpass/gpg.c index a729028..dedc149 100644 --- a/src/libnpass/gpg.c +++ b/src/libnpass/gpg.c @@ -18,7 +18,7 @@ } while (0) static gpgme_ctx_t ctx = NULL; -static gpgme_key_t key = NULL; +static gpgme_key_t key[2] = {0}; static int gpg_init(void); static void gpg_cleanup(void); @@ -45,9 +45,9 @@ static int gpg_init(void) static void gpg_cleanup(void) { if (ctx) - gpgme_key_release(key); - if (key) gpgme_release(ctx); + if (*key) + gpgme_key_release(*key); } int gpg_key_validate(const char *fpr) @@ -59,7 +59,7 @@ int gpg_key_validate(const char *fpr) if (r) return r; - err = gpgme_get_key(ctx, fpr, &key, 1); + err = gpgme_get_key(ctx, fpr, key, 1); gpg_err_ret(err); gpg_cleanup(); @@ -108,14 +108,14 @@ int gpg_encrypt(FILE *stream, const char *fpr, const char *pass, size_t n) if (r) return r; - err = gpgme_get_key(ctx, fpr, &key, 1); + err = gpgme_get_key(ctx, fpr, key, 1); gpg_err_ret(err); err = gpgme_data_new_from_mem(&in, pass, n, 0); gpg_err_ret(err); err = gpgme_data_new(&out); gpg_err_ret(err); - err = gpgme_op_encrypt(ctx, &key, GPGME_ENCRYPT_ALWAYS_TRUST, in, out); + err = gpgme_op_encrypt(ctx, key, GPGME_ENCRYPT_ALWAYS_TRUST, in, out); gpg_err_ret(err); r = gpgme_data_seek(out, 0, SEEK_SET); |