0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-24 20:29:23 +01:00
nodejs/test/js-native-api/test_string/test_null.js
Gabriel Schulhof d615aeb758 node-api: avoid crashing on passed-in null string
When `napi_create_string_*` receives a null pointer as its second
argument, it must null-check it before passing it into V8, otherwise a
crash will occur.

Signed-off-by: Gabriel Schulhof <gabrielschulhof@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/38923
Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
Reviewed-By: Michael Dawson <midawson@redhat.com>
2021-06-11 09:01:22 -07:00

18 lines
604 B
JavaScript

'use strict';
const common = require('../../common');
const assert = require('assert');
// Test passing NULL to object-related N-APIs.
const { testNull } = require(`./build/${common.buildType}/test_string`);
const expectedResult = {
envIsNull: 'Invalid argument',
stringIsNullNonZeroLength: 'Invalid argument',
stringIsNullZeroLength: 'napi_ok',
resultIsNull: 'Invalid argument',
};
assert.deepStrictEqual(expectedResult, testNull.test_create_latin1());
assert.deepStrictEqual(expectedResult, testNull.test_create_utf8());
assert.deepStrictEqual(expectedResult, testNull.test_create_utf16());