Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

check for segfaults in SAFE_HEAP

  • Loading branch information...
commit 1896c00715d1cbfd47a295c9564691dcf88d6032 1 parent 953ebf7
@kripken authored
Showing with 37 additions and 2 deletions.
  1. +3 −1 src/preamble.js
  2. +3 −1 src/settings.js
  3. +31 −0 tests/runner.py
View
4 src/preamble.js
@@ -24,6 +24,8 @@ var ACCEPTABLE_SAFE_HEAP_ERRORS = 0;
function SAFE_HEAP_ACCESS(dest, type, store, ignore) {
//if (dest === A_NUMBER) Module.print ([dest, type, store] + ' ' + new Error().stack); // Something like this may be useful, in debugging
+ assert(dest >= STACK_ROOT, 'segmentation fault: null pointer, or below normal memory');
+
#if USE_TYPED_ARRAYS
// When using typed arrays, reads over the top of TOTAL_MEMORY will fail silently, so we must
// correct that by growing TOTAL_MEMORY as needed. Without typed arrays, memory is a normal
@@ -643,7 +645,7 @@ var base = intArrayFromString('(null)'); // So printing %s of NULL gives '(null)
// Also this ensures we leave 0 as an invalid address, 'NULL'
STATICTOP = base.length;
for (var i = 0; i < base.length; i++) {
- {{{ makeSetValue(0, 'i', 'base[i]', 'i8') }}}
+ {{{ makeSetValue(0, 'i', 'base[i]', 'i8', null, null, null, 1) }}}
}
Module['HEAP'] = HEAP;
View
4 src/settings.js
@@ -104,7 +104,9 @@ var CATCH_EXIT_CODE = 0; // If set, causes exit() to throw an exception object w
// terminated with an error message.
// Generated code debugging options
-var SAFE_HEAP = 0; // Check each write to the heap against a list of blocked addresses
+var SAFE_HEAP = 0; // Check each write to the heap, for example, this will give a clear
+ // error on what would be segfaults in a native build (like deferencing
+ // 0). See preamble.js for the actual checks performed.
// If equal to 2, done on a line-by-line basis according to
// SAFE_HEAP_LINES, checking only the specified lines.
// If equal to 3, checking all *but* the specified lines. Note
View
31 tests/runner.py
@@ -2108,6 +2108,37 @@ def test_polymorph(self):
'''
self.do_run(src, '*11,74,32,1012*\n*11*\n*22*')
+ def test_segfault(self):
+ Settings.SAFE_HEAP = 1
+
+ for addr in ['0', '7', 'new D2()']:
+ print addr
+ src = r'''
+ #include <stdio.h>
+
+ struct Classey {
+ virtual void doIt() = 0;
+ };
+
+ struct D1 : Classey {
+ virtual void doIt() { printf("fleefl\n"); }
+ };
+
+ struct D2 : Classey {
+ virtual void doIt() { printf("marfoosh\n"); }
+ };
+
+ int main(int argc, char **argv)
+ {
+ Classey *p = argc == 100 ? new D1() : (Classey*)%s;
+
+ p->doIt();
+
+ return 0;
+ }
+ ''' % addr
+ self.do_run(src, 'segmentation fault' if addr.isdigit() else 'marfoosh')
+
def test_dynamic_cast(self):
if self.emcc_args is None: return self.skip('need libcxxabi')
Please sign in to comment.
Something went wrong with that request. Please try again.