Skip to content

Commit b6daa0b

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 b6daa0b

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
@@ -553,6 +553,11 @@ ecma_builtin_typedarray_prototype_filter (ecma_value_t this_arg, /**< this argum
553553
ecma_object_t *func_object_p = ecma_get_object_from_value (cb_func_val);
554554
ecma_value_t ret_value = ECMA_VALUE_EMPTY;
555555

556+
if (len == 0)
557+
{
558+
return ret_value;
559+
}
560+
556561
JMEM_DEFINE_LOCAL_ARRAY (pass_value_list_p, len * element_size, lit_utf8_byte_t);
557562

558563
lit_utf8_byte_t *pass_value_p = pass_value_list_p;

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)