Closed
Bug 455987
Opened 16 years ago
Closed 16 years ago
integer overflow in nsEscape
Categories
(Core :: XPCOM, defect, P1)
Core
XPCOM
Tracking
()
RESOLVED
FIXED
People
(Reporter: dveditz, Assigned: dveditz)
References
Details
(Keywords: fixed1.8.1.18, fixed1.9.0.4, fixed1.9.1, Whiteboard: [sg:moderate])
Attachments
(2 files, 3 obsolete files)
7.21 KB,
patch
|
samuel.sidler+old
:
approval1.8.1.18+
samuel.sidler+old
:
approval1.9.0.4+
asac
:
approval1.8.0.next+
|
Details | Diff | Splinter Review |
2.75 KB,
patch
|
Details | Diff | Splinter Review |
+++ This bug was initially created as a clone of Bug #445117 +++
> /* XXX Hardcoded max entity len. The +1 is for the trailing null. */
> char *rv = (char *) nsMemory::Alloc(strlen(string) * 6 + 1);
>
> |* 6| overflows at about 683M on 32 bit platform.
The issue Georgi noted in bug 445117 also occurs in xpcom/io/nsEscape.cpp -- the same pattern happens in nsEscapeHTML() and nsEscapeHTML2()
I'm not sure if you can practically stuff 683M into the things that use nsEscapeHTML, maybe if the transport is gzipped.
http://mxr.mozilla.org/mozilla/search?string=nsEscapeHTML
Flags: wanted1.8.1.x+
Flags: blocking1.9.1?
Flags: blocking1.9.0.3?
Flags: blocking1.8.1.18+
Assignee | ||
Updated•16 years ago
|
Whiteboard: [sg:moderate]
Comment 1•16 years ago
|
||
dveditz you mean something different from Bug 367736 ?
Comment 2•16 years ago
|
||
aaa, i see:
http://mxr.mozilla.org/mozilla-central/source/xpcom/io/nsEscape.cpp#292
292 PRUnichar *resultBuffer = (PRUnichar *)nsMemory::Alloc(aSourceBufferLen *
293 6 * sizeof(PRUnichar) + sizeof(PRUnichar('\0')));
Comment 3•16 years ago
|
||
>I'm not sure if you can practically stuff 683M
i suppose receiving it is possible.
more of problems for exploiting this probably are:
1. 683 MB on the wire consumes much more VM so OOM may be hit
2. one must avoid crash. though if one does overlapping copy (the returned ptr is in low address) it may not crash.
Comment 4•16 years ago
|
||
in theory 683MB need not be on the wire - they may be javascript generated probably
Assignee | ||
Comment 5•16 years ago
|
||
Yeah, a document title in places, say, or something fed through the feed sanitizer.
Assignee | ||
Updated•16 years ago
|
Flags: blocking1.9.0.4? → blocking1.9.0.4+
Assignee | ||
Updated•16 years ago
|
Assignee: nobody → dveditz
Assignee | ||
Comment 6•16 years ago
|
||
This code got copied to nsPlacesImportExportService.cpp, apparently because the use of string apis in the nsEscape copy caused problems?
http://bonsai.mozilla.org/cvsblame.cgi?file=mozilla/browser/components/places/src/nsPlacesImportExportService.cpp&rev=1.65#239
Dietrich: what's the story there? Is the situation different now so this code can call the standard escape routine? Simple enough to fix in both places, but if it's no longer necessary getting rid of duplicate code would be nice.
Assignee | ||
Comment 7•16 years ago
|
||
In addition to the patch I cleaned up a bunch of tabs. Will attach a -w patch next to make review easier.
Attachment #344247 -
Flags: superreview?(benjamin)
Attachment #344247 -
Flags: review?(benjamin)
Assignee | ||
Comment 8•16 years ago
|
||
Assignee | ||
Comment 9•16 years ago
|
||
Attachment #344249 -
Flags: review?(dietrich)
Comment 10•16 years ago
|
||
Comment on attachment 344247 [details] [diff] [review]
prevent nsEscapeHTML overflow
>Index: xpcom/io/nsEscape.cpp
>+ char *rv = nsnull;
>+ /* XXX Hardcoded max entity len. The +1 is for the trailing null. */
>+ PRUint32 len = PL_strlen(string);
>+ if (len < (PR_UINT32_MAX / 6)) {
>+ rv = (char *)nsMemory::Alloc( (len * 6) + 1 );
>+ }
>+ char *ptr = rv;
>
>- return(rv);
>+ if(rv)
This would be a lot clearer if you took a shortcut path:
if (len >= PR_UINT32_MAX / 6)
return nsnull;
char *rv = (char*) NS_Alloc((6 * len) + 1);
if (!rv)
return nsnull;
... conversion code
This reduces the overall indent and makes the control flow more apparent.
Also please use NS_Alloc instead of nsMemory::Alloc in all new code.
r=me with those nits addressed
Attachment #344247 -
Flags: superreview?(benjamin)
Attachment #344247 -
Flags: superreview+
Attachment #344247 -
Flags: review?(benjamin)
Attachment #344247 -
Flags: review+
Assignee | ||
Comment 11•16 years ago
|
||
Attachment #344247 -
Attachment is obsolete: true
Attachment #344248 -
Attachment is obsolete: true
Attachment #344249 -
Attachment is obsolete: true
Attachment #344249 -
Flags: review?(dietrich)
Assignee | ||
Comment 12•16 years ago
|
||
Assignee | ||
Updated•16 years ago
|
Attachment #344700 -
Flags: approval1.9.0.4?
Attachment #344700 -
Flags: approval1.8.1.18?
Assignee | ||
Comment 13•16 years ago
|
||
Status: NEW → RESOLVED
Closed: 16 years ago
Resolution: --- → FIXED
Comment 14•16 years ago
|
||
Comment on attachment 344700 [details] [diff] [review]
nits fixed, what was checked in
Approved for 1.8.1.18 and 1.9.0.4. a=ss
Attachment #344700 -
Flags: approval1.9.0.4?
Attachment #344700 -
Flags: approval1.9.0.4+
Attachment #344700 -
Flags: approval1.8.1.18?
Attachment #344700 -
Flags: approval1.8.1.18+
Assignee | ||
Comment 15•16 years ago
|
||
Checked into the 1.8 and 1.9.0 branches
Keywords: fixed1.8.1.18,
fixed1.9.0.4
Comment 16•16 years ago
|
||
Any word on a mechanism to exercise this code as we discussed the other day, Dan?
Updated•16 years ago
|
Flags: blocking1.8.0.15+
Comment 17•16 years ago
|
||
Comment on attachment 344700 [details] [diff] [review]
nits fixed, what was checked in
a=asac for 1.8.0 branch
Attachment #344700 -
Flags: approval1.8.0.15+
Assignee | ||
Updated•16 years ago
|
Group: core-security
Comment 18•16 years ago
|
||
This landed before 1.9.1 branched
You need to log in
before you can comment on or make changes to this bug.
Description
•