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 730381 - addressbook: Add bounds checking to a summary file function
addressbook: Add bounds checking to a summary file function
Status: RESOLVED FIXED
Product: evolution-data-server
Classification: Platform
Component: general
unspecified
Other All
: Normal normal
: ---
Assigned To: Evolution Shell Maintainers Team
Evolution QA team
Depends on:
Blocks:
 
 
Reported: 2014-05-19 14:03 UTC by Philip Withnall
Modified: 2014-11-03 22:21 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
addressbook: Add bounds checking to a summary file function (1.25 KB, patch)
2014-05-19 14:03 UTC, Philip Withnall
committed Details | Review
addressbook: Fix ordering of parameters to fread() (1.29 KB, patch)
2014-11-01 13:55 UTC, Philip Withnall
committed Details | Review
camel: Fix ordering of parameters to fread() (1.96 KB, patch)
2014-11-01 13:55 UTC, Philip Withnall
reviewed Details | Review
camel: Fix ordering of parameters to fread() (1.36 KB, patch)
2014-11-03 15:50 UTC, Philip Withnall
committed Details | Review
camel: Fix ordering of parameters to fwrite() (2.80 KB, patch)
2014-11-03 16:01 UTC, Philip Withnall
committed Details | Review
addressbook: Fix ordering of parameters to fwrite() (1.63 KB, patch)
2014-11-03 16:01 UTC, Philip Withnall
committed Details | Review

Description Philip Withnall 2014-05-19 14:03:19 UTC
Patch attached.
Comment 1 Philip Withnall 2014-05-19 14:03:21 UTC
Created attachment 276779 [details] [review]
addressbook: Add bounds checking to a summary file function

There was not a bug here, as the len parameter always came from a
guint16, so no overflow was possible. However, a bounds check is always
a good idea and makes the code more robust in the face of future
changes.

Coverity issue: #1061517
Comment 2 Milan Crha 2014-05-19 16:37:01 UTC
Review of attachment 276779 [details] [review]:

Heh, G_MAXSIZE is quite large value. Feel free to commit. Thanks.
Comment 3 Philip Withnall 2014-05-20 10:11:36 UTC
Attachment 276779 [details] pushed as 2a5d6db - addressbook: Add bounds checking to a summary file function
Comment 4 Philip Withnall 2014-11-01 13:55:10 UTC
Created attachment 289779 [details] [review]
addressbook: Fix ordering of parameters to fread()

This is a follow up to commit 2a5d6db6, since it did not eliminate the
use of tainted data in the sense that fread() was being called with a
variable-sized size argument, when it should be called with a
variable-sized nmemb argument.

Coverity issue: #1061517
Comment 5 Philip Withnall 2014-11-01 13:55:15 UTC
Created attachment 289780 [details] [review]
camel: Fix ordering of parameters to fread()

fread() takes two integer parameters: size and nmemb. size should always
be constant, as it is a structure size. nmemb may vary. Using these two
parameters the correct way around means the return value is consistently
related to nmemb, and static analysers such as Coverity can perform
taint tests on the values passed to size.

Coverity issue: #1061517
Comment 6 Philip Withnall 2014-11-01 14:03:29 UTC
So, having rescanned with Coverity, this didn’t entirely fix the issue. Two patches attached to fix it further, and the same underlying issue in other places in EDS.
Comment 7 Milan Crha 2014-11-03 10:20:43 UTC
Review of attachment 289779 [details] [review]:

Looks good, feel free to commit to sources.

::: addressbook/libedata-book/e-book-backend-summary.c
@@ +275,3 @@
 {
 	gchar *buf;
+	gsize rv;

it's not accurate, if size_t changes (fread's return value is size_t), but I guess this will work too, thus feel free to commit it.
Comment 8 Milan Crha 2014-11-03 10:23:52 UTC
Review of attachment 289780 [details] [review]:

::: camel/providers/nntp/camel-nntp-store-summary.c
@@ +296,3 @@
 	}
 
+	if (fread (is->last_newslist, NNTP_DATE_SIZE, 1, in) != 1)

This change doesn't make much sense to me. At all the other occurrences (attached patches here) you changed the call in the other way, that the chunk size is 1 byte (sizeof(gchar)), and you save 'len' chunks, while you expect to have read/written 'len' chunks. Why do you do that here in the opposite way?
Comment 9 Philip Withnall 2014-11-03 15:50:11 UTC
Created attachment 289911 [details] [review]
camel: Fix ordering of parameters to fread()

fread() takes two integer parameters: size and nmemb. size should always
be constant, as it is a structure size. nmemb may vary. Using these two
parameters the correct way around means the return value is consistently
related to nmemb, and static analysers such as Coverity can perform
taint tests on the values passed to size.

Coverity issue: #1061517
Comment 10 Philip Withnall 2014-11-03 15:50:51 UTC
(In reply to comment #8)
> This change doesn't make much sense to me. At all the other occurrences
> (attached patches here) you changed the call in the other way, that the chunk
> size is 1 byte (sizeof(gchar)), and you save 'len' chunks, while you expect to
> have read/written 'len' chunks. Why do you do that here in the opposite way?

You’re right. I misread NNTP_DATE_SIZE as being something like sizeof(NntpDate), rather than being the length of a string. I’ve reverted that patch chunk.
Comment 11 Philip Withnall 2014-11-03 15:52:40 UTC
Comment on attachment 289779 [details] [review]
addressbook: Fix ordering of parameters to fread()

Committed the first patch with the s/gsize/size_t/ change.

Attachment 289779 [details] pushed as 9ccd4ce - addressbook: Fix ordering of parameters to fread()
Comment 12 Philip Withnall 2014-11-03 16:01:32 UTC
Created attachment 289916 [details] [review]
camel: Fix ordering of parameters to fwrite()

fwrite() takes two integer parameters: size and nmemb. size should always
be constant, as it is a structure size. nmemb may vary. Using these two
parameters the correct way around means the return value is consistently
related to nmemb, and static analysers such as Coverity can perform
taint tests on the values passed to size.
Comment 13 Philip Withnall 2014-11-03 16:01:36 UTC
Created attachment 289917 [details] [review]
addressbook: Fix ordering of parameters to fwrite()

fwrite() takes two integer parameters: size and nmemb. size should always
be constant, as it is a structure size. nmemb may vary. Using these two
parameters the correct way around means the return value is consistently
related to nmemb, and static analysers such as Coverity can perform
taint tests on the values passed to size.
Comment 14 Milan Crha 2014-11-03 18:22:20 UTC
Review of attachment 289911 [details] [review]:

Looks good, feel free to commit to sources.
Comment 15 Milan Crha 2014-11-03 18:23:40 UTC
Review of attachment 289916 [details] [review]:

Looks good, feel free to commit to sources.
Comment 16 Milan Crha 2014-11-03 18:27:32 UTC
Review of attachment 289917 [details] [review]:

Looks good, feel free to commit to sources.
Comment 17 Philip Withnall 2014-11-03 22:21:06 UTC
Attachment 289911 [details] pushed as 6a69786 - camel: Fix ordering of parameters to fread()
Attachment 289916 [details] pushed as f81b1ec - camel: Fix ordering of parameters to fwrite()
Attachment 289917 [details] pushed as 08b65f5 - addressbook: Fix ordering of parameters to fwrite()