Skip to content

Commit 58f2bd4

Browse files
author
Daniel Balla
committed
Fix for null pointer dereference in jmem_heap_free_block
Fixes #2435. JerryScript-DCO-1.0-Signed-off-by: Daniel Balla [email protected]
1 parent 8482fef commit 58f2bd4

File tree

3 files changed

+22
-7
lines changed

3 files changed

+22
-7
lines changed

jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-typedarray-prototype.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -588,6 +588,11 @@ ecma_builtin_typedarray_prototype_filter (ecma_value_t this_arg, /**< this argum
588588

589589
ret_value = ecma_op_create_typedarray_with_type_and_length (obj_p, pass_num);
590590

591+
if (len == 0)
592+
{
593+
return ret_value;
594+
}
595+
591596

592597
if (!ECMA_IS_VALUE_ERROR (ret_value))
593598
{

jerry-core/jmem/jmem.h

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -195,16 +195,11 @@ void jmem_run_free_unused_memory_callbacks (jmem_free_unused_memory_severity_t s
195195
* if it was allocated (i.e. if the array's size was non-zero).
196196
*/
197197
#define JMEM_FINALIZE_LOCAL_ARRAY(var_name) \
198-
if (var_name != NULL) \
198+
if (JERRY_LIKELY (var_name ## ___size != 0)) \
199199
{ \
200-
JERRY_ASSERT (var_name ## ___size != 0); \
201-
\
200+
JERRY_ASSERT (var_name != NULL); \
202201
jmem_heap_free_block (var_name, var_name ## ___size); \
203202
} \
204-
else \
205-
{ \
206-
JERRY_ASSERT (var_name ## ___size == 0); \
207-
} \
208203
}
209204

210205
/**
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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+
(new Int8Array(0)).filter(parseInt)

0 commit comments

Comments
 (0)