Fix few (possible) crashes due to missing return code checks (patch
authorwwp <subscript@free.fr>
Thu, 3 Jan 2019 09:36:37 +0000 (10:36 +0100)
committerwwp <subscript@free.fr>
Thu, 3 Jan 2019 09:36:37 +0000 (10:36 +0100)
by Zhouyang, with few modifications).

Fixes bug #3977: Fix crshes when some external APIs fail

src/addr_compl.c
src/mimeview.c
src/plugins/libravatar/libravatar_image.c
src/plugins/spam_report/spam_report.c

index cb842abd9aac1cf7501efe27380139947e4e38e0..e0e93733afa428497e41ecd6f5a4fe5db8b009e8 100644 (file)
@@ -945,6 +945,7 @@ static void completion_window_advance_selection(GtkTreeView *list_view, gboolean
  */
 static void addrcompl_resize_window( CompletionWindow *cw ) {
        GtkRequisition r;
+       GdkGrabStatus status;
        gint x, y, width, height, depth;
 
        /* Get current geometry of window */
@@ -963,7 +964,9 @@ static void addrcompl_resize_window( CompletionWindow *cw ) {
                         GDK_POINTER_MOTION_MASK | GDK_BUTTON_PRESS_MASK |
                         GDK_BUTTON_RELEASE_MASK,
                         NULL, NULL, GDK_CURRENT_TIME);
-       gdk_keyboard_grab(gtk_widget_get_window(cw->window), FALSE, GDK_CURRENT_TIME);
+       status = gdk_keyboard_grab(gtk_widget_get_window(cw->window), FALSE, GDK_CURRENT_TIME);
+       if (status != GDK_GRAB_SUCCESS)
+               g_warning("gdk_keyboard_grab failed with status %d", status);
        gtk_grab_add(cw->window);
 
 }
@@ -1443,6 +1446,7 @@ static void address_completion_create_completion_window( GtkEntry *entry_ )
 {
        gint x, y, height, width, depth;
        GtkWidget *scroll, *list_view;
+       GdkGrabStatus status;
        GtkRequisition r;
        GtkWidget *window;
        GtkWidget *entry = GTK_WIDGET(entry_);
@@ -1503,7 +1507,9 @@ static void address_completion_create_completion_window( GtkEntry *entry_ )
                         GDK_POINTER_MOTION_MASK | GDK_BUTTON_PRESS_MASK |
                         GDK_BUTTON_RELEASE_MASK,
                         NULL, NULL, GDK_CURRENT_TIME);
-       gdk_keyboard_grab(gtk_widget_get_window(window), FALSE, GDK_CURRENT_TIME);
+       status = gdk_keyboard_grab(gtk_widget_get_window(window), FALSE, GDK_CURRENT_TIME);
+       if (status != GDK_GRAB_SUCCESS)
+               g_warning("gdk_keyboard_grab failed with status %d", status);
        gtk_grab_add( window );
 }
 
index daaac32d4fe5242bd6b3e40a754f059f02aac406..b697d52acda25897b1d00a5d0bb6bda2b8ab10a9 100644 (file)
@@ -1275,7 +1275,7 @@ static void mimeview_check_sig_in_thread(MimeView *mimeview)
                        mimeview_check_sig_worker_thread, 
                        mimeview) != 0) {
                /* arh. We'll do it synchronously. */
-               g_warning("can't create thread");
+               g_warning("can't create checked thread");
                g_free(mimeview->check_data);
                mimeview->check_data = NULL;
                return;
@@ -1285,12 +1285,17 @@ static void mimeview_check_sig_in_thread(MimeView *mimeview)
        }
 
        /* create the killer thread */
-       pthread_create(&th2, &detach2, 
+       if (pthread_create(&th2, &detach2, 
                        mimeview_check_sig_cancel_thread, 
-                       mimeview);
-
-       mimeview->check_data->cancel_th = th2;
-       mimeview->check_data->cancel_th_init = TRUE;
+                       mimeview) != 0) {
+               g_warning("can't create killer thread");
+               g_free(mimeview->check_data);
+               mimeview->check_data = NULL;
+               return;
+       } else {
+               mimeview->check_data->cancel_th = th2;
+               mimeview->check_data->cancel_th_init = TRUE;
+       }
 }
 #endif
 
index 9a0338b603ba5e4852708f172051edd8fc6cae98..057569a0f32c71544591267e932190c55c04376f 100644 (file)
@@ -72,6 +72,7 @@ static GdkPixbuf *pixbuf_from_url(const gchar *url, const gchar *md5, const gcha
        GdkPixbuf *image = NULL;
        FILE *file;
        CURL *curl;
+       CURLcode res;
        long filesize;
 
        file = claws_fopen(filename, "wb");
@@ -105,21 +106,26 @@ static GdkPixbuf *pixbuf_from_url(const gchar *url, const gchar *md5, const gcha
        }
        curl_easy_setopt(curl, CURLOPT_FILE, file);
        debug_print("retrieving URL to file: %s -> %s\n", url, filename);
-       curl_easy_perform(curl);
-       filesize = ftell(file);
-       claws_safe_fclose(file);
-       if (filesize < MIN_PNG_SIZE)
-               debug_print("not enough data for an avatar image: %ld bytes\n", filesize);
-       else
-               image = image_pixbuf_from_filename(filename);
-
-       if (!libravatarprefs.cache_icons || filesize == 0) {
-               if (g_unlink(filename) < 0)
-                       g_warning("failed to delete cache file '%s'", filename);
-       }
+       res = curl_easy_perform(curl);
+       if (res != CURLE_OK) {
+               debug_print("curl_easy_perfom failed: %s", curl_easy_strerror(res));
+               claws_safe_fclose(file);
+       } else {
+               filesize = ftell(file);
+               claws_safe_fclose(file);
+               if (filesize < MIN_PNG_SIZE)
+                       debug_print("not enough data for an avatar image: %ld bytes\n", filesize);
+               else
+                       image = image_pixbuf_from_filename(filename);
+
+               if (!libravatarprefs.cache_icons || filesize == 0) {
+                       if (g_unlink(filename) < 0)
+                               g_warning("failed to delete cache file '%s'", filename);
+               }
 
-       if (filesize == 0)
-               missing_add_md5(libravatarmisses, md5);
+               if (filesize == 0)
+                       missing_add_md5(libravatarmisses, md5);
+       }
 
        curl_easy_cleanup(curl);
 
index 21c96ccb894477871bf88e43cc338a62526063b9..50f0c104a76fe7b840111243508a6db828a04daf 100644 (file)
@@ -198,6 +198,7 @@ static void report_spam(gint id, ReportInterface *intf, MsgInfo *msginfo, gchar
        gchar *reqbody = NULL, *tmp = NULL, *auth = NULL, *b64 = NULL, *geturl = NULL;
        size_t len_contents;
        CURL *curl;
+       CURLcode res;
        long response;
        struct CurlReadWrite chunk;
 
@@ -239,7 +240,9 @@ static void report_spam(gint id, ReportInterface *intf, MsgInfo *msginfo, gchar
                        curl_easy_setopt(curl, CURLOPT_TIMEOUT, prefs_common_get_prefs()->io_timeout_secs);
                        curl_easy_setopt(curl, CURLOPT_USERAGENT,
                                SPAM_REPORT_USERAGENT "(" PLUGINS_URI ")");
-                       curl_easy_perform(curl);
+                       res = curl_easy_perform(curl);
+                       if (res != CURLE_OK)
+                               debug_print("curl_easy_perfom failed: %s", curl_easy_strerror(res));
                        curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &response);
                        curl_easy_cleanup(curl);
                        spamreport_http_response_log(intf->url, response);
@@ -261,7 +264,9 @@ static void report_spam(gint id, ReportInterface *intf, MsgInfo *msginfo, gchar
                                SPAM_REPORT_USERAGENT "(" PLUGINS_URI ")");
                curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, curl_writefunction_cb);
                curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&chunk);
-               curl_easy_perform(curl);
+               res = curl_easy_perform(curl);
+               if (res != CURLE_OK)
+                       debug_print("curl_easy_perfom failed: %s", curl_easy_strerror(res));
                curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &response);
                curl_easy_cleanup(curl);
                spamreport_http_response_log(geturl, response);