Skip to content
Memory corruption Disclosed report CVE-2016-1951

Overflow in prprf/GrowStuff can cause memory-safety bug

q1 Follow

Originally disclosed on Mozilla

  • Fixed in 5 months
  • Paid in 6 months
  • Disclosed after 5 months
Text
GrowStuff (38.0.1\nsprpub\pr\src\io\prprf.c) can cause an overflow if the size of the existing buffer in units of bytes (maxlen) + the size of the string to be appended (len) > 0xffffffff. In this case, the function either allocates a tiny buffer or doesn't even attempt to allocate one large enough, then writes the new string beyond the buffer's end.

1081: static int GrowStuff(SprintfState *ss, const char *sp, PRUint32 len)
1082: {
1083:     ptrdiff_t off;
1084:     char *newbase;
1085:     PRUint32 newlen;
1086: 
1087:     off = ss->cur - ss->base;
1088:     if (off + len >= ss->maxlen) {
1089:        /* Grow the buffer */
1090:        newlen = ss->maxlen + ((len > 32) ? len : 32);
1091:        if (ss->base) {
1092:            newbase = (char*) PR_REALLOC(ss->base, newlen);
1093:        } else {
1094:            newbase = (char*) PR_MALLOC(newlen);
1095:        }
1096:        if (!newbase) {
1097:            /* Ran out of memory */
1098:            return -1;
1099:        }
1100:        ss->base = newbase;
1101:        ss->maxlen = newlen;
1102:        ss->cur = ss->base + off;
1103:     }
1104: 
1105:     /* Copy data */
1106:     while (len) {
1107:        --len;
1108:        *ss->cur++ = *sp++;
...


On 32-bit platforms, line 1088 can overflow. In that case, the code doesn't allocate a new buffer, but instead writes the new data beginning just beyond the end of the existing one. Presumably this can occur only if a caller attempts to write a single very long string, because otherwise the system would run out of memory.

On 64-bit platforms, line 1088 doesn't overflow (because ptrdiff_t isa signed 64-bit int), but line 1090 does. In that case, the code allocates a buffer that is much too small, then writes the new data far beyond its end.

The functions that use GrowStuff (PR_vsmprintf and PR_vsprintf_append in prptr.c) are used in several places, but I don't know whether any of the callers ultimately derive potentially very long strings from untrusted sources.

[BTW, I notice that the new Bugzilla doesn't handle pasting of long lines as gracefully as the old one].

The original report as published on Mozilla's Bugzilla, by q1. Images and videos are our own copies; raw HTML is shown as text. View it on Mozilla's Bugzilla.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

What is known

A medium-severity memory corruption bug in NSPR. Mozilla made it public on 25 November 2015 as CVE-2016-1951.

About Memory corruption

Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

What is Memory corruption?

Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.

More by q1

View all

71 more disclosed reports, best first.

More from Mozilla

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Memory corruption

The lesson behind this report.

Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.