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 780587 - Various Coverity code fixes
Various Coverity code fixes
Status: RESOLVED FIXED
Product: gnome-settings-daemon
Classification: Core
Component: general
unspecified
Other All
: Normal normal
: ---
Assigned To: gnome-settings-daemon-maint
gnome-settings-daemon-maint
Depends on:
Blocks:
 
 
Reported: 2017-03-27 11:32 UTC by Philip Withnall
Modified: 2017-03-29 13:00 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
power: Fix signed/unsigned assignment and comparison (1.70 KB, patch)
2017-03-27 11:32 UTC, Philip Withnall
committed Details | Review
rfkill: Refactor error handling for cc_rfkill_glib_open() (4.25 KB, patch)
2017-03-27 11:32 UTC, Philip Withnall
committed Details | Review
housekeeping: Ignore return value from mkdir() calls (1.58 KB, patch)
2017-03-27 11:33 UTC, Philip Withnall
committed Details | Review
clipboard: Fix potential divisions by zero (3.25 KB, patch)
2017-03-27 11:33 UTC, Philip Withnall
committed Details | Review
color: Potentially fix sunrise calcs for fractional timezone offsets (1.39 KB, patch)
2017-03-27 11:34 UTC, Philip Withnall
committed Details | Review

Description Philip Withnall 2017-03-27 11:32:29 UTC
Various minor fixes, mostly on errors paths. Includes one more important fix for sunrise calculations for non-integer timezones.
Comment 1 Philip Withnall 2017-03-27 11:32:35 UTC
Created attachment 348788 [details] [review]
power: Fix signed/unsigned assignment and comparison

The value retrieved from GSettings is a gint, so don’t implicitly cast
to to a guint before clamping it to a non-negative value.

Coverity ID: 1418248
Comment 2 Philip Withnall 2017-03-27 11:32:58 UTC
Created attachment 348789 [details] [review]
rfkill: Refactor error handling for cc_rfkill_glib_open()

Returning the FD is a bad idea, since ownership of it is already
transferred to the GUnixInputStream inside rfkill-glib.c. The only
caller (in gsd-rfkill-manager.c) doesn’t use the return value anyway.

Tidy this up a bit by using a GError instead. This changes how warning
messages are printed, but otherwise introduces no functional changes.

Coverity ID: 1418249
Comment 3 Philip Withnall 2017-03-27 11:33:34 UTC
Created attachment 348790 [details] [review]
housekeeping: Ignore return value from mkdir() calls

We don’t care whether they succeed, since there’s nothing we can do if
they fail. Notifying the user is fairly pointless, since not having the
directories around doesn’t result in a major loss of functionality.

Coverity ID: 1418240
Comment 4 Philip Withnall 2017-03-27 11:33:54 UTC
Created attachment 348791 [details] [review]
clipboard: Fix potential divisions by zero

If handling an unknown format of X data, the bytes_per_item will be
calculated as zero, which will cause a division by zero.

Return early in those cases.

Coverity IDs: 1418241, 1418244
Comment 5 Philip Withnall 2017-03-27 11:34:23 UTC
Created attachment 348792 [details] [review]
color: Potentially fix sunrise calcs for fractional timezone offsets

If a timezone is offset by a non-integer number of hours, the value of
tz_offset would be truncated. Fix that by casting to double first.

Coverity ID: 1418246
Comment 6 Bastien Nocera 2017-03-27 15:56:32 UTC
Review of attachment 348788 [details] [review]:

::: plugins/power/gsd-power-manager.c
@@ +1709,3 @@
         timeout_sleep = 0;
         if (!is_action_inhibited (manager, action_type)) {
+                gint timeout_sleep_;

I prefer _timeout_sleep though.
Comment 7 Bastien Nocera 2017-03-27 15:58:40 UTC
Review of attachment 348789 [details] [review]:

::: plugins/rfkill/rfkill-glib.c
@@ +359,3 @@
 }
 
+void

Please return a gboolean rather than void, so you can check cc_rfkill_glib_open()'s retval rather than for whether GError is set.
Comment 8 Bastien Nocera 2017-03-27 15:59:16 UTC
Review of attachment 348790 [details] [review]:

Certainly.
Comment 9 Bastien Nocera 2017-03-27 16:00:04 UTC
Review of attachment 348791 [details] [review]:

Sure.
Comment 10 Bastien Nocera 2017-03-27 16:01:27 UTC
Review of attachment 348792 [details] [review]:

There's a test program in gcm-self-test.c, can you please amend it to check for this error?
Looks good to commit now though.
Comment 11 Philip Withnall 2017-03-29 09:25:47 UTC
Comment on attachment 348791 [details] [review]
clipboard: Fix potential divisions by zero

Attachment 348791 [details] pushed as 694f27a - clipboard: Fix potential divisions by zero
Comment 12 Philip Withnall 2017-03-29 09:28:48 UTC
Attachment 348788 [details] pushed as 74a57e1 - power: Fix signed/unsigned assignment and comparison
Attachment 348790 [details] pushed as 968523c - housekeeping: Ignore return value from mkdir() calls
Comment 13 Philip Withnall 2017-03-29 09:35:06 UTC
Comment on attachment 348789 [details] [review]
rfkill: Refactor error handling for cc_rfkill_glib_open()

Pushed to master with a change to return a gboolean.

Attachment 348789 [details] pushed as d0bc039 - rfkill: Refactor error handling for cc_rfkill_glib_open()
Comment 14 Philip Withnall 2017-03-29 12:53:20 UTC
Comment on attachment 348792 [details] [review]
color: Potentially fix sunrise calcs for fractional timezone offsets

Pushed the sunrise/sunset fix to master with a change to add a unit test for it (yay for unit tests!). Verified that the fix unbreaks the new test case.

Attachment 348792 [details] pushed as e861325 - color: Potentially fix sunrise calcs for fractional timezone offsets
Comment 15 Philip Withnall 2017-03-29 13:00:37 UTC
Pushed the potential crasher/incorrectness fixes to gnome-3-24 too:

8bfac91 color: Potentially fix sunrise calcs for fractional timezone offsets
9c5fd32 clipboard: Fix potential divisions by zero