Bug 669434 - Fix obscure bugs in CompileFileHelper. r=brendan.
authorNicholas Nethercote <nnethercote@mozilla.com>
Thu, 14 Jul 2011 19:40:23 -0700
changeset 72858 a8224422f7c6f48be324d7ce2e0603a00519edc5
parent 72857 e4a42cc36dc733793a6b6c2632b5e65c0528805f
child 72859 6d85a68e820e3cab4f63c0425b9ccc812532d2ce
push id20776
push usereakhgari@mozilla.com
push dateFri, 15 Jul 2011 12:13:35 +0000
treeherdermozilla-central@9349ae9094f6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbrendan
bugs669434
milestone8.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 669434 - Fix obscure bugs in CompileFileHelper. r=brendan. H:Bug 669434 - Fix obscure bugs in CompileFileHelper. r=brendan. ubranch 'default'
js/src/jsapi.cpp
--- a/js/src/jsapi.cpp
+++ b/js/src/jsapi.cpp
@@ -1518,16 +1518,17 @@ JS_InitStandardClasses(JSContext *cx, JS
 
     /*
      * JS_SetGlobalObject might or might not change cx's compartment, so call
      * it before assertSameCompartment. (The API contract is that *after* this,
      * cx and obj must be in the same compartment.)
      */
     if (!cx->globalObject)
         JS_SetGlobalObject(cx, obj);
+
     assertSameCompartment(cx, obj);
 
     return obj->asGlobal()->initStandardClasses(cx);
 }
 
 #define CLASP(name)                 (&js_##name##Class)
 #define TYPED_ARRAY_CLASP(type)     (&TypedArray::fastClasses[TypedArray::type])
 #define EAGER_ATOM(name)            ATOM_OFFSET(name), NULL
@@ -4590,18 +4591,19 @@ CompileFileHelper(JSContext *cx, JSObjec
 
     jschar *buf = NULL;
     size_t len = st.st_size;
     size_t i = 0;
     JSScript *script;
 
     /* Read in the whole file, then compile it. */
     if (fp == stdin) {
-        JS_ASSERT(len == 0);
-        len = 8;  /* start with a small buffer, expand as necessary */
+        if (len == 0)
+            len = 8;  /* start with a small buffer, expand as necessary */
+
         int c;
         bool hitEOF = false;
         while (!hitEOF) {
             len *= 2;
             jschar* tmpbuf = (jschar *) cx->realloc_(buf, len * sizeof(jschar));
             if (!tmpbuf) {
                 cx->free_(buf);
                 return NULL;
@@ -4618,17 +4620,19 @@ CompileFileHelper(JSContext *cx, JSObjec
             }
         }
     } else {
         buf = (jschar *) cx->malloc_(len * sizeof(jschar));
         if (!buf)
             return NULL;
 
         int c;
-        while ((c = fast_getc(fp)) != EOF)
+        // The |i < len| is necessary for files that lie about their length,
+        // e.g. /dev/zero and /dev/random.  See bug 669434.
+        while (i < len && (c = fast_getc(fp)) != EOF)
             buf[i++] = (jschar) (unsigned char) c;
     }
 
     JS_ASSERT(i <= len);
     len = i;
     uint32 tcflags = JS_OPTIONS_TO_TCFLAGS(cx) | TCF_NEED_MUTABLE_SCRIPT;
     script = Compiler::compileScript(cx, obj, NULL, principals, tcflags, buf, len, filename, 1,
                                      cx->findVersion());