Skip to content
  • Sergey Bugaev's avatar
    urilauncher: Fix use-after-free on GCC < 12 · 46363b61
    Sergey Bugaev authored
    
    
    Building GTK with GCC 8 results in the following warning:
    
      gtk/gtkurilauncher.c: In function ‘gtk_uri_launcher_launch’:
      gtk/gtkurilauncher.c:315:3: warning: this ‘else’ clause does not guard... [-Wmisleading-indentation]
         else
         ^~~~
      gtk/gtkurilauncher.c:317:1: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the ‘else’
       G_GNUC_BEGIN_IGNORE_DEPRECATIONS
       ^~~
    
    In the compiled code, gtk_show_uri_full () is invoked whether the portal
    branch is taken or not, leading to use-after-free of the task.
    
    It looks like GCC in versions older than 12 treats the _Pragma(s) that
    G_GNUC_BEGIN_IGNORE_DEPRECATIONS expands to as C-level statements, and
    therefore the pragma takes up the 'else' statement slot.
    
    See https://godbolt.org/z/e5zqbaqxo for a simple reproducer.
    
    Signed-off-by: default avatarSergey Bugaev <bugaevc@gmail.com>
    46363b61