diff --git a/src/device.c b/src/device.c index 1d317c7..716ad78 100644 --- a/src/device.c +++ b/src/device.c @@ -1917,22 +1917,30 @@ fprint_device_list_enrolled_fingers (FprintDBusDevice *dbus_dev, const char *username) { FprintDevice *rdev = FPRINT_DEVICE (dbus_dev); - FprintDevicePrivate *priv = fprint_device_get_instance_private (rdev); g_autoptr(GPtrArray) ret = NULL; - g_autoptr(GSList) prints = NULL; - GSList *item; + g_autoptr(GPtrArray) prints = NULL; const char *sender; const char *user; + guint i; sender = g_dbus_method_invocation_get_sender (invocation); _fprint_device_add_client (rdev, sender); user = g_object_get_qdata (G_OBJECT (invocation), quark_auth_user); g_assert (user); - prints = store.discover_prints (priv->dev, user); + prints = load_user_prints (rdev, user); - if (!prints) + ret = g_ptr_array_new (); + for (i = 0; i < prints->len; i++) + { + FpFinger finger = fp_print_get_finger (g_ptr_array_index (prints, i)); + + if (finger != FP_FINGER_UNKNOWN) + g_ptr_array_add (ret, (char *) fp_finger_to_name (finger)); + } + + if (!ret->len) { g_dbus_method_invocation_return_error_literal (invocation, FPRINT_ERROR, @@ -1941,12 +1949,7 @@ fprint_device_list_enrolled_fingers (FprintDBusDevice *dbus_dev, return TRUE; } - ret = g_ptr_array_new (); - for (item = prints; item; item = item->next) - { - FpFinger finger = GPOINTER_TO_UINT (item->data); - g_ptr_array_add (ret, (char *) fp_finger_to_name (finger)); - } + /* Add null-termination */ g_ptr_array_add (ret, NULL); fprint_dbus_device_complete_list_enrolled_fingers (dbus_dev, diff --git a/tests/fprintd.py b/tests/fprintd.py index aaf6508..fb74993 100644 --- a/tests/fprintd.py +++ b/tests/fprintd.py @@ -1265,6 +1265,15 @@ class FPrintdVirtualDeviceTest(FPrintdVirtualDeviceBaseTest): with self.assertFprintError('NoEnrolledPrints'): self.device.ListEnrolledFingers('(s)', 'testuser') + def test_unclaimed_list_enrolled_fingers_ignores_invalid(self): + print_path = self.get_print_file_path('testuser', FPrint.Finger.LEFT_INDEX) + os.makedirs(os.path.dirname(print_path), exist_ok=True) + with open(print_path, mode='wb') as new_print_file: + new_print_file.write(b'I am an invalid print!') + + with self.assertFprintError('NoEnrolledPrints'): + self.device.ListEnrolledFingers('(s)', 'testuser') + def test_claim_device_open_fail(self): os.rename(self.tmpdir, self.tmpdir + '-moved') self.addCleanup(os.rename, self.tmpdir + '-moved', self.tmpdir)