From 1511eb93eab7844b5d317e13d4ed4d7a18335efa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Tue, 2 Mar 2021 16:17:14 +0100 Subject: [PATCH] device: Do not list invalid prints as enrolled The user may have some invalid prints saved (like the ones enrolled with fprintd 1) in the storage, this lead to list such prints as enrolled but they're actually not valid. So load the prints to ensure that those are of the valid type instead of just discovering them. We may make just store.discover_prints to be aware of this, but this would break some assumptions we do in tests, so better to go this way. --- src/device.c | 25 ++++++++++++++----------- tests/fprintd.py | 9 +++++++++ 2 files changed, 23 insertions(+), 11 deletions(-) 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)