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 780310 - g_tls_database_verify_chain doesn't set the GError for failures other than cancellation
g_tls_database_verify_chain doesn't set the GError for failures other than ca...
Status: RESOLVED FIXED
Product: glib
Classification: Platform
Component: network
unspecified
Other All
: Normal normal
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks:
 
 
Reported: 2017-03-20 15:11 UTC by Debarshi Ray
Modified: 2017-04-03 16:58 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
docs: Clarify the use of the GError in g_tls_database_verify_chain* (3.26 KB, patch)
2017-03-22 18:24 UTC, Debarshi Ray
none Details | Review
docs: Clarify the use of the GError in g_tls_database_verify_chain* (3.63 KB, patch)
2017-04-03 11:50 UTC, Debarshi Ray
committed Details | Review

Description Debarshi Ray 2017-03-20 15:11:26 UTC
It is idiomatic for GIO API to set the GError *and* return an appropriate return value when there is a failure. Sometimes there are exceptions and deviations (eg., the libsecret and gcr API), but I think those should be clearly documented.

Currently g_tls_database_verify_chain throws an error only if the operation was cancelled. If the certificate could not be verified due to actual problems with it, no error is thrown and only the flags (ie. the return value) is set. This can trick code that follows this pattern:

error = NULL;
result = foo_operation (arg1, ..., &error);
if (error != NULL)
  {
    /* handle the error */
  }

We should either throw an error or document this.
Comment 1 Dan Winship 2017-03-20 15:36:35 UTC
Throwing an error would be an API break, so this would be a documentation thing.

I guess the problem is that the function's name is wrong; it's not "verify that the chain is valid", it's "determine the verified-ness of the chain". Determining that the chain is invalid is considered success; it only returns an error if something prevents it from being able to check the chain at all.
Comment 2 Debarshi Ray 2017-03-22 18:24:25 UTC
Created attachment 348524 [details] [review]
docs: Clarify the use of the GError in g_tls_database_verify_chain*
Comment 3 Dan Winship 2017-03-23 14:18:31 UTC
Comment on attachment 348524 [details] [review]
docs: Clarify the use of the GError in g_tls_database_verify_chain*

That wording is kind of confusing. I'd suggest something like:

  If @chain is found to be valid, then the return value will be 0. If
  @chain is found to be invalid, then the return value will indicate the
  problems found. If the function is unable to determine whether @chain
  is valid or not (eg, because @cancellable is triggered before it
  completes) then the return value will be %G_TLS_CERTIFICATE_GENERIC_ERROR
  and @error will be set accordingly.

(If you want to add an additional parenthetical "(@error is not set when @chain is successfully analyzed but found to be invalid)" then go ahead.)
Comment 4 Debarshi Ray 2017-04-03 11:50:58 UTC
Created attachment 349174 [details] [review]
docs: Clarify the use of the GError in g_tls_database_verify_chain*
Comment 5 Debarshi Ray 2017-04-03 11:51:53 UTC
(In reply to Dan Winship from comment #3)

Thanks for the review!

> That wording is kind of confusing. I'd suggest something like:
> 
>   If @chain is found to be valid, then the return value will be 0. If
>   @chain is found to be invalid, then the return value will indicate the
>   problems found. If the function is unable to determine whether @chain
>   is valid or not (eg, because @cancellable is triggered before it
>   completes) then the return value will be %G_TLS_CERTIFICATE_GENERIC_ERROR
>   and @error will be set accordingly.
> 
> (If you want to add an additional parenthetical "(@error is not set when
> @chain is successfully analyzed but found to be invalid)" then go ahead.)

I updated the wording. What do you think?
Comment 6 Debarshi Ray 2017-04-03 16:58:35 UTC
Comment on attachment 349174 [details] [review]
docs: Clarify the use of the GError in g_tls_database_verify_chain*

Pushed to master. Thanks.