[gnome-control-center/wip/oholy/libpwquality-crashes: 25/25] user-accounts: Fix libpwquality error handling



commit f27b99e3385a055939a2420f726942d7a7e4325e
Author: Ondrej Holy <oholy redhat com>
Date:   Thu Aug 30 16:33:06 2018 +0200

    user-accounts: Fix libpwquality error handling
    
    Always use pwquality_strerror() in case of error in order to prevent
    memory leaks and to improve error messages.
    
    https://gitlab.gnome.org/GNOME/gnome-control-center/issues/171

 panels/user-accounts/pw-utils.c | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)
---
diff --git a/panels/user-accounts/pw-utils.c b/panels/user-accounts/pw-utils.c
index 5a07036e5..0f4dfd8b0 100644
--- a/panels/user-accounts/pw-utils.c
+++ b/panels/user-accounts/pw-utils.c
@@ -34,10 +34,15 @@ get_pwq (void)
 
         if (settings == NULL) {
                 gchar *err = NULL;
+                gint rv = 0;
+
                 settings = pwquality_default_settings ();
                 pwquality_set_int_value (settings, PWQ_SETTING_MAX_SEQUENCE, 4);
-                if (pwquality_read_config (settings, NULL, (gpointer)&err) < 0) {
-                        g_warning ("failed to read pwquality configuration: %s\n", err);
+
+                rv = pwquality_read_config (settings, NULL, (gpointer)&err);
+                if (rv < 0) {
+                        g_warning ("failed to read pwquality configuration: %s\n",
+                                   pwquality_strerror (NULL, 0, rv, err));
                         pwquality_free_settings (settings);
 
                         /* Load just default settings in case of failure. */
@@ -53,9 +58,12 @@ gint
 pw_min_length (void)
 {
         gint value = 0;
+        gint rv;
 
-        if (pwquality_get_int_value (get_pwq (), PWQ_SETTING_MIN_LENGTH, &value) < 0) {
-                g_warning ("Failed to read pwquality setting\n");
+        rv = pwquality_get_int_value (get_pwq (), PWQ_SETTING_MIN_LENGTH, &value);
+        if (rv < 0) {
+                g_warning ("Failed to read pwquality setting: %s\n",
+                           pwquality_strerror (NULL, 0, rv, NULL));
         }
 
         return value;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]