After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 783587 - Crash when NULL is passed to GtkActionHelper to unset action-name
Crash when NULL is passed to GtkActionHelper to unset action-name
Status: RESOLVED FIXED
Product: gtk+
Classification: Platform
Component: .General
3.22.x
Other All
: Normal normal
: ---
Assigned To: gtk-bugs
gtk-bugs
Depends on:
Blocks: 742662
 
 
Reported: 2017-06-09 10:11 UTC by Debarshi Ray
Modified: 2017-06-13 20:00 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
GtkActionHelper: Allow a NULL action-name to unset the previous GAction (4.09 KB, patch)
2017-06-09 10:27 UTC, Debarshi Ray
none Details | Review
GtkActionHelper: Allow a NULL action-name to unset the previous GAction (5.65 KB, patch)
2017-06-13 08:50 UTC, Debarshi Ray
committed Details | Review
GtkActionHelper: Remove unnecessary NULL check (1.77 KB, patch)
2017-06-13 09:09 UTC, Debarshi Ray
committed Details | Review

Description Debarshi Ray 2017-06-09 10:11:19 UTC
gtk_actionable_set_action_name [1] is supposed to accept a NULL action-name to dissociate the widget from any previous GAction. However, implementations using GtkActionHelper fail to do that and crash:

  • #0 g_str_hash
    at ghash.c line 1882
  • #1 g_hash_table_lookup_node
    at ghash.c line 379
  • #2 g_hash_table_lookup
    at ghash.c line 1153
  • #3 gtk_action_muxer_register_observer
    at gtkactionmuxer.c line 470
  • #4 gtk_action_helper_set_action_name
    at gtkactionhelper.c line 434
  • #5 photos_zoom_bar_update_buttons
    at photos-zoom-bar.c line 68
  • #6 photos_zoom_bar_notify_idle
    at photos-zoom-bar.c line 99
  • #7 g_idle_dispatch
    at gmain.c line 5500
  • #8 g_main_dispatch
    at gmain.c line 3148
  • #9 g_main_context_dispatch
    at gmain.c line 3813
  • #10 g_main_context_iterate
    at gmain.c line 3886
  • #11 g_main_context_iteration
    at gmain.c line 3947
  • #12 g_application_run
    at gapplication.c line 2378
  • #13 main
    at photos-main.c line 72

There are three GtkActionHelper based widgets at the moment - GtkMenuItem, GtkButton and GtkSwitch. Of those, the latter two seem to have regressed with https://git.gnome.org/browse/gtk+/commit/?id=694be447e3f08e8ff4341099048e9b17a24c8f0e and https://git.gnome.org/browse/gtk+/commit/?id=fbb38e95ac40a50178f7dbbba5dfa8c0c0cdfb85

Note how gtk_button_update_action_observer and gtk_switch_update_action_observer used to be careful about a NULL action-name.

[1] https://developer.gnome.org/gtk3/stable/GtkActionable.html#gtk-actionable-set-action-name
Comment 1 Debarshi Ray 2017-06-09 10:26:04 UTC
Note that I didn't originally intend to use NULL to unset the GAction. I wanted to switch the same GtkButton between two GActions - one without any parameters, and one that takes a double. Unfortunately, these sequences of calls trigger the WARNING in gtk_action_helper_action_added:
 gtk_actionable_set_action_name (..., "action-no-parameter");
 gtk_actionable_set_action_name (..., "action-parameter");
 gtk_actionable_set_action_target (..., "d", 1.0);
... or:
 gtk_actionable_set_action_name (..., "action-parameter");
 gtk_actionable_set_action_target (..., "d", 1.0);
 gtk_actionable_set_action_name (..., "action-no-parameter");

It tries to match the parameter type from the earlier action with the target from the newer action. Trying to work around that by forcefully unsetting the GAction led to this bug.

One bug at a time...
Comment 2 Debarshi Ray 2017-06-09 10:27:04 UTC
Created attachment 353451 [details] [review]
GtkActionHelper: Allow a NULL action-name to unset the previous GAction
Comment 3 Matthias Clasen 2017-06-12 14:35:28 UTC
Review of attachment 353451 [details] [review]:

Seems like the function must accept NULL, indeed.

::: gtk/gtkactionhelper.c
@@ +473,1 @@
 

I think this is not quite right. When setting action_name to NULL, we also need to set enabled to FALSE, I believe, and call gtk_action_helper_report_change
Comment 4 Debarshi Ray 2017-06-13 08:27:21 UTC
(In reply to Matthias Clasen from comment #3)
> Review of attachment 353451 [details] [review] [review]:
> 
> Seems like the function must accept NULL, indeed.
> 
> ::: gtk/gtkactionhelper.c
> @@ +473,1 @@
>  
> 
> I think this is not quite right. When setting action_name to NULL, we also
> need to set enabled to FALSE, I believe, and call
> gtk_action_helper_report_change

Ok. I wasn't sure if enabled should be TRUE or FALSE because ultimately it drives GtkWidget:sensitive which is TRUE by default. But I think FALSE is right because it matches with the gtk_action_observer_action_removed behaviour.
Comment 5 Debarshi Ray 2017-06-13 08:50:21 UTC
Created attachment 353660 [details] [review]
GtkActionHelper: Allow a NULL action-name to unset the previous GAction
Comment 6 Debarshi Ray 2017-06-13 09:09:48 UTC
Created attachment 353662 [details] [review]
GtkActionHelper: Remove unnecessary NULL check

I don't understand this comment in gtk_action_helper_set_action_name:
   * When called during construction, widget is NULL.  We don't need to                                               
   * report in that case.

And in trying to understand that, I found this needless NULL check.
Comment 7 Matthias Clasen 2017-06-13 19:18:09 UTC
Review of attachment 353660 [details] [review]:

it looks right to me
Comment 8 Matthias Clasen 2017-06-13 19:19:46 UTC
Review of attachment 353662 [details] [review]:

hmm, right
Comment 9 Matthias Clasen 2017-06-13 19:21:30 UTC
Review of attachment 353662 [details] [review]:

hmm, right
Comment 10 Debarshi Ray 2017-06-13 20:00:13 UTC
Thanks for the reviews! Pushed to master and gtk-3-22.