[seahorse/pgp/fix-add-subkey-warnings] pgp: Handle GDateTime with care when adding subkeys




commit 8ed541755dfeb610b993cc001d592e3cb09811a0
Author: Niels De Graef <nielsdegraef gmail com>
Date:   Tue Jul 27 23:56:20 2021 +0200

    pgp: Handle GDateTime with care when adding subkeys
    
    * Do a proper NULL-check before doing anything with it
    * `seahorse_date_picker_get_datetime()` returns an unowned reference,
      so don't use `g_autoptr()` on the result

 pgp/seahorse-gpgme-key-op.c       | 9 +++++++--
 pgp/seahorse-pgp-key-properties.c | 2 +-
 2 files changed, 8 insertions(+), 3 deletions(-)
---
diff --git a/pgp/seahorse-gpgme-key-op.c b/pgp/seahorse-gpgme-key-op.c
index 76ff6b0d..84f7e036 100644
--- a/pgp/seahorse-gpgme-key-op.c
+++ b/pgp/seahorse-gpgme-key-op.c
@@ -1376,6 +1376,7 @@ seahorse_gpgme_key_op_add_subkey_async (SeahorseGpgmeKey    *pkey,
     gpgme_key_t key;
     const char *algo;
     g_autofree char *algo_full = NULL;
+    int64_t expires_ts;
     g_autoptr(GSource) gsource = NULL;
     unsigned int flags = 0;
 
@@ -1403,8 +1404,12 @@ seahorse_gpgme_key_op_add_subkey_async (SeahorseGpgmeKey    *pkey,
     algo_full = g_strdup_printf ("%s%u", algo, length);
 
     /* 0 means "no expire" for us (GPGME picks a default otherwise) */
-    if (expires == 0)
+    if (expires) {
+        expires_ts = g_date_time_to_unix (expires);
+    } else {
+        expires_ts = 0;
         flags |= GPGME_CREATE_NOEXPIRE;
+    }
 
     /* Add usage flags */
     switch (type) {
@@ -1423,7 +1428,7 @@ seahorse_gpgme_key_op_add_subkey_async (SeahorseGpgmeKey    *pkey,
                                             key,
                                             algo_full,
                                             0,
-                                            g_date_time_to_unix (expires),
+                                            expires_ts,
                                             flags);
     }
 
diff --git a/pgp/seahorse-pgp-key-properties.c b/pgp/seahorse-pgp-key-properties.c
index 02551e94..5c4451f8 100644
--- a/pgp/seahorse-pgp-key-properties.c
+++ b/pgp/seahorse-pgp-key-properties.c
@@ -991,7 +991,7 @@ on_subkeys_add (GSimpleAction *action, GVariant *param, gpointer user_data)
     int response;
     SeahorseKeyEncType type;
     guint length;
-    g_autoptr(GDateTime) expires = NULL;
+    GDateTime *expires;
 
     g_return_if_fail (SEAHORSE_GPGME_IS_KEY (self->key));
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]