Skip to content

Commit 5060579

Browse files
zherczegakosthekiss
authored andcommitted
Fix double literal free. (#2535)
Fixes #2531. JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg [email protected]
1 parent 3afc4b0 commit 5060579

File tree

3 files changed

+43
-2
lines changed

3 files changed

+43
-2
lines changed

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ matrix:
7575

7676
- env:
7777
- JOBNAME="ASAN Tests"
78-
- OPTS="--quiet --jerry-tests --jerry-test-suite --skip-list=parser-oom.js --buildoptions=--compile-flag=-fsanitize=address,--compile-flag=-m32,--compile-flag=-fno-omit-frame-pointer,--compile-flag=-fno-common,--compile-flag=-O2,--debug,--system-allocator=on,--linker-flag=-fuse-ld=gold"
78+
- OPTS="--quiet --jerry-tests --jerry-test-suite --skip-list=parser-oom.js,parser-oom2.js --buildoptions=--compile-flag=-fsanitize=address,--compile-flag=-m32,--compile-flag=-fno-omit-frame-pointer,--compile-flag=-fno-common,--compile-flag=-O2,--debug,--system-allocator=on,--linker-flag=-fuse-ld=gold"
7979
- ASAN_OPTIONS=detect_stack_use_after_return=1:check_initialization_order=true:strict_init_order=true
8080
- TIMEOUT=600
8181
compiler: gcc-5
@@ -86,7 +86,7 @@ matrix:
8686

8787
- env:
8888
- JOBNAME="UBSAN Tests"
89-
- OPTS="--quiet --jerry-tests --jerry-test-suite --skip-list=parser-oom.js --buildoptions=--compile-flag=-fsanitize=undefined,--compile-flag=-m32,--compile-flag=-fno-omit-frame-pointer,--compile-flag=-fno-common,--debug,--system-allocator=on,--linker-flag=-fuse-ld=gold"
89+
- OPTS="--quiet --jerry-tests --jerry-test-suite --skip-list=parser-oom.js,parser-oom2.js --buildoptions=--compile-flag=-fsanitize=undefined,--compile-flag=-m32,--compile-flag=-fno-omit-frame-pointer,--compile-flag=-fno-common,--debug,--system-allocator=on,--linker-flag=-fuse-ld=gold"
9090
- UBSAN_OPTIONS=print_stacktrace=1
9191
- TIMEOUT=600
9292
compiler: gcc-5

jerry-core/parser/js/js-parser.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,8 @@ parser_compute_indicies (parser_context_t *context_p, /**< context */
204204
if (!(literal_p->status_flags & LEXER_FLAG_SOURCE_PTR))
205205
{
206206
jmem_heap_free_block ((void *) char_p, literal_p->prop.length);
207+
/* This literal should not be freed even if an error is encountered later. */
208+
literal_p->status_flags |= LEXER_FLAG_SOURCE_PTR;
207209
}
208210
}
209211
}

tests/jerry/parser-oom2.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Copyright JS Foundation and other contributors, http://js.foundation
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
/* String which is 32 bytes long. */
16+
var str = "'\\t' +'\\t' +'\\t'+'\\t'+'\\t'+'\\t'+";
17+
18+
for (var i = 0; i < 10; i++) {
19+
str = str + str;
20+
}
21+
22+
str = "(function() { return " + str + "1 })";
23+
24+
/* Eat memory. */
25+
var array = [];
26+
27+
try
28+
{
29+
for (var i = 0; i < 90; i++)
30+
{
31+
array[i] = eval(str);
32+
}
33+
assert (false);
34+
}
35+
catch (err)
36+
{
37+
array = null;
38+
assert (err === null);
39+
}

0 commit comments

Comments
 (0)