This code is unsafe when worker threads are active:
| old = umask(0); |
| umask(static_cast<mode_t>(old)); |
The umask(0) call temporarily changes the process-wide umask and races with fs operations from other threads.
Test case:
'use strict';const{ Worker, isMainThread }=require('worker_threads');const{ statSync, writeFileSync, unlinkSync }=require('fs');functionpummel(){for(leti=0;i<1e4;i++)process.umask();setImmediate(pummel);}if(isMainThread){process.umask(0o22);newWorker(__filename);pummel();}else{constfile='x.txt';for(;;){writeFileSync(file,'ok',{mode: 0o666});consts=statSync(file);s.mode&=0o777;if(0o644!==s.mode)throw'unexpected mode: '+s.mode.toString(8);unlinkSync(file);}}Fails within a few iterations with unexpected mode: 666
process.umask() (no arg) is allowed in workers so this test case works both ways.
This bug is potentially a security issue.
This code is unsafe when worker threads are active:
node/src/node_process_methods.cc
Lines 248 to 249 in 40b559a
The
umask(0)call temporarily changes the process-wide umask and races with fs operations from other threads.Test case:
Fails within a few iterations with
unexpected mode: 666process.umask()(no arg) is allowed in workers so this test case works both ways.This bug is potentially a security issue.