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 776115 - Patches for spotted Coverity errors
Patches for spotted Coverity errors
Status: RESOLVED FIXED
Product: libgrss
Classification: Other
Component: General
unspecified
Other Linux
: Normal normal
: ---
Assigned To: Libgrss Maintainers
Libgrss Maintainers
Depends on:
Blocks:
 
 
Reported: 2016-12-14 23:03 UTC by Carlos Garnacho
Modified: 2017-02-16 20:25 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Check socket() return value correctly (808 bytes, patch)
2016-12-14 23:04 UTC, Carlos Garnacho
committed Details | Review
Fix "Dereference after NULL check" Coverity error in PIE handler (1004 bytes, patch)
2016-12-14 23:04 UTC, Carlos Garnacho
none Details | Review
Fix "Dereference after NULL check" Coverity error in RSS handler (919 bytes, patch)
2016-12-14 23:04 UTC, Carlos Garnacho
none Details | Review
Fix "Dereference after NULL check" Coverity error in ATOM handler (893 bytes, patch)
2016-12-14 23:04 UTC, Carlos Garnacho
none Details | Review
Fix "Explicit NULL dereferenced" Coverity error (876 bytes, patch)
2016-12-14 23:04 UTC, Carlos Garnacho
none Details | Review
Fix "Explicit NULL dereferenced" Coverity error (955 bytes, patch)
2016-12-14 23:04 UTC, Carlos Garnacho
none Details | Review
src: Add missing NULL checks for XML elements (2.58 KB, patch)
2016-12-21 16:56 UTC, Philip Withnall
committed Details | Review
src: Remove some unnecessary NULL checks (1.39 KB, patch)
2016-12-21 16:56 UTC, Philip Withnall
needs-work Details | Review
src: Fix binding between mode and parameters in publisher (1.99 KB, patch)
2016-12-21 16:56 UTC, Philip Withnall
committed Details | Review
src: Fix check for return value from socket() (919 bytes, patch)
2016-12-21 16:56 UTC, Philip Withnall
none Details | Review

Description Carlos Garnacho 2016-12-14 23:03:17 UTC
I'm attaching some patches fixing warnings I saw in Coverity. All of these patches (except the one fixing socket() retval checks) are quite unlikely to happen, still good to keep the code robust.
Comment 1 Carlos Garnacho 2016-12-14 23:04:03 UTC
Created attachment 341975 [details] [review]
Check socket() return value correctly

socket() returns -1 in case of error, but that was being given
as good, and passed to connect(). Spotted through Coverity.
Comment 2 Carlos Garnacho 2016-12-14 23:04:08 UTC
Created attachment 341976 [details] [review]
Fix "Dereference after NULL check" Coverity error in PIE handler

The cur variable might end up NULL on the while loop above, and
its contents used in later code without further checks.
Comment 3 Carlos Garnacho 2016-12-14 23:04:13 UTC
Created attachment 341977 [details] [review]
Fix "Dereference after NULL check" Coverity error in RSS handler

The cur variable might end up NULL on the while loop above, and
its contents used in later code without further checks.
Comment 4 Carlos Garnacho 2016-12-14 23:04:18 UTC
Created attachment 341978 [details] [review]
Fix "Dereference after NULL check" Coverity error in ATOM handler

The cur variable might end up NULL on the while loop above, and
its contents used in later code without further checks.
Comment 5 Carlos Garnacho 2016-12-14 23:04:24 UTC
Created attachment 341979 [details] [review]
Fix "Explicit NULL dereferenced" Coverity error

The callback variable might end up NULL here, causing crashes
on strcmp().
Comment 6 Carlos Garnacho 2016-12-14 23:04:29 UTC
Created attachment 341980 [details] [review]
Fix "Explicit NULL dereferenced" Coverity error

The verify variable might end up NULL here, causing crashes
on strcmp().
Comment 7 Philip Withnall 2016-12-21 16:56:41 UTC
Created attachment 342341 [details] [review]
src: Add missing NULL checks for XML elements

If the loop to skip blank elements ends up reading the entire document,
cur will be set to NULL, and the following code (which dereferences its
elements) will crash. Avoid that by checking cur again.

Coverity IDs: 1388544, 1388545, 1388548
Comment 8 Philip Withnall 2016-12-21 16:56:47 UTC
Created attachment 342342 [details] [review]
src: Remove some unnecessary NULL checks

These were redundant, given that feed was dereferenced on every path up
to them. Add a precondition check for NULL instead.

Coverity ID: 1388550
Comment 9 Philip Withnall 2016-12-21 16:56:52 UTC
Created attachment 342343 [details] [review]
src: Fix binding between mode and parameters in publisher

Previously, the code assumed that the correct parameters were provided
for each mode, but that’s not necessarily the case. If incorrect
parameters were provided (specifically, if the ones pertaining to the
given mode were missing), some NULL pointer dereferences would happen
and hence the code would crash.

Fix that by checking for the parameters and returning error 400 if they
are not present.

Coverity IDs: 1388546, 1388547
Comment 10 Philip Withnall 2016-12-21 16:56:57 UTC
Created attachment 342344 [details] [review]
src: Fix check for return value from socket()

Failure is indicated by a negative number, not by 0. 0 is a valid FD,
although it’s normally used by stdio.

Coverity ID: 1388549
Comment 11 Philip Withnall 2016-12-21 16:57:59 UTC
I think the original patches here are partially incorrect, as they don’t set GErrors or the HTTP return status when they bail out in error cases. Here’s a set of patches which does. (I don’t know if they’re completely right though: this is just a drive-by patch dump.)
Comment 12 Philip Withnall 2016-12-21 17:36:48 UTC
I wrote my patches before I new Carlos’ existed, so some are duplicates.
Comment 13 Igor Gnatenko 2017-02-16 19:58:52 UTC
Review of attachment 341975 [details] [review]:

lgtm
Comment 14 Igor Gnatenko 2017-02-16 19:58:54 UTC
Review of attachment 341975 [details] [review]:

lgtm
Comment 15 Igor Gnatenko 2017-02-16 19:59:24 UTC
Review of attachment 342341 [details] [review]:

lgtm
Comment 16 Igor Gnatenko 2017-02-16 20:00:02 UTC
Review of attachment 342342 [details] [review]:

::: src/feed-atom-handler.c
@@ +330,3 @@
 	gchar *alternate = NULL;
 
+	g_return_val_if_fail GRSS_IS_FEED_CHANNEL (feed), NULL);

missing opening brace
Comment 17 Igor Gnatenko 2017-02-16 20:00:51 UTC
Review of attachment 342343 [details] [review]:

lgtm
Comment 18 Igor Gnatenko 2017-02-16 20:00:51 UTC
Review of attachment 342343 [details] [review]:

lgtm
Comment 19 Philip Withnall 2017-02-16 20:25:04 UTC
Thanks for the reviews. Pushed with the missing bracket fixed. I accidentally pushed my version of attachment #341975 [details] rather than Carlos’, but they are identical.

f47bef4 src: Fix check for return value from socket()
79842ad src: Fix binding between mode and parameters in publisher
7021e8c src: Remove some unnecessary NULL checks
9a9376c src: Add missing NULL checks for XML elements