Skip to content

Commit 5e19c4a

Browse files
lundibundicodebytere
authored andcommitted
src: fix console debug output on Windows
The FWrite function on Windows assumed that MultiByteToWideChar automatically null-terminates the resulting string, but it will only do so if the size of the source was passed as -1 or null character was explicitly counted in the size. The FWrite uses std::string and its `.size()` method which doesn't count the null character even though the `.data()` method adds it to the resulting string. https://docs.microsoft.com/en-us/windows/win32/api/stringapiset/nf-stringapiset-multibytetowidechar#remarks > MultiByteToWideChar does not null-terminate an output string if the input string length is explicitly specified without a terminating null character. To null-terminate an output string for this function, the application should pass in -1 or explicitly count the terminating null character for the input string. PR-URL: #31580 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Rich Trott <[email protected]>
1 parent 0eb2dbb commit 5e19c4a

File tree

2 files changed

+7
-9
lines changed

2 files changed

+7
-9
lines changed

‎src/debug_utils.cc‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -468,9 +468,7 @@ void FWrite(FILE* file, const std::string& str){
468468
std::vector<wchar_t> wbuf(n);
469469
MultiByteToWideChar(CP_UTF8, 0, str.data(), str.size(), wbuf.data(), n);
470470

471-
// Don't include the final null character in the output
472-
CHECK_GT(n, 0);
473-
WriteConsoleW(handle, wbuf.data(), n - 1, nullptr, nullptr);
471+
WriteConsoleW(handle, wbuf.data(), n, nullptr, nullptr);
474472
return;
475473
#elif defined(__ANDROID__)
476474
if (file == stderr){

‎test/parallel/test-http2-debug.js‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,16 @@ const{stdout, stderr } = child_process.spawnSync(process.execPath, [
1212
path.resolve(__dirname,'test-http2-ping.js')
1313
],{encoding: 'utf8'});
1414

15-
assert(stderr.match(/SettingtheNODE_DEBUGenvironmentvariableto'http2'canexposesensitivedata\(suchaspasswords,tokensandauthenticationheaders\)intheresultinglog\./),
15+
assert(stderr.match(/SettingtheNODE_DEBUGenvironmentvariableto'http2'canexposesensitivedata\(suchaspasswords,tokensandauthenticationheaders\)intheresultinglog\.\r?\n/),
1616
stderr);
17-
assert(stderr.match(/Http2Sessionclient\(\d+\)handlingdataframeforstream\d+/),
17+
assert(stderr.match(/Http2Sessionclient\(\d+\)handlingdataframeforstream\d+\r?\n/),
1818
stderr);
19-
assert(stderr.match(/HttpStream\d+\(\d+\)\[Http2Sessionclient\(\d+\)\]readingstarting/),
19+
assert(stderr.match(/HttpStream\d+\(\d+\)\[Http2Sessionclient\(\d+\)\]readingstarting\r?\n/),
2020
stderr);
21-
assert(stderr.match(/HttpStream\d+\(\d+\)\[Http2Sessionclient\(\d+\)\]closedwithcode0/),
21+
assert(stderr.match(/HttpStream\d+\(\d+\)\[Http2Sessionclient\(\d+\)\]closedwithcode0\r?\n/),
2222
stderr);
23-
assert(stderr.match(/HttpStream\d+\(\d+\)\[Http2Sessionserver\(\d+\)\]closedwithcode0/),
23+
assert(stderr.match(/HttpStream\d+\(\d+\)\[Http2Sessionserver\(\d+\)\]closedwithcode0\r?\n/),
2424
stderr);
25-
assert(stderr.match(/HttpStream\d+\(\d+\)\[Http2Sessionserver\(\d+\)\]tearingdownstream/),
25+
assert(stderr.match(/HttpStream\d+\(\d+\)\[Http2Sessionserver\(\d+\)\]tearingdownstream\r?\n/),
2626
stderr);
2727
assert.strictEqual(stdout.trim(),'');

0 commit comments

Comments
(0)