Closed
Bug 430193
Opened 17 years ago
Closed 1 year ago
Audit comi18n.cpp for string buffer abuse
Categories
(Thunderbird :: Security, defect)
Tracking
(Not tracked)
RESOLVED
WORKSFORME
People
(Reporter: bugmil.ebirol, Unassigned)
References
Details
(Keywords: sec-audit, Whiteboard: [sg:audit])
intlmime_encode_b, and and intlmime_encode_q functions in comi18n.cpp should be re-factored to prevent buffer overflows.
Flags: wanted-thunderbird3?
Flags: wanted-thunderbird3.0a2?
Reporter | ||
Comment 1•17 years ago
|
||
Thanks to David Bienvenu for pointing this out in #413874
>In comi18n.cpp, we protect overflowing the output buffer everywhere but here,
>right? Those functions are internal to libmime.
>
> if (method == 'B')
> enclen = intlmime_encode_b((const unsigned char *)ibuf,
>strlen(ibuf), o);
> else
> enclen = intlmime_encode_q((const unsigned char *)ibuf,
>strlen(ibuf), o);
Reporter | ||
Updated•17 years ago
|
OS: Mac OS X → All
Comment 2•17 years ago
|
||
It looks like the output buffer was allocated assuming worst-case expansion in apply_rfc2047_encoding() -- at least I think so. Confusing enough it's definitely worth an audit but for now I don't think this is actually exploitable.
Watch out for integer overflows, too. "in+srclen" might wrap around, although in this case that should result in in > end so we'd skip the loop.
Whiteboard: [sg:investigate]
Comment 4•17 years ago
|
||
My comment from bug 432469:
I looked throught the patch in bug 413874 and it seems to me that
buffer overflow is still possible even when using PL_strncpyz().
An example:
http://bonsai.mozilla.org/cvsblame.cgi?file=/mozilla/mailnews/mime/src/comi18n.cpp&rev=1.133&root=/cvsroot&mark=349,352-353#348
'obufsize' is declared as PRInt32.
The buffer size parameter of PL_strncpyz() is declared PRUint32.
Suppose the buffer is near full such that PL_strncpyz() cannot
write the full length of 'encodedword_head'.
We still do "obufsize -= encodedword_headlen" causing 'obufsize'
to become negative. The next PL_strncpyz() to 'o' will be a
buffer overflow.
Briefly looking through the patch, I think all the places that updates
the remaining buffer length needs to use strlen() to find out how much
was actually copied.
Also, I looked at the code for PL_strncpyz():
http://bonsai.mozilla.org/cvsblame.cgi?file=/mozilla/nsprpub/lib/libc/src/strcpy.c&rev=3.8&root=/cvsroot&mark=74-75#69
Silently accepting NULL src/dest hides programming errors.
I'd like a fatal assert there in debug builds.
Blocks: 413874
Comment 5•17 years ago
|
||
Another issue:
http://bonsai.mozilla.org/cvsblame.cgi?file=mozilla/mailnews/mime/src/nsMsgHeaderParser.cpp&rev=1.66&mark=1548-1550,1557-1559#1536
'outlen' needs to be decremented -1 for each embedded NUL too.
Updated•17 years ago
|
Whiteboard: [sg:investigate] → [sg:critical?]
Comment 6•16 years ago
|
||
Updated•16 years ago
|
Assignee: bugmil.ebirol → nobody
Component: General → Security
QA Contact: general → thunderbird
Comment 7•16 years ago
|
||
dmose: this should probably block tb3, cc'ing you in case you aren't looking at the "wanted" flags.
Flags: wanted-thunderbird3.0a2? → blocking-thunderbird3?
Updated•16 years ago
|
Flags: blocking-thunderbird3? → blocking-thunderbird3+
Comment 9•15 years ago
|
||
Mats, can you respond to comment 6? Do we need spin-off bugs filed? What needs to be done to close the books on this bug?
Updated•15 years ago
|
Target Milestone: --- → Thunderbird 3.0rc1
Comment 11•15 years ago
|
||
I believe that since we pre-allocate the buffer to a worst-case size for the expansions, this shouldn't be exploitable, so I'm clearing this from the blocking list. It's still worth leaving this open to really fix the code, though.
Flags: blocking-thunderbird3+
Updated•15 years ago
|
Whiteboard: [sg:critical?] → [sg:audit]
Comment 12•13 years ago
|
||
(In reply to David :Bienvenu from comment #11)
> I believe that since we pre-allocate the buffer to a worst-case size for the
> expansions, this shouldn't be exploitable
If this isn't exploitable can we open this bug up?
Updated•12 years ago
|
Assignee: mozilla → nobody
Target Milestone: Thunderbird 3.0rc1 → ---
Comment 14•1 year ago
|
||
The functions in question do not exist anymore. https://searchfox.org/comm-central/source/mailnews/mime/src/comi18n.cpp
Status: NEW → RESOLVED
Closed: 1 year ago
Resolution: --- → WORKSFORME
You need to log in
before you can comment on or make changes to this bug.
Description
•