bleakgrey / tootle

GTK-based Mastodon client for Linux
GNU General Public License v3.0
404 stars 61 forks source link

Segfault trying to load account #312

Closed bugaevc closed 3 years ago

bugaevc commented 3 years ago

Upon logging in to my instance, Tootle immediately segfaulted with this stacktrace:

#0  0x0000000000417868 in tootle_instance_account_get_is_active ()
    at ../src/Services/Accounts/InstanceAccount.vala:22
#1  0x00000000004196c5 in _vala_tootle_instance_account_get_property ()
    at ../src/Services/Accounts/InstanceAccount.vala:4
#2  0x00007f587fccc671 in g_object_get_property () at /lib64/libgobject-2.0.so.0
#3  0x00007f587fa1273e in json_gobject_dump.lto_priv () at /lib64/libjson-glib-1.0.so.0
#4  0x00007f587fa128fa in json_gobject_serialize () at /lib64/libjson-glib-1.0.so.0
#5  0x000000000043c4b3 in tootle_entity_to_json () at ../src/API/Entity.vala:49
#6  0x000000000044e355 in tootle_dialogs_new_account_request_token_co ()
    at ../src/Dialogs/NewAccount.vala:160
#7  0x000000000044d8e6 in tootle_dialogs_new_account_request_token_ready ()
    at ../src/Dialogs/NewAccount.vala:150
#8  0x00007f587fadaa7a in g_task_return_now () at /lib64/libgio-2.0.so.0
#9  0x00007f587fadac7b in g_task_return () at /lib64/libgio-2.0.so.0
#10 0x0000000000415d3e in tootle_instance_account_verify_credentials_co ()
    at ../src/Services/Accounts/InstanceAccount.vala:90
#11 0x000000000041573d in tootle_instance_account_verify_credentials_ready ()
    at ../src/Services/Accounts/InstanceAccount.vala:92
#12 0x00007f587fadaa7a in g_task_return_now () at /lib64/libgio-2.0.so.0
#13 0x00007f587fadac7b in g_task_return () at /lib64/libgio-2.0.so.0
#14 0x000000000042646e in tootle_request_await_co () at ../src/Services/Network/Request.vala:131
#15 0x000000000042609a in __lambda24_ ()
    at ../src/Services/Network/Request.vala:123
#16 0x00000000004260cc in ___lambda24__tootle_network_success_callback ()
    at ../src/Services/Network/Request.vala:122
#17 0x0000000000423230 in ___lambda4_ ()
    at ../src/Services/Network/Network.vala:55
#18 0x0000000000423336 in ____lambda4__soup_session_callback ()
    at ../src/Services/Network/Network.vala:52
#19 0x00007f587fc6404b in soup_session_process_queue_item.part () at /lib64/libsoup-2.4.so.1
#20 0x00007f587fc6459d in async_run_queue () at /lib64/libsoup-2.4.so.1
#21 0x00007f587fc646ba in idle_run_queue () at /lib64/libsoup-2.4.so.1
#22 0x00007f587fe2174b in g_idle_dispatch () at /lib64/libglib-2.0.so.0
#23 0x00007f587fe254cf in g_main_context_dispatch () at /lib64/libglib-2.0.so.0
#24 0x00007f587fe794e8 in g_main_context_iterate.constprop () at /lib64/libglib-2.0.so.0
#25 0x00007f587fe22c03 in g_main_context_iteration () at /lib64/libglib-2.0.so.0
#26 0x00007f587fb0895d in g_application_run () at /lib64/libgio-2.0.so.0
#27 0x000000000040e820 in tootle_application_main () at ../src/Application.vala:77
#28 0x000000000040e84c in main () at ../src/Application.vala:65

The crash is on this line:

https://github.com/bleakgrey/tootle/blob/cb7a17963ca491562e83005ec19018e9b94dd134/src/Services/Accounts/InstanceAccount.vala#L22

It gets compiled to the following C code:

gboolean
tootle_instance_account_get_is_active (TootleInstanceAccount* self)
{
        gboolean result;
        TootleAccountStore* _tmp0_;
        TootleInstanceAccount* _tmp1_;
        TootleInstanceAccount* _tmp2_;
        const gchar* _tmp3_;
        const gchar* _tmp4_;
#line 22 "../src/Services/Accounts/InstanceAccount.vala"
        g_return_val_if_fail (self != NULL, FALSE);
#line 22 "../src/Services/Accounts/InstanceAccount.vala"
        _tmp0_ = tootle_accounts;
#line 22 "../src/Services/Accounts/InstanceAccount.vala"
        _tmp1_ = tootle_account_store_get_active (_tmp0_);
#line 22 "../src/Services/Accounts/InstanceAccount.vala"
        _tmp2_ = _tmp1_;
#line 22 "../src/Services/Accounts/InstanceAccount.vala"
        _tmp3_ = _tmp2_->priv->_access_token;
#line 22 "../src/Services/Accounts/InstanceAccount.vala"
        _tmp4_ = self->priv->_access_token;
#line 22 "../src/Services/Accounts/InstanceAccount.vala"
        result = g_strcmp0 (_tmp3_, _tmp4_) == 0;
#line 22 "../src/Services/Accounts/InstanceAccount.vala"
        return result;
#line 2074 "InstanceAccount.c"
}

In GDB, I see that _tmp1_ and _tmp2_ are both NULL, and the crash is at trying to access _tmp2_->priv->_access_token.

Build

The OS is Fedora Linux 34.

I built the app at 8907af6753027389f24d299d8ab97bfe0d8f2ca1 (which is my PR based on cb7a17963ca491562e83005ec19018e9b94dd134), with the following additional patch applied:

diff --git a/meson.build b/meson.build
index 73b228a..314b743 100644
--- a/meson.build
+++ b/meson.build
@@ -26,8 +26,18 @@ asresources = gnome.compile_resources(
   c_name: 'as'
 )

-libgtk_dep = dependency('gtk4', version: '>=4.3.0', required: true)
-libadwaita_dep = dependency('libadwaita-1', version: '>=1.0.0', required: true)
+libgtk_dep = dependency('gtk4', required: true)
+libadwaita_dep = dependency(
+  'libadwaita-1',
+  version: '>=1.0.0',
+  required: false,
+)
+
+if not libadwaita_dep.found()
+  libadwaita_proj = subproject('libadwaita')
+  libadwaita_dep = libadwaita_proj.get_variable('libadwaita_dep')
+  libadwaita_vapi = libadwaita_proj.get_variable('libadwaita_vapi')
+endif

 sources = files(
     'src/Application.vala',
@@ -123,6 +133,7 @@ executable(
         dependency('libsecret-1', required: true),
         libgtk_dep,
         libadwaita_dep,
+        libadwaita_vapi,
     ],
     install: true,
 )
diff --git a/subprojects/libadwaita.wrap b/subprojects/libadwaita.wrap
index 3f864f9..12a4362 100644
--- a/subprojects/libadwaita.wrap
+++ b/subprojects/libadwaita.wrap
@@ -1,5 +1,5 @@
 [wrap-file]
-directory=libadwaita-594eb987c57e4d20370cc20520871f230ff02ae2
-source_url=https://gitlab.gnome.org/GNOME/libadwaita/-/archive/594eb987c57e4d20370cc20520871f230ff02ae2/libadwaita-594eb987c57e4d20370cc20520871f230ff02ae2.zip
-source_filename=libadwaita-594eb987c57e4d20370cc20520871f230ff02ae2.zip
-source_hash=a2c604e573ac1f87c5f3ae6dbd9349666ad574321a66f9f05bb27d785db18aa7
+directory=libadwaita-959f4340f05914ed8f03497ba74aa3887ed493e2
+source_url=https://gitlab.gnome.org/GNOME/libadwaita/-/archive/959f4340f05914ed8f03497ba74aa3887ed493e2/libadwaita-959f4340f05914ed8f03497ba74aa3887ed493e2.zip
+source_filename=libadwaita-959f4340f05914ed8f03497ba74aa3887ed493e2.zip
+source_hash=062d2b40b9410d457f535e40595058d58a66d18b076ad96b7a9fba6809715dbf

The purpose of the patch is to be able to do a non-Flatpak build with whatever version of GTK 4 I have installed and the very latest libadwaita as a subproject. Perhaps you'd want to include something like that upstream; but it doesn't seem to be related to the crash.

Logs

** (com.github.bleakgrey.tootle:210230): WARNING **: 16:36:47.421: NewAccount.vala:51: Using manual auth method

** (com.github.bleakgrey.tootle:210230): CRITICAL **: 16:36:47.421: string_to_string: assertion 'self != NULL' failed
** Message: 16:36:47.421: Network.vala:49: POST: https://mastodon.technology/api/v1/apps
** Message: 16:36:48.023: NewAccount.vala:124: OK: Instance registered client
** Message: 16:36:48.024: NewAccount.vala:131: Opening permission request page
** Message: 16:36:48.024: Host.vala:11: Opening URI: https://mastodon.technology/oauth/authorize?scope=read write follow&response_type=code&redirect_uri=urn:ietf:wg:oauth:2.0:oob&client_id=redacted
Failed to register: Timeout was reached
** Message: 16:37:28.454: NewAccount.vala:142: Requesting access token

** (com.github.bleakgrey.tootle:210230): CRITICAL **: 16:37:28.455: string_to_string: assertion 'self != NULL' failed
** Message: 16:37:28.455: Network.vala:49: POST: https://mastodon.technology/oauth/token?redirect_uri=urn:ietf:wg:oauth:2.0:oob&client_id=redacted&client_secret=redacted&grant_type=authorization_code&code=redacted
** Message: 16:37:29.187: Network.vala:49: GET: https://mastodon.technology/api/v1/accounts/verify_credentials
** Message: 16:37:29.393: InstanceAccount.vala:98: @bugaevc@mastodon.technology: profile updated
Segmentation fault (core dumped)
bleakgrey commented 3 years ago

Did the app restart correctly afterwards, or does the crash persist?

bugaevc commented 3 years ago

No idea, I haven't tried.

McSinyx commented 2 years ago

The problem persists on latest release (2.0-alpha1) as well as current master (02f918d6377f78481de1b9d9485bfb4fa183aaaa) on NixOS:

Log

```console $ result/bin/com.github.bleakgrey.tootle ** Message: 22:57:56.310: Build.vala:41: Tootle 2.0-alpha1 ** Message: 22:57:56.310: Build.vala:41: Running on: NixOS 22.05 (Quokka) ** Message: 22:57:56.310: Build.vala:41: Build prefix: "/nix/store/f2hcs6mpajqf6xaqbx6r4slfczmmr5bw-tootle-unstable-2021-09-09" ** Message: 22:57:56.362: SecretAccountStore.vala:11: Using libsecret v0.20.4 ** Message: 22:57:56.364: SecretAccountStore.vala:45: Loaded 0 accounts ** Message: 22:57:56.365: AccountStore.vala:81: Reset active account ** Message: 22:57:56.365: Application.vala:134: Presenting NewAccount dialog ** (com.github.bleakgrey.tootle:967989): CRITICAL **: 22:57:56.369: string_to_string: assertion 'self != NULL' failed ** (com.github.bleakgrey.tootle:967989): CRITICAL **: 22:57:56.370: string_to_string: assertion 'self != NULL' failed ** Message: 22:57:56.492: NewAccount.vala:65: Reset state ** (com.github.bleakgrey.tootle:967989): CRITICAL **: 22:57:56.492: string_to_string: assertion 'self != NULL' failed ** (com.github.bleakgrey.tootle:967989): CRITICAL **: 22:57:56.492: string_to_string: assertion 'self != NULL' failed ** (com.github.bleakgrey.tootle:967989): CRITICAL **: 22:57:56.492: string_to_string: assertion 'self != NULL' failed ** Message: 22:57:56.606: Application.vala:134: Presenting NewAccount dialog ** Message: 22:57:56.609: NewAccount.vala:65: Reset state ** (com.github.bleakgrey.tootle:967989): CRITICAL **: 22:57:56.609: string_to_string: assertion 'self != NULL' failed ** (com.github.bleakgrey.tootle:967989): CRITICAL **: 22:57:56.609: string_to_string: assertion 'self != NULL' failed ** (com.github.bleakgrey.tootle:967989): CRITICAL **: 22:57:56.609: string_to_string: assertion 'self != NULL' failed ** Message: 22:57:56.609: NewAccount.vala:65: Reset state ** (com.github.bleakgrey.tootle:967989): CRITICAL **: 22:57:56.609: string_to_string: assertion 'self != NULL' failed ** (com.github.bleakgrey.tootle:967989): CRITICAL **: 22:57:56.609: string_to_string: assertion 'self != NULL' failed ** (com.github.bleakgrey.tootle:967989): CRITICAL **: 22:57:56.609: string_to_string: assertion 'self != NULL' failed ** Message: 22:57:56.609: NewAccount.vala:65: Reset state ** (com.github.bleakgrey.tootle:967989): CRITICAL **: 22:57:56.609: string_to_string: assertion 'self != NULL' failed ** (com.github.bleakgrey.tootle:967989): CRITICAL **: 22:57:56.609: string_to_string: assertion 'self != NULL' failed ** (com.github.bleakgrey.tootle:967989): CRITICAL **: 22:57:56.609: string_to_string: assertion 'self != NULL' failed ** Message: 22:58:02.028: NewAccount.vala:96: Checking instance URL ** (com.github.bleakgrey.tootle:967989): CRITICAL **: 22:58:02.030: string_to_string: assertion 'self != NULL' failed ** Message: 22:58:02.030: Network.vala:49: GET: https://nixnet.social/api/v1/instance ** Message: 22:58:02.824: AccountStore.vala:152: https://nixnet.social is using Mastodon ** Message: 22:58:02.825: NewAccount.vala:111: Registering client ** Message: 22:58:02.876: NewAccount.vala:47: Successfully associated MIME type for automatic authorization ** (com.github.bleakgrey.tootle:967989): CRITICAL **: 22:58:02.876: string_to_string: assertion 'self != NULL' failed ** Message: 22:58:02.876: Network.vala:49: POST: https://nixnet.social/api/v1/apps ** Message: 22:58:03.799: NewAccount.vala:124: OK: Instance registered client ** Message: 22:58:03.800: NewAccount.vala:131: Opening permission request page ** Message: 22:58:03.800: Host.vala:11: Opening URI: https://nixnet.social/oauth/authorize?scope=read write follow&response_type=code&redirect_uri=tootle://auth_code&client_id=Cb3PejqOeVMYgCYhJWZ3FfmnR3hdIb6pYGMbRSK-5mQ ** Message: 22:58:05.543: NewAccount.vala:65: Reset state ** (com.github.bleakgrey.tootle:967989): CRITICAL **: 22:58:05.543: string_to_string: assertion 'self != NULL' failed ** (com.github.bleakgrey.tootle:967989): CRITICAL **: 22:58:05.543: string_to_string: assertion 'self != NULL' failed ** (com.github.bleakgrey.tootle:967989): CRITICAL **: 22:58:05.543: string_to_string: assertion 'self != NULL' failed ** Message: 22:58:05.770: NewAccount.vala:65: Reset state ** (com.github.bleakgrey.tootle:967989): CRITICAL **: 22:58:05.771: string_to_string: assertion 'self != NULL' failed ** (com.github.bleakgrey.tootle:967989): CRITICAL **: 22:58:05.771: string_to_string: assertion 'self != NULL' failed ** (com.github.bleakgrey.tootle:967989): CRITICAL **: 22:58:05.771: string_to_string: assertion 'self != NULL' failed ** Message: 22:58:06.545: NewAccount.vala:96: Checking instance URL ** (com.github.bleakgrey.tootle:967989): CRITICAL **: 22:58:06.547: string_to_string: assertion 'self != NULL' failed ** Message: 22:58:06.547: Network.vala:49: GET: https://nixnet.social/api/v1/instance ** Message: 22:58:06.781: AccountStore.vala:152: https://nixnet.social is using Mastodon ** Message: 22:58:06.781: NewAccount.vala:111: Registering client ** (com.github.bleakgrey.tootle:967989): WARNING **: 22:58:06.781: NewAccount.vala:51: Using manual auth method ** (com.github.bleakgrey.tootle:967989): CRITICAL **: 22:58:06.781: string_to_string: assertion 'self != NULL' failed ** Message: 22:58:06.781: Network.vala:49: POST: https://nixnet.social/api/v1/apps ** Message: 22:58:07.766: NewAccount.vala:124: OK: Instance registered client ** Message: 22:58:07.766: NewAccount.vala:131: Opening permission request page ** Message: 22:58:07.766: Host.vala:11: Opening URI: https://nixnet.social/oauth/authorize?scope=read write follow&response_type=code&redirect_uri=urn:ietf:wg:oauth:2.0:oob&client_id=P4h_zxBpXNNv4vGEe9awibUniH8ji2gasszTDgDSATA ** Message: 22:58:14.259: NewAccount.vala:142: Requesting access token ** (com.github.bleakgrey.tootle:967989): CRITICAL **: 22:58:14.260: string_to_string: assertion 'self != NULL' failed ** Message: 22:58:14.260: Network.vala:49: POST: https://nixnet.social/oauth/token?redirect_uri=urn:ietf:wg:oauth:2.0:oob&client_id=P4h_zxBpXNNv4vGEe9awibUniH8ji2gasszTDgDSATA&client_secret=PlWhKupiA3ZVctvuzqiYR54Te_lUxWr7xsALh9JqiSE&grant_type=authorization_code&code=bKbIfhDOoZhJow8J2tT_WmldvHVcq9vHf2NFuG9iuA4 ** Message: 22:58:14.968: Network.vala:49: GET: https://nixnet.social/api/v1/accounts/verify_credentials ** Message: 22:58:15.199: InstanceAccount.vala:98: @cnx@nixnet.social: profile updated Segmentation fault (core dumped) ```

The log above was produced from the result of the recipe at https://github.com/McSinyx/nixpkgs/commit/14b6226ea03cda69010db6fb145ed394d33ca618