libupower-glib: up-client: Fix crash when printing the error message from a NULL GError pointer

Passing a NULL UpClient to up_client_get_devices2() led to the following
error message since up_client_get_devices_full() returned immediately
without properly setting up a GError with the reasons for the error.

(upower:21076): libupower-glib-CRITICAL **: 16:33:53.919: up_client_get_devices_full: assertion 'UP_IS_CLIENT (client)' failed
Segmentation fault         (core dumped) ./upower -d

Related: https://gitlab.freedesktop.org/upower/upower/-/merge_requests/296
This commit is contained in:
Kate Hsuan 2026-01-23 16:23:43 +08:00
parent f61735aa6d
commit 991a7d9433

View file

@ -106,7 +106,15 @@ up_client_get_devices_full (UpClient *client,
GPtrArray *array;
guint i;
g_return_val_if_fail (UP_IS_CLIENT (client), NULL);
if (!UP_IS_CLIENT (client)) {
g_set_error (error, G_IO_ERROR,
G_IO_ERROR_INVALID_ARGUMENT,
"Invalid UpClient object");
g_return_if_fail_warning (G_LOG_DOMAIN,
G_STRFUNC,
"UP_IS_CLIENT (client)");
return NULL;
}
if (up_exported_daemon_call_enumerate_devices_sync (client->priv->proxy,
&devices,