Skip to content

Commit 4d4fa97

Browse files
Daniel Ballahaesik
authored andcommitted
Add an extra check to the stats object (#1919)
Fixes #1917 IoT.js-DCO-1.0-Signed-off-by: Daniel Balla dballa@inf.u-szeged.hu
1 parent a638eda commit 4d4fa97

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

src/modules/iotjs_module_fs.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,11 @@ JS_FUNCTION(fs_read_dir) {
451451
static jerry_value_t stats_is_typeof(jerry_value_t stats, int type) {
452452
jerry_value_t mode = iotjs_jval_get_property(stats, IOTJS_MAGIC_STRING_MODE);
453453

454+
if (!jerry_value_is_number(mode)) {
455+
jerry_release_value(mode);
456+
return JS_CREATE_ERROR(TYPE, "fstat: file mode should be a number");
457+
}
458+
454459
int mode_number = (int)iotjs_jval_as_number(mode);
455460

456461
jerry_release_value(mode);

test/run_fail/test-issue-1917.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/* Copyright 2019-present Samsung Electronics Co., Ltd. and other contributors
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+
16+
var fs = require('fs')
17+
setInterval(fs.fstatSync(1).isFile, 1);

test/testsets.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1111,6 +1111,13 @@
11111111
{
11121112
"name": "test_timers_issue_1353.js",
11131113
"expected-failure": true
1114+
},
1115+
{
1116+
"name": "test-issue-1917.js",
1117+
"expected-failure": true,
1118+
"required-modules": [
1119+
"fs"
1120+
]
11141121
}
11151122
],
11161123
"node/parallel": [

0 commit comments

Comments
 (0)