GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fs: validate fd on fs.write · Fishrock123/node@f9c681c

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • src
    • node_file.cc
  • test/parallel
    • test-fs-write-no-fd.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎src/node_file.cc‎

Copy file name to clipboardExpand all lines: src/node_file.cc
+3-1Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -779,7 +779,9 @@ static void Open(const FunctionCallbackInfo<Value>& args) {
779779
static void WriteBuffer(const FunctionCallbackInfo<Value>& args) {
780780
Environment* env = Environment::GetCurrent(args);
781781

782-
CHECK(args[0]->IsInt32());
782+
if (!args[0]->IsInt32())
783+
return env->ThrowTypeError("First argument must be file descriptor");
784+
783785
CHECK(Buffer::HasInstance(args[1]));
784786

785787
int fd = args[0]->Int32Value();
Collapse file

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

Copy file name to clipboard
+11Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
const common = require('../common');
2+
const fs = require('fs');
3+
const assert = require('assert');
4+
5+
assert.throws(function() {
6+
fs.write(null, new Buffer(1), 0, 1);
7+
}, /TypeError/);
8+
9+
assert.throws(function() {
10+
fs.write(null, '1', 0, 1);
11+
}, /TypeError/);

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.