node-getpass icon indicating copy to clipboard operation
node-getpass copied to clipboard

cleanup() calls fs.closeSync() after the file descriptor has already been closed

Open melloc opened this issue 7 years ago • 0 comments

Because cleanup() calls wtty.end() and rtty.end(), the wfd and rfd file descriptors get closed before the following mod_fs.closeSync() calls. This results in EBADF, since there's no longer a valid file descriptor. For example, I can reproduce this using triton with a locked key:

cody@101901c9-6d66-ea32-fe42-f1fbebd4bf99 ~ % node --version
v0.10.46
cody@101901c9-6d66-ea32-fe42-f1fbebd4bf99 ~ % triton insts
Enter passphrase for id_ecdsa:

fs.js:409
  return binding.close(fd);
                 ^
Error: EBADF, bad file descriptor
    at Object.fs.closeSync (fs.js:409:18)
    at cleanup (/home/cody/.npm-global/lib/node_modules/triton/node_modules/getpass/lib/index.js:95:12)
    at ReadStream.onData (/home/cody/.npm-global/lib/node_modules/triton/node_modules/getpass/lib/index.js:71:6)
    at ReadStream.emit (events.js:95:17)
    at ReadStream.<anonymous> (_stream_readable.js:765:14)
    at ReadStream.emit (events.js:92:17)
    at emitReadable_ (_stream_readable.js:427:10)
    at emitReadable (_stream_readable.js:423:5)
    at readableAddChunk (_stream_readable.js:166:9)
    at ReadStream.Readable.push (_stream_readable.js:128:10)

melloc avatar Oct 17 '17 19:10 melloc