]> git.notmuchmail.org Git - notmuch/commitdiff
cli: fix use of uninitialized variable in "notmuch reply"
authorJani Nikula <jani@nikula.org>
Thu, 5 Jan 2012 20:25:12 +0000 (22:25 +0200)
committerDavid Bremner <bremner@debian.org>
Mon, 9 Jan 2012 10:44:47 +0000 (06:44 -0400)
notmuch_show_params_t params is only initialized partially in
notmuch_reply_command(). The only field that is used uninitialized is
params.decrypt. It is usually non-zero, making "notmuch reply" on encrypted
messages work by coincidence.

Initialize params properly, and set params.decrypt as needed.

Signed-off-by: Jani Nikula <jani@nikula.org>
notmuch-reply.c

index f8d5f64716e2a47e39a2d6767f4e36eeab980d5a..1f33a8667779b814ca2ef98c720ae42b37c29b98 100644 (file)
@@ -621,11 +621,9 @@ notmuch_reply_command (void *ctx, int argc, char *argv[])
     char *opt, *query_string;
     int i, ret = 0;
     int (*reply_format_func)(void *ctx, notmuch_config_t *config, notmuch_query_t *query, notmuch_show_params_t *params);
     char *opt, *query_string;
     int i, ret = 0;
     int (*reply_format_func)(void *ctx, notmuch_config_t *config, notmuch_query_t *query, notmuch_show_params_t *params);
-    notmuch_show_params_t params;
+    notmuch_show_params_t params = { .part = -1 };
 
     reply_format_func = notmuch_reply_format_default;
 
     reply_format_func = notmuch_reply_format_default;
-    params.part = -1;
-    params.cryptoctx = NULL;
 
     argc--; argv++; /* skip subcommand argument */
 
 
     argc--; argv++; /* skip subcommand argument */
 
@@ -647,10 +645,12 @@ notmuch_reply_command (void *ctx, int argc, char *argv[])
        } else if ((STRNCMP_LITERAL (argv[i], "--decrypt") == 0)) {
            if (params.cryptoctx == NULL) {
                GMimeSession* session = g_object_new(g_mime_session_get_type(), NULL);
        } else if ((STRNCMP_LITERAL (argv[i], "--decrypt") == 0)) {
            if (params.cryptoctx == NULL) {
                GMimeSession* session = g_object_new(g_mime_session_get_type(), NULL);
-               if (NULL == (params.cryptoctx = g_mime_gpg_context_new(session, "gpg")))
+               if (NULL == (params.cryptoctx = g_mime_gpg_context_new(session, "gpg"))) {
                    fprintf (stderr, "Failed to construct gpg context.\n");
                    fprintf (stderr, "Failed to construct gpg context.\n");
-               else
+               } else {
+                   params.decrypt = TRUE;
                    g_mime_gpg_context_set_always_trust((GMimeGpgContext*)params.cryptoctx, FALSE);
                    g_mime_gpg_context_set_always_trust((GMimeGpgContext*)params.cryptoctx, FALSE);
+               }
                g_object_unref (session);
                session = NULL;
            }
                g_object_unref (session);
                session = NULL;
            }