From 919e8972a6635539499f153a28d92e0c4052b354 Mon Sep 17 00:00:00 2001
From: Ondrej Holy <oholy@redhat.com>
Date: Tue, 30 Jan 2018 08:58:20 +0100
Subject: [PATCH 15/15] act-user: Prevent segfault if accounts_proxy is not
created
act_user_get_locked may segfault if accounts_proxy is not created (e.g.
when run under root). All other functions which rely on accounts_proxy
already contain checks for NULL and valid ActUser. Do the same also in
act_user_get_locked in order to avoid segfaults in certain cases.
https://bugs.freedesktop.org/show_bug.cgi?id=104851
---
src/libaccountsservice/act-user.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/src/libaccountsservice/act-user.c b/src/libaccountsservice/act-user.c
index a24f25a..e21c9db 100644
--- a/src/libaccountsservice/act-user.c
+++ b/src/libaccountsservice/act-user.c
@@ -859,60 +859,65 @@ act_user_is_logged_in (ActUser *user)
/**
* act_user_is_logged_in_anywhere:
* @user: a #ActUser
*
* Returns whether or not #ActUser is currently logged in in any way
* whatsoever. See also act_user_is_logged_in().
*
* (Currently, this function is only implemented for systemd-logind.
* For ConsoleKit, it is equivalent to act_user_is_logged_in.)
*
* Returns: %TRUE or %FALSE
*/
gboolean
act_user_is_logged_in_anywhere (ActUser *user)
{
return user->our_sessions != NULL || user->other_sessions != NULL;
}
/**
* act_user_get_locked:
* @user: a #ActUser
*
* Returns whether or not the #ActUser account is locked.
*
* Returns: %TRUE or %FALSE
*/
gboolean
act_user_get_locked (ActUser *user)
{
+ g_return_val_if_fail (ACT_IS_USER (user), TRUE);
+
+ if (user->accounts_proxy == NULL)
+ return TRUE;
+
return accounts_user_get_locked (user->accounts_proxy);
}
/**
* act_user_get_automatic_login:
* @user: a #ActUser
*
* Returns whether or not #ActUser is automatically logged in at boot time.
*
* Returns: %TRUE or %FALSE
*/
gboolean
act_user_get_automatic_login (ActUser *user)
{
g_return_val_if_fail (ACT_IS_USER (user), FALSE);
if (user->accounts_proxy == NULL)
return FALSE;
return accounts_user_get_automatic_login (user->accounts_proxy);
}
/**
* act_user_is_system_account:
* @user: a #ActUser
*
* Returns whether or not #ActUser represents a 'system account' like
* 'root' or 'nobody'.
*
* Returns: %TRUE or %FALSE
--
2.14.3