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 705968 - Fix use of uninitialized memory in ostree_builtin_checksum()
Fix use of uninitialized memory in ostree_builtin_checksum()
Status: RESOLVED FIXED
Product: ostree
Classification: Infrastructure
Component: general
unspecified
Other All
: Normal normal
: ---
Assigned To: OSTree maintainer(s)
OSTree maintainer(s)
Depends on:
Blocks:
 
 
Reported: 2013-08-14 08:21 UTC by Stef Walter
Modified: 2013-08-18 11:21 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Fix use of uninitialized memory in ostree_builtin_checksum() (963 bytes, patch)
2013-08-14 08:21 UTC, Stef Walter
committed Details | Review
Use { 0, } for structure initialization rather than memset() (5.83 KB, patch)
2013-08-17 12:00 UTC, Colin Walters
committed Details | Review

Description Stef Walter 2013-08-14 08:21:26 UTC
Causes a critical warning:


(ostree checksum:20281): GLib-CRITICAL **: g_main_loop_unref: assertion `g_atomic_int_get (&loop->ref_count) > 0' failed
ostree checksum: A filename must be given
Comment 1 Stef Walter 2013-08-14 08:21:32 UTC
Created attachment 251576 [details] [review]
Fix use of uninitialized memory in ostree_builtin_checksum()
Comment 2 Colin Walters 2013-08-17 03:00:00 UTC
Review of attachment 251576 [details] [review]:

I'd prefer:

memset (&data, 0, sizeof (data));

Since it's robust against other fields too.  Feel free to push with that change, thanks!
Comment 3 Stef Walter 2013-08-17 04:52:04 UTC
Review of attachment 251576 [details] [review]:

Will do, but FWIW = { 0, } is defined in C to set all fields to zero. Any fields not specified in the initializer will be set to zero.
Comment 4 Stef Walter 2013-08-17 05:09:19 UTC
Attachment 251576 [details] pushed as 349d795 - Fix use of uninitialized memory in ostree_builtin_checksum()
Comment 5 Colin Walters 2013-08-17 11:54:20 UTC
(In reply to comment #3)
> Review of attachment 251576 [details] [review]:
> 
> Will do, but FWIW = { 0, } is defined in C to set all fields to zero. Any
> fields not specified in the initializer will be set to zero.

Ok so... { 0, }; is one of those things that I somehow had it in my head "don't use this".  When you filed this patch, I couldn't remember exactly why, but I thought of something that sounded plausible =)

But the real reason, thinking about this more, is a while ago I was reading about kernel information leaks.  While it's true that { 0, } will fill in the fields, it *doesn't* necessarily fill in holes in the structure for padding, and this is really bad for a kernel.

We however are obviously not a kernel, and so we really should use { 0, } since it's significantly cleaner and more concise.  

Sorry about the brainfart!
Comment 6 Colin Walters 2013-08-17 12:00:20 UTC
Created attachment 252007 [details] [review]
Use { 0, } for structure initialization rather than memset()

It's cleaner, safer, and I had a totally wrong idea stuck in my head
about why memset() should be used.
Comment 7 Stef Walter 2013-08-17 12:49:44 UTC
(In reply to comment #5)
> But the real reason, thinking about this more, is a while ago I was reading
> about kernel information leaks.  While it's true that { 0, } will fill in the
> fields, it *doesn't* necessarily fill in holes in the structure for padding,
> and this is really bad for a kernel.

Interesting, good to know.
Comment 8 Colin Walters 2013-08-17 13:50:46 UTC
(In reply to comment #7)
> (In reply to comment #5)
> > But the real reason, thinking about this more, is a while ago I was reading
> > about kernel information leaks.  While it's true that { 0, } will fill in the
> > fields, it *doesn't* necessarily fill in holes in the structure for padding,
> > and this is really bad for a kernel.
> 
> Interesting, good to know.

Can you review the patch?  Not sure if you saw https://mail.gnome.org/archives/ostree-list/2013-August/msg00004.html
Comment 9 Stef Walter 2013-08-18 06:21:59 UTC
Comment on attachment 252007 [details] [review]
Use { 0, } for structure initialization rather than memset()

Looks good to me.
Comment 10 Colin Walters 2013-08-18 11:21:52 UTC
Attachment 252007 [details] pushed as eaee309 - Use { 0, } for structure initialization rather than memset()