Browse Source

fs: validate fd on fs.write

PR-URL: #1553
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
v2.0.2
Julian Duque 10 years ago
parent
commit
f9c681cf62
  1. 4
      src/node_file.cc
  2. 11
      test/parallel/test-fs-write-no-fd.js

4
src/node_file.cc

@ -779,7 +779,9 @@ static void Open(const FunctionCallbackInfo<Value>& args) {
static void WriteBuffer(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args);
CHECK(args[0]->IsInt32());
if (!args[0]->IsInt32())
return env->ThrowTypeError("First argument must be file descriptor");
CHECK(Buffer::HasInstance(args[1]));
int fd = args[0]->Int32Value();

11
test/parallel/test-fs-write-no-fd.js

@ -0,0 +1,11 @@
const common = require('../common');
const fs = require('fs');
const assert = require('assert');
assert.throws(function() {
fs.write(null, new Buffer(1), 0, 1);
}, /TypeError/);
assert.throws(function() {
fs.write(null, '1', 0, 1);
}, /TypeError/);
Loading…
Cancel
Save