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 751385 - Hard-to-reproduce crash due to unescaped '%' chars in overview.html
Hard-to-reproduce crash due to unescaped '%' chars in overview.html
Status: RESOLVED FIXED
Product: epiphany
Classification: Core
Component: General
unspecified
Other All
: Normal normal
: ---
Assigned To: Epiphany Maintainers
Epiphany Maintainers
: 737994 (view as bug list)
Depends on:
Blocks:
 
 
Reported: 2015-06-23 15:15 UTC by Emanuele Aina
Modified: 2015-08-03 08:55 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
overview: Escape bare '%' used in a printf-style template (2.31 KB, patch)
2015-06-23 15:15 UTC, Emanuele Aina
none Details | Review
overview: Move the overview CSS to about.css and generate the HTML from the code (18.46 KB, patch)
2015-07-31 10:15 UTC, Carlos Garcia Campos
committed Details | Review

Description Emanuele Aina 2015-06-23 15:15:15 UTC
The contents of the overview.html file are used as a printf-style
format string, which means that '%' are reserved characters that should
be escaped as '%%' to appear in the output.

Unfortunately the sizes expressed as percentages in the embedded CSS
have unescaped '%' characters, leading the printf parser to try to read
extra arguments that aren't really there.

This doesn't always result in segfaults since '% 5e' makes the parser look
for a double parameter with 5 digit precision and a space if the number
is not negative: given that most calling convenctions put floating
points parameters in their own specific registers this doesn't mess with
the ordering of the real non-floating parameter and results in a random
floating point value being read from a register and outputted in the
middle of a CSS rule.

This can be confirmed by looking with the inspector at the spurious
floating value being printed in the middle of the CSS rule.

The other bare '%' is followed instead by a ';' which is not a valid
conversion type and gets outputted literally by printf.

I've added some noisy comments in my patch to grab the attention of future
developers as it's easy to overlook the issue as it's very subtle and it may
cause some hard-to-reproduce crashes as in my case.
Comment 1 Emanuele Aina 2015-06-23 15:15:18 UTC
Created attachment 305921 [details] [review]
overview: Escape bare '%' used in a printf-style template

The contents of the overview.html file are used as a printf-style
format string, which means that '%' are reserved characters that should
be escaped as '%%' to appear in the output.

Unfortunately the sizes expressed as percentages in the embedded CSS
have unescaped '%' characters, leading the printf parser to try to read
extra arguments that aren't really there.

This didn't always result in segfaults since '% 5e' made the parser look
for a double parameter with 5 digit precision and a space if the number
is not negative: given that most calling convenctions put floating
points parameters in their own specific registers this didn't mess with
the ordering of the real non-floating parameter and resulted in a random
floating point value being read from a register and outputted in the
middle of a CSS rule.

This can be confirmed by looking with the inspector at the spurious
floating value being printed in the middle of the CSS rule.

The other bare '%' was followed instead by a ';' which is not a valid
conversion type and was outputted literally by printf.

The noisy comments are there to grab the attention as it's easy to
overlook the issue again when someone will edit the file in the future.
Comment 2 Claudio Saavedra 2015-06-23 15:35:16 UTC
The fact that it's easy to overlook this makes me think that we shouldn't be doing it this way in the first place.
Comment 3 Emanuele Aina 2015-06-23 15:44:38 UTC
Yep, having the whole file to be a printf-style template can be surprising, and there's a good chance of colliding given how often '%' is used in CSS.

One option could be to split the CSS out, it would be one more resource to load but I don't think it will cause a noticeable slowdown.

Otherwise we could either edit the DOM from the C code or inject some JS data hand have some JavaScript code embedded in the page which picks the data up and edits the page contents accordingly.
Comment 4 Carlos Garcia Campos 2015-07-31 10:15:39 UTC
Created attachment 308525 [details] [review]
overview: Move the overview CSS to about.css and generate the HTML from the code
Comment 5 Ole Laursen 2015-07-31 12:01:05 UTC
*** Bug 737994 has been marked as a duplicate of this bug. ***
Comment 6 Ole Laursen 2015-07-31 12:04:05 UTC
It would be nice if you could get a patch out in a bugfix point release. While my Epiphany seldomly crashes from this bug these days, I never see the speed dial, only garbage characters.
Comment 7 Michael Catanzaro 2015-07-31 13:09:37 UTC
Patch looks good, for gnome-3-16 as well as master.
Comment 8 Carlos Garcia Campos 2015-08-03 08:54:58 UTC
Comment on attachment 308525 [details] [review]
overview: Move the overview CSS to about.css and generate the HTML from the code

Pushed to master and gnome-3-16 branch.