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 792402 - glib-networking Coverity fixes
glib-networking Coverity fixes
Status: RESOLVED FIXED
Product: glib
Classification: Platform
Component: network
unspecified
Other All
: Normal normal
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks:
 
 
Reported: 2018-01-10 12:05 UTC by Philip Withnall
Modified: 2018-01-11 10:52 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
gnutls: Fix use of undefined variables on early cancellation (1.59 KB, patch)
2018-01-10 12:05 UTC, Philip Withnall
committed Details | Review
tests: Fix addressing of buffers in tests (1.12 KB, patch)
2018-01-10 12:05 UTC, Philip Withnall
committed Details | Review

Description Philip Withnall 2018-01-10 12:05:43 UTC
A couple of fixes spotted by Coverity.
Comment 1 Philip Withnall 2018-01-10 12:05:48 UTC
Created attachment 366598 [details] [review]
gnutls: Fix use of undefined variables on early cancellation

If a claim_op() operation is cancelled before entering its blocking
while loop, the value of `result` would be undefined, which is bad.
Initialise `result` to a value which imitates what would happen had the
while loop been iterated and *then* cancelled.

Coverity CID: 249792

Signed-off-by: Philip Withnall <withnall@endlessm.com>
Comment 2 Philip Withnall 2018-01-10 12:05:55 UTC
Created attachment 366599 [details] [review]
tests: Fix addressing of buffers in tests

They were being referenced once too much, which was causing the tests to
write into arbitrary memory.

Coverity CID: 249795

Signed-off-by: Philip Withnall <withnall@endlessm.com>
Comment 3 Michael Catanzaro 2018-01-10 19:01:27 UTC
Review of attachment 366598 [details] [review]:

This one should go on the glib-2-54 branch as well.

::: tls/gnutls/gtlsconnection-gnutls.c
@@ +741,3 @@
       int nfds;
       gint64 start_time;
+      gint result = 1;  /* if the loop is never entered, it’s as if we cancelled early */

Why 1 and not 0? Wouldn't it be 0 if the poll call timed out?
Comment 4 Michael Catanzaro 2018-01-10 19:02:23 UTC
Review of attachment 366599 [details] [review]:

OK
Comment 5 Philip Withnall 2018-01-11 10:46:22 UTC
(In reply to Michael Catanzaro from comment #3)
> Review of attachment 366598 [details] [review] [review]:
> 
> This one should go on the glib-2-54 branch as well.
> 
> ::: tls/gnutls/gtlsconnection-gnutls.c
> @@ +741,3 @@
>        int nfds;
>        gint64 start_time;
> +      gint result = 1;  /* if the loop is never entered, it’s as if we
> cancelled early */
> 
> Why 1 and not 0? Wouldn't it be 0 if the poll call timed out?

If we are to hit the path where `result` is referenced by the code while being undefined, then the `while` loop has to not be iterated at all. That means that either of the cancellables are already cancelled by the time its condition is first checked. A cancellable being cancelled is *not* equivalent to timeout in this code: it’s equivalent to one of the FDs in the g_poll() call becoming readable (because that’s what the poll() call is for). That would imply (result == 1) or (result == 2). I chose (result == 1) out of those options, since (result == 2) is only possible if both cancellables are present (which is not always the case; see higher up in the function).

Does that make sense?
Comment 6 Philip Withnall 2018-01-11 10:47:24 UTC
t log -2 --oneline# Bug 792402 - glib-networking Coverity fixes - NEW
Pushed to master. Will push both to glib-2-54 shortly.

Attachment 366598 [details] pushed as eb24905 - gnutls: Fix use of undefined variables on early cancellation
Attachment 366599 [details] pushed as 2812952 - tests: Fix addressing of buffers in tests
Comment 7 Philip Withnall 2018-01-11 10:52:49 UTC
Actually, neither of these apply on glib-2-54, and neither of them are relevant (those tests don’t exist, and the g_poll() result is not handled in gtlsconnection-gnutls.c because none of the new custom GSource code is there).