After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 777508 - smartcard: Some fixes for error handling
smartcard: Some fixes for error handling
Status: RESOLVED FIXED
Product: gnome-settings-daemon
Classification: Core
Component: smartcard
unspecified
Other All
: Normal normal
: ---
Assigned To: Ray Strode [halfline]
gnome-settings-daemon-maint
Depends on:
Blocks:
 
 
Reported: 2017-01-19 20:28 UTC by Philip Withnall
Modified: 2017-01-24 09:59 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
smartcard: Set an error on cancellation (1.16 KB, patch)
2017-01-19 20:28 UTC, Philip Withnall
none Details | Review
smartcard: Fix a g_task_return_error(task, NULL) call (2.03 KB, patch)
2017-01-19 20:28 UTC, Philip Withnall
none Details | Review
smartcard: Set an error on cancellation (1.10 KB, patch)
2017-01-21 08:54 UTC, Philip Withnall
committed Details | Review
smartcard: Fix a g_task_return_error(task, NULL) call (3.29 KB, patch)
2017-01-21 08:54 UTC, Philip Withnall
none Details | Review
smartcard: Fix a g_task_return_error(task, NULL) call (2.76 KB, patch)
2017-01-24 09:58 UTC, Bastien Nocera
committed Details | Review

Description Philip Withnall 2017-01-19 20:28:00 UTC
Here are a couple of fixes I made after spotting the following line in my journal:
   gnome-settings-[641]: g_task_return_error: assertion 'error != NULL' failed

I believe they are the only two places in gnome-settings-daemon which could be causing this control flow, so hopefully they fix it. I can’t currently verify because rebuilding and testing g-s-d is a pain and I have limited time. Feel free to reject the patches on that basis.
Comment 1 Philip Withnall 2017-01-19 20:28:04 UTC
Created attachment 343842 [details] [review]
smartcard: Set an error on cancellation

All callers of watch_one_event_from_driver() expect that iff it returns
FALSE, an error is set. That was not the case on the cancellation path.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
Comment 2 Philip Withnall 2017-01-19 20:28:09 UTC
Created attachment 343843 [details] [review]
smartcard: Fix a g_task_return_error(task, NULL) call

It’s possible for activate_all_drivers_async_finish() to return FALSE
without an error set, in the case that there were no drivers to activate
(but there were no errors either).

Fix on_all_drivers_activated() to not assume that FALSE means error,
thus fixing a warning I saw in my journal:
   gnome-settings-[641]: g_task_return_error: assertion 'error != NULL' failed

Signed-off-by: Philip Withnall <withnall@endlessm.com>
Comment 3 Bastien Nocera 2017-01-20 10:29:19 UTC
Review of attachment 343842 [details] [review]:

Remove the S-o-B please.
Comment 4 Bastien Nocera 2017-01-20 10:31:11 UTC
Review of attachment 343843 [details] [review]:

::: plugins/smartcard/gsd-smartcard-manager.c
@@ +600,3 @@
         PK11SlotInfo *login_token;
 
+        activate_all_drivers_async_finish (self, result, &error);

I'd rather have activate_all_drivers_async_finish() return an error with the code itself saying that there were not drivers to enable.
Comment 5 Philip Withnall 2017-01-21 08:54:31 UTC
Created attachment 343941 [details] [review]
smartcard: Set an error on cancellation

All callers of watch_one_event_from_driver() expect that iff it returns
FALSE, an error is set. That was not the case on the cancellation path.
Comment 6 Philip Withnall 2017-01-21 08:54:37 UTC
Created attachment 343942 [details] [review]
smartcard: Fix a g_task_return_error(task, NULL) call

It’s possible for activate_all_drivers_async_finish() to return FALSE
without an error set, in the case that there were no drivers to activate
(but there were no errors either).

Fix it to return a new error code
(GSD_SMARTCARD_MANAGER_ERROR_NO_DRIVERS) in that case, to preserve the
invariant that a FALSE return value means an error, thus fixing a
warning I saw in my journal:
   gnome-settings-[641]: g_task_return_error: assertion 'error != NULL' failed
Comment 7 Philip Withnall 2017-01-21 08:55:32 UTC
(In reply to Bastien Nocera from comment #3)
> Review of attachment 343842 [details] [review] [review]:
> 
> Remove the S-o-B please.

Out of interest, why drop it? Is it doing any harm? All it means is that I’ve certified I’ve got the rights to the code I’m submitting. If the project doesn’t require that (I don’t know if any GNOME projects do?) it doesn’t matter.

(In reply to Bastien Nocera from comment #4)
> Review of attachment 343843 [details] [review] [review]:
> 
> ::: plugins/smartcard/gsd-smartcard-manager.c
> @@ +600,3 @@
>          PK11SlotInfo *login_token;
>  
> +        activate_all_drivers_async_finish (self, result, &error);
> 
> I'd rather have activate_all_drivers_async_finish() return an error with the
> code itself saying that there were not drivers to enable.

Fixed!
Comment 8 Bastien Nocera 2017-01-21 23:52:47 UTC
Review of attachment 343941 [details] [review]:

Yep.
Comment 9 Bastien Nocera 2017-01-21 23:54:33 UTC
Review of attachment 343942 [details] [review]:

::: plugins/smartcard/gsd-smartcard-manager.c
@@ +606,1 @@
+        if (error != NULL) {

Revert that hunk and:
if (g_error_matches(...)) {
   g_clear_error (&error);
} else {
   g_task_return_error ();
   return;
}
Comment 10 Bastien Nocera 2017-01-21 23:56:59 UTC
(In reply to Philip Withnall from comment #7)
> (In reply to Bastien Nocera from comment #3)
> > Review of attachment 343842 [details] [review] [review] [review]:
> > 
> > Remove the S-o-B please.
> 
> Out of interest, why drop it? Is it doing any harm? All it means is that
> I’ve certified I’ve got the rights to the code I’m submitting. If the
> project doesn’t require that (I don’t know if any GNOME projects do?) it
> doesn’t matter.

That's what it means *for the kernel*. You can only S-o-b, for the kernel, with a real name as well, which means that we can't use it if we still want anonymous, or pseudonymous contributions. In this case, it doesn't mean anything, and just pollutes the logs.
Comment 11 Philip Withnall 2017-01-22 00:21:42 UTC
Review of attachment 343942 [details] [review]:

I deliberately left the error reporting in here (rather than squashing the NO_DRIVERS error). I know it’s a change of behaviour, but if I’ve followed the control flow through correctly, I think it just results in a g_debug() entry later on (and nothing else) anyway, so I thought it was best to keep things simple and go with that.
Comment 12 Bastien Nocera 2017-01-24 09:58:34 UTC
Created attachment 344099 [details] [review]
smartcard: Fix a g_task_return_error(task, NULL) call

It’s possible for activate_all_drivers_async_finish() to return FALSE
without an error set, in the case that there were no drivers to activate
(but there were no errors either).

Fix it to return a new error code
(GSD_SMARTCARD_MANAGER_ERROR_NO_DRIVERS) in that case, to preserve the
invariant that a FALSE return value means an error, thus fixing a
warning I saw in my journal:
   gnome-settings-[641]: g_task_return_error: assertion 'error != NULL' failed
Comment 13 Bastien Nocera 2017-01-24 09:59:37 UTC
Attachment 343941 [details] pushed as fc1f51c - smartcard: Set an error on cancellation
Attachment 344099 [details] pushed as b719bc0 - smartcard: Fix a g_task_return_error(task, NULL) call