More null pointer dereference fixes
authorColin Leroy <colin@colino.net>
Fri, 13 Nov 2015 09:49:25 +0000 (10:49 +0100)
committerColin Leroy <colin@colino.net>
Fri, 13 Nov 2015 09:49:25 +0000 (10:49 +0100)
src/plugins/archive/libarchive_archive.c
src/plugins/managesieve/managesieve.c
src/plugins/pdf_viewer/poppler_viewer.c
src/plugins/pgpcore/select-keys.c
src/plugins/pgpcore/sgpgme.c
src/plugins/python/python-hooks.c
src/plugins/rssyl/libfeed/parser_atom10.c

index f0ae67b..ddedbda 100644 (file)
@@ -157,10 +157,10 @@ static GDate* iso2GDate(const gchar* date) {
 
     gdate = g_date_new();
     parts = g_strsplit(date, "-", 3);
-    if (! is_iso_string(parts))
-        return NULL;
     if (!parts)
         return NULL;
+    if (! is_iso_string(parts))
+        return NULL;
     for (i = 0; i < 3; i++) {
         int t = atoi(parts[i]);
         switch (i) {
index f0159e7..9739a0e 100644 (file)
@@ -620,7 +620,7 @@ static void parse_response(gchar *msg, SieveResult *result)
        }
 
        /* response code */
-       if (msg[0] == '(' && (end = strchr(msg, ')'))) {
+       if (msg && msg[0] == '(' && (end = strchr(msg, ')'))) {
                msg++;
                *end++ = '\0';
                result->code =
@@ -635,7 +635,7 @@ static void parse_response(gchar *msg, SieveResult *result)
        }
 
        /* s2c octets */
-       if (msg[0] == '{' && (end = strchr(msg, '}'))) {
+       if (msg && msg[0] == '{' && (end = strchr(msg, '}'))) {
                msg++;
                *end++ = '\0';
                if (msg[0] == '0' && msg+1 == end) {
@@ -654,7 +654,7 @@ static void parse_response(gchar *msg, SieveResult *result)
        }
 
        /* text */
-       if (*msg) {
+       if (msg && *msg) {
                unquote_inplace(msg);
                result->description = msg;
        } else {
index eee0cb6..a0cecaf 100644 (file)
@@ -1486,7 +1486,8 @@ static void pdf_viewer_show_mimepart(MimeViewer *_viewer, const gchar *infile,
 
        pdf_viewer_update((MimeViewer *)viewer, TRUE, 1);
 
-       messageview->updating = FALSE;
+       if (messageview)
+               messageview->updating = FALSE;
 }
 
 static void pdf_viewer_clear(MimeViewer *_viewer)
index 6559220..9abac75 100644 (file)
@@ -275,7 +275,7 @@ fill_clist (struct select_keys_s *sk, const char *pattern, gpgme_protocol_t prot
     clist = sk->clist;
     cm_return_val_if_fail (clist, NULL);
 
-    debug_print ("select_keys:fill_clist:  pattern '%s' proto %d\n", pattern, proto);
+    debug_print ("select_keys:fill_clist:  pattern '%s' proto %d\n", pattern != NULL ? pattern : "NULL", proto);
 
     /*gtk_cmclist_freeze (select_keys.clist);*/
     err = gpgme_new (&ctx);
@@ -291,7 +291,7 @@ fill_clist (struct select_keys_s *sk, const char *pattern, gpgme_protocol_t prot
     err = gpgme_op_keylist_start (ctx, pattern, 0);
     if (err) {
         debug_print ("** gpgme_op_keylist_start(%s) failed: %s",
-                     pattern, gpgme_strerror (err));
+                     pattern != NULL ? pattern : "NULL", gpgme_strerror (err));
         sk->select_ctx = NULL;
         gpgme_release(ctx);
         return NULL;
@@ -312,7 +312,7 @@ fill_clist (struct select_keys_s *sk, const char *pattern, gpgme_protocol_t prot
                        continue;
                raw_mail = g_strdup(uid->email);
                extract_address(raw_mail);
-               if (!strcasecmp(pattern, raw_mail)) {
+               if (pattern != NULL && !strcasecmp(pattern, raw_mail)) {
                        exact_match = TRUE;
                        last_uid = uid;
                        g_free(raw_mail);
index 6730078..5d0ecac 100644 (file)
@@ -325,7 +325,7 @@ gchar *sgpgme_sigstat_info_full(gpgme_ctx_t ctx, gpgme_verify_result_t status)
                case GPG_ERR_NO_ERROR:
                        g_string_append_printf(siginfo,
                                _("Good signature from uid \"%s\" (Validity: %s)\n"),
-                               uid, get_validity_str(key->uids?key->uids->validity:GPGME_VALIDITY_UNKNOWN));
+                               uid, get_validity_str((key && key->uids) ? key->uids->validity:GPGME_VALIDITY_UNKNOWN));
                        break;
                case GPG_ERR_KEY_EXPIRED:
                        g_string_append_printf(siginfo,
@@ -335,7 +335,7 @@ gchar *sgpgme_sigstat_info_full(gpgme_ctx_t ctx, gpgme_verify_result_t status)
                case GPG_ERR_SIG_EXPIRED:
                        g_string_append_printf(siginfo,
                                _("Expired signature from uid \"%s\" (Validity: %s)\n"),
-                               uid, get_validity_str(key->uids?key->uids->validity:GPGME_VALIDITY_UNKNOWN));
+                               uid, get_validity_str((key && key->uids) ? key->uids->validity:GPGME_VALIDITY_UNKNOWN));
                        break;
                case GPG_ERR_CERT_REVOKED:
                        g_string_append_printf(siginfo,
@@ -352,17 +352,19 @@ gchar *sgpgme_sigstat_info_full(gpgme_ctx_t ctx, gpgme_verify_result_t status)
                }
                if (sig->status != GPG_ERR_BAD_SIGNATURE) {
                        gint j = 1;
-                       key->uids = key->uids ? key->uids->next : NULL;
-                       while (key->uids != NULL) {
-                               g_string_append_printf(siginfo,
-                                       _("                    uid \"%s\" (Validity: %s)\n"),
-                                       key->uids->uid,
-                                       key->uids->revoked==TRUE?_("Revoked"):get_validity_str(key->uids->validity));
-                               j++;
-                               key->uids = key->uids->next;
+                       if (key) {
+                               key->uids = key->uids ? key->uids->next : NULL;
+                               while (key->uids != NULL) {
+                                       g_string_append_printf(siginfo,
+                                               _("                    uid \"%s\" (Validity: %s)\n"),
+                                               key->uids->uid,
+                                               key->uids->revoked==TRUE?_("Revoked"):get_validity_str(key->uids->validity));
+                                       j++;
+                                       key->uids = key->uids->next;
+                               }
                        }
                        g_string_append_printf(siginfo,_("Owner Trust: %s\n"),
-                                              get_owner_trust_str(key->owner_trust));
+                                              key ? get_owner_trust_str(key->owner_trust) : _("No key!"));
                        g_string_append(siginfo,
                                _("Primary key fingerprint:"));
                        const char* primary_fpr = NULL;
index 4cd1cb5..e4e464f 100644 (file)
@@ -275,8 +275,10 @@ parasite_python_run(const char *command,
        if (repr != NULL) {
            char *string = PyString_AsString(repr);
 
-           stdout_logger(string, user_data);
-           stdout_logger("\n", user_data);
+           if (stdout_logger != NULL) {
+               stdout_logger(string, user_data);
+               stdout_logger("\n", user_data);
+           }
         }
 
         Py_XDECREF(repr);
index eda6064..f2afa3f 100644 (file)
@@ -83,12 +83,12 @@ void feed_parser_atom10_start(void *data, const gchar *el, const gchar **attr)
                } else if( !strcmp(el, "link") ) {
                        /* Capture item URL, from the "url" XML attribute. */
                        if (ctx->curitem && ctx->location == FEED_LOC_ATOM10_ENTRY)
-                 ctx->curitem->url = g_strdup(feed_parser_get_attribute_value(attr, "href"));
+                               ctx->curitem->url = g_strdup(feed_parser_get_attribute_value(attr, "href"));
                } else if( !strcmp(el, "source") ) {
                        ctx->location = FEED_LOC_ATOM10_SOURCE;
                } else ctx->location = FEED_LOC_ATOM10_ENTRY;
 
-               if( !strcmp(el, "title") ) {
+               if( !strcmp(el, "title") && ctx->curitem != NULL) {
                        a = feed_parser_get_attribute_value(attr, "type");
                        if( !a || !strcmp(a, "text") )
                                ctx->curitem->title_format = FEED_ITEM_TITLE_TEXT;
@@ -98,7 +98,7 @@ void feed_parser_atom10_start(void *data, const gchar *el, const gchar **attr)
                                ctx->curitem->title_format = FEED_ITEM_TITLE_XHTML;
                        else
                                ctx->curitem->title_format = FEED_ITEM_TITLE_UNKNOWN;
-               } else if (!strcmp(el, "content") ) {
+               } else if (!strcmp(el, "content") && ctx->curitem != NULL) {
                        a = feed_parser_get_attribute_value(attr, "type");
                        if (a && !strcmp(a, "xhtml")) {
                                ctx->curitem->xhtml_content = TRUE;