Skip to content

Commit

Permalink
fs: validate fd on fs.write
Browse files Browse the repository at this point in the history
PR-URL: #1553
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
  • Loading branch information
julianduque committed Apr 28, 2015
1 parent 509b59e commit f9c681c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/node_file.cc
Expand Up @@ -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();
Expand Down
11 changes: 11 additions & 0 deletions 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/);

0 comments on commit f9c681c

Please sign in to comment.