diff options
author | Reuben Green <[email protected]> | 2019-08-03 22:54:44 +0100 |
---|---|---|
committer | raveit65 <[email protected]> | 2019-08-06 16:25:46 +0200 |
commit | 807e54f51919de389c2824df6ccef41947c57911 (patch) | |
tree | 5a41441b1a2f9d60de9a720f41fb27789e67cbae | |
parent | aa8c51c24a3d716986ace9a4104a9632436ccff5 (diff) | |
download | atril-807e54f51919de389c2824df6ccef41947c57911.tar.bz2 atril-807e54f51919de389c2824df6ccef41947c57911.tar.xz |
prevent segfaults when no document loaded
See the issue report for a description of the bug. The root cause is
dereferencing of NULL pointers, specifically the priv->document member of
EvWindow structures when no document is loaded. This commit adds checks
for a NULL value of priv->document at all the points in the file
shell/ev-window.c where this pointer was previously dereferenced without
being checked.
Fixes 357 (https://github.com/mate-desktop/atril/issues/357)
-rw-r--r-- | shell/ev-window.c | 63 |
1 files changed, 32 insertions, 31 deletions
diff --git a/shell/ev-window.c b/shell/ev-window.c index e1893115..a74639d8 100644 --- a/shell/ev-window.c +++ b/shell/ev-window.c @@ -1448,7 +1448,7 @@ setup_view_from_metadata (EvWindow *window) /* Presentation */ if (ev_metadata_get_boolean (window->priv->metadata, "presentation", &presentation)) { if (presentation) { - if (window->priv->document->iswebdocument == TRUE ) { + if (window->priv->document && window->priv->document->iswebdocument == TRUE ) { return; } else { @@ -1849,7 +1849,7 @@ static void ev_window_handle_link (EvWindow *ev_window, EvLinkDest *dest) { - if (ev_window->priv->document->iswebdocument == TRUE ) { + if (ev_window->priv->document && ev_window->priv->document->iswebdocument == TRUE ) { return; } if (dest) { @@ -4116,7 +4116,7 @@ ev_window_cmd_edit_select_all (GtkAction *action, EvWindow *ev_window) */ if (ev_window->priv->chrome & EV_CHROME_FINDBAR) { egg_find_bar_grab_focus(ev_window->priv->find_bar); - } else if (ev_window->priv->document->iswebdocument == FALSE ) { + } else if (ev_window->priv->document && ev_window->priv->document->iswebdocument == FALSE ) { ev_view_select_all (EV_VIEW (ev_window->priv->view)); } #if ENABLE_EPUB @@ -4151,7 +4151,7 @@ ev_window_cmd_edit_find_next (GtkAction *action, EvWindow *ev_window) update_chrome_flag (ev_window, EV_CHROME_FINDBAR, TRUE); update_chrome_visibility (ev_window); gtk_widget_grab_focus (ev_window->priv->find_bar); - if (ev_window->priv->document->iswebdocument == FALSE) { + if (ev_window->priv->document && ev_window->priv->document->iswebdocument == FALSE) { ev_view_find_next (EV_VIEW (ev_window->priv->view)); } #if ENABLE_EPUB @@ -4170,7 +4170,7 @@ ev_window_cmd_edit_find_previous (GtkAction *action, EvWindow *ev_window) update_chrome_flag (ev_window, EV_CHROME_FINDBAR, TRUE); update_chrome_visibility (ev_window); gtk_widget_grab_focus (ev_window->priv->find_bar); - if (ev_window->priv->document->iswebdocument == FALSE) { + if (ev_window->priv->document && ev_window->priv->document->iswebdocument == FALSE) { ev_view_find_previous (EV_VIEW (ev_window->priv->view)); } #if ENABLE_EPUB @@ -4185,7 +4185,7 @@ ev_window_cmd_edit_copy (GtkAction *action, EvWindow *ev_window) { g_return_if_fail (EV_IS_WINDOW (ev_window)); #if ENABLE_EPUB - if (ev_window->priv->document->iswebdocument) { + if (ev_window->priv->document && ev_window->priv->document->iswebdocument) { ev_web_view_copy(EV_WEB_VIEW(ev_window->priv->webview)); } else #endif @@ -4405,8 +4405,9 @@ ev_window_run_presentation (EvWindow *window) if (EV_WINDOW_IS_PRESENTATION (window)) return; + - if (window->priv->document->iswebdocument) { + if (window->priv->document && window->priv->document->iswebdocument) { ev_window_warning_message(window,_("Presentation mode is not supported for ePub documents")); return; } @@ -4794,7 +4795,7 @@ ev_window_cmd_view_zoom_in (GtkAction *action, EvWindow *ev_window) ev_document_model_set_sizing_mode (ev_window->priv->model, EV_SIZING_FREE); #if ENABLE_EPUB - if (ev_window->priv->document->iswebdocument) { + if (ev_window->priv->document && ev_window->priv->document->iswebdocument) { ev_web_view_zoom_in(EV_WEB_VIEW(ev_window->priv->webview)); } else @@ -4811,7 +4812,7 @@ ev_window_cmd_view_zoom_out (GtkAction *action, EvWindow *ev_window) ev_document_model_set_sizing_mode (ev_window->priv->model, EV_SIZING_FREE); #if ENABLE_EPUB - if ( ev_window->priv->document->iswebdocument) { + if (ev_window->priv->document && ev_window->priv->document->iswebdocument) { ev_web_view_zoom_out(EV_WEB_VIEW(ev_window->priv->webview)); } else @@ -4828,7 +4829,7 @@ ev_window_cmd_view_zoom_reset (GtkAction *action, EvWindow *ev_window) ev_document_model_set_sizing_mode (ev_window->priv->model, EV_SIZING_FREE); #if ENABLE_EPUB - if ( ev_window->priv->document->iswebdocument) { + if (ev_window->priv->document && ev_window->priv->document->iswebdocument) { ev_web_view_zoom_reset(EV_WEB_VIEW(ev_window->priv->webview)); } else @@ -4843,7 +4844,7 @@ ev_window_cmd_go_previous_page (GtkAction *action, EvWindow *ev_window) { g_return_if_fail (EV_IS_WINDOW (ev_window)); #if ENABLE_EPUB - if ( ev_window->priv->document->iswebdocument == TRUE ) { + if (ev_window->priv->document && ev_window->priv->document->iswebdocument == TRUE ) { ev_web_view_previous_page(EV_WEB_VIEW(ev_window->priv->webview)); } else @@ -4858,7 +4859,7 @@ ev_window_cmd_go_next_page (GtkAction *action, EvWindow *ev_window) { g_return_if_fail (EV_IS_WINDOW (ev_window)); #if ENABLE_EPUB - if ( ev_window->priv->document->iswebdocument == TRUE ) { + if (ev_window->priv->document && ev_window->priv->document->iswebdocument == TRUE ) { ev_web_view_next_page(EV_WEB_VIEW(ev_window->priv->webview)); } else #endif @@ -5447,8 +5448,8 @@ view_menu_link_popup (EvWindow *ev_window, gboolean show_internal = FALSE; GtkAction *action; - if ( ev_window->priv->document->iswebdocument == TRUE ) return ; - + if (ev_window->priv->document && ev_window->priv->document->iswebdocument == TRUE ) return ; + if (ev_window->priv->link) g_object_unref (ev_window->priv->link); @@ -5501,7 +5502,7 @@ view_menu_image_popup (EvWindow *ev_window, GtkAction *action; gboolean show_image = FALSE; - if (ev_window->priv->document->iswebdocument == TRUE ) return ; + if (ev_window->priv->document && ev_window->priv->document->iswebdocument == TRUE ) return ; if (ev_window->priv->image) g_object_unref (ev_window->priv->image); @@ -5529,7 +5530,7 @@ view_menu_annot_popup (EvWindow *ev_window, gboolean show_annot = FALSE; gboolean can_remove_annots = FALSE; - if (ev_window->priv->document->iswebdocument == TRUE ) return ; + if (ev_window->priv->document && ev_window->priv->document->iswebdocument == TRUE ) return ; if (ev_window->priv->annot) g_object_unref (ev_window->priv->annot); ev_window->priv->annot = (annot) ? g_object_ref (annot) : NULL; @@ -5683,7 +5684,7 @@ ev_window_find_job_updated_cb (EvJobFind *job, { ev_window_update_actions (ev_window); #if ENABLE_EPUB - if (ev_window->priv->document->iswebdocument == TRUE ) { + if (ev_window->priv->document && ev_window->priv->document->iswebdocument == TRUE ) { ev_web_view_find_changed(EV_WEB_VIEW(ev_window->priv->webview), job->results,job->text, job->case_sensitive); } @@ -5720,7 +5721,7 @@ find_bar_previous_cb (EggFindBar *find_bar, EvWindow *ev_window) { #if ENABLE_EPUB - if (ev_window->priv->document->iswebdocument == TRUE ) { + if (ev_window->priv->document && ev_window->priv->document->iswebdocument == TRUE ) { ev_web_view_find_previous(EV_WEB_VIEW(ev_window->priv->webview)); }else #endif @@ -5734,7 +5735,7 @@ find_bar_next_cb (EggFindBar *find_bar, EvWindow *ev_window) { #if ENABLE_EPUB - if (ev_window->priv->document->iswebdocument == TRUE ) { + if (ev_window->priv->document && ev_window->priv->document->iswebdocument == TRUE ) { ev_web_view_find_next(EV_WEB_VIEW(ev_window->priv->webview)); } else #endif @@ -5748,7 +5749,7 @@ find_bar_close_cb (EggFindBar *find_bar, EvWindow *ev_window) { #if ENABLE_EPUB - if (ev_window->priv->document->iswebdocument == TRUE ) { + if (ev_window->priv->document && ev_window->priv->document->iswebdocument == TRUE ) { ev_web_view_find_cancel(EV_WEB_VIEW(ev_window->priv->webview)); } else @@ -5804,7 +5805,7 @@ find_bar_search_changed_cb (EggFindBar *find_bar, { /* Either the string or case sensitivity could have changed. */ #if ENABLE_EPUB - if (ev_window->priv->document->iswebdocument) { + if (ev_window->priv->document && ev_window->priv->document->iswebdocument) { ev_web_view_find_search_changed(EV_WEB_VIEW (ev_window->priv->webview)); } else #endif @@ -6574,7 +6575,7 @@ static const GtkActionEntry attachment_popup_entries [] = { static void sidebar_links_link_activated_cb (EvSidebarLinks *sidebar_links, EvLink *link, EvWindow *window) { - if (window->priv->document->iswebdocument == FALSE ) { + if (window->priv->document && window->priv->document->iswebdocument == FALSE ) { ev_view_handle_link (EV_VIEW (window->priv->view), link); } #if ENABLE_EPUB @@ -6603,7 +6604,7 @@ static void navigation_action_activate_link_cb (EvNavigationAction *action, EvLink *link, EvWindow *window) { #if ENABLE_EPUB - if (window->priv->document->iswebdocument == TRUE ) { + if (window->priv->document && window->priv->document->iswebdocument == TRUE ) { ev_web_view_handle_link(EV_WEB_VIEW(window->priv->webview),link); gtk_widget_grab_focus (window->priv->webview); return; @@ -6617,7 +6618,7 @@ static void sidebar_layers_visibility_changed (EvSidebarLayers *layers, EvWindow *window) { - if (window->priv->document->iswebdocument == FALSE ) { + if (window->priv->document && window->priv->document->iswebdocument == FALSE ) { ev_view_reload (EV_VIEW (window->priv->view)); } #if ENABLE_EPUB @@ -6633,7 +6634,7 @@ sidebar_annots_annot_activated_cb (EvSidebarAnnotations *sidebar_annots, EvMapping *annot_mapping, EvWindow *window) { - if (window->priv->document->iswebdocument == TRUE ) return; + if (window->priv->document && window->priv->document->iswebdocument == TRUE ) return; ev_view_focus_annotation (EV_VIEW (window->priv->view), annot_mapping); } @@ -6642,7 +6643,7 @@ sidebar_annots_begin_annot_add (EvSidebarAnnotations *sidebar_annots, EvAnnotationType annot_type, EvWindow *window) { - if (window->priv->document->iswebdocument == TRUE ) return; + if (window->priv->document && window->priv->document->iswebdocument == TRUE ) return; ev_view_begin_add_annotation (EV_VIEW (window->priv->view), annot_type); } @@ -6667,7 +6668,7 @@ static void sidebar_annots_annot_add_cancelled (EvSidebarAnnotations *sidebar_annots, EvWindow *window) { - if (window->priv->document->iswebdocument == TRUE ) return; + if (window->priv->document && window->priv->document->iswebdocument == TRUE ) return; ev_view_cancel_add_annotation (EV_VIEW (window->priv->view)); } @@ -7074,7 +7075,7 @@ view_external_link_cb (EvWindow *window, EvLinkAction *action) static void ev_view_popup_cmd_open_link (GtkAction *action, EvWindow *window) { - if (window->priv->document->iswebdocument == TRUE ) return; + if (window->priv->document && window->priv->document->iswebdocument == TRUE ) return; ev_view_handle_link (EV_VIEW (window->priv->view), window->priv->link); } @@ -7099,7 +7100,7 @@ static void ev_view_popup_cmd_copy_link_address (GtkAction *action, EvWindow *window) { EvLinkAction *ev_action; - if (window->priv->document->iswebdocument == TRUE ) return; + if (window->priv->document && window->priv->document->iswebdocument == TRUE ) return; ev_action = ev_link_get_action (window->priv->link); if (!ev_action) return; @@ -7289,8 +7290,8 @@ static void ev_view_popup_cmd_annot_properties (GtkAction *action, EvWindow *window) { - if (window->priv->document->iswebdocument == TRUE ) return; - + if (window->priv->document && window->priv->document->iswebdocument == TRUE ) return; + const gchar *author; GdkRGBA rgba; gdouble opacity; |