From 732f8b964152d4bff6033628c9b3904cf0ba554d Mon Sep 17 00:00:00 2001 From: Eivind Uggedal Date: Thu, 4 Jul 2013 18:52:14 +0200 Subject: [PATCH 1/8] doc: add missing word in Transform stream intro --- doc/api/stream.markdown | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/api/stream.markdown b/doc/api/stream.markdown index 3e810930db..a2f5e1fb01 100644 --- a/doc/api/stream.markdown +++ b/doc/api/stream.markdown @@ -1037,8 +1037,8 @@ connected in some way to the input, such as a [zlib][] stream or a There is no requirement that the output be the same size as the input, the same number of chunks, or arrive at the same time. For example, a Hash stream will only ever have a single chunk of output which is -provided when the input is ended. A zlib stream will either produce -much smaller or much larger than its input. +provided when the input is ended. A zlib stream will produce output +that is either much smaller or much larger than its input. Rather than implement the [`_read()`][] and [`_write()`][] methods, Transform classes must implement the `_transform()` method, and may optionally From 31a27ca72d696db94705dafa2e4dba682979ef52 Mon Sep 17 00:00:00 2001 From: Edward Hutchins Date: Wed, 22 May 2013 18:04:36 -0700 Subject: [PATCH 2/8] Added documentation for process.execArgv --- doc/api/process.markdown | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/doc/api/process.markdown b/doc/api/process.markdown index d128620e7f..802f247227 100644 --- a/doc/api/process.markdown +++ b/doc/api/process.markdown @@ -167,6 +167,28 @@ Example: /usr/local/bin/node +## process.execArgv + +This is the set of node-specific command line options from the +executable that started the process. These options do not show up in +`process.argv`, and do not include the node executable, the name of +the script, or any options following the script name. These options +are useful in order to spawn child processes with the same execution +environment as the parent. + +Example: + + $ node --harmony script.js --version + +results in process.execArgv: + + ['--harmony'] + +and process.argv: + + ['/usr/local/bin/node', 'script.js', '--version'] + + ## process.abort() This causes node to emit an abort. This will cause node to exit and From 2385fbbc3ad9f2dbf1b49752667f035f593530ae Mon Sep 17 00:00:00 2001 From: ChrisWren Date: Sun, 11 Aug 2013 12:30:03 -0700 Subject: [PATCH 3/8] doc: fixed syntax error in stream.Transform --- doc/api/stream.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/api/stream.markdown b/doc/api/stream.markdown index a2f5e1fb01..22198c460f 100644 --- a/doc/api/stream.markdown +++ b/doc/api/stream.markdown @@ -1126,7 +1126,7 @@ approach. ```javascript var util = require('util'); -var Transform = require('stream').Transform); +var Transform = require('stream').Transform; util.inherits(SimpleProtocol, Transform); function SimpleProtocol(options) { From 9456cf8fe2b42ccfb2a9561cd50430e623bdc6d2 Mon Sep 17 00:00:00 2001 From: Duan Yao Date: Tue, 4 Dec 2012 18:12:10 +0800 Subject: [PATCH 4/8] doc: Add callback parameter to dgram socket.bind() Also, describe more details of bind(). --- doc/api/dgram.markdown | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/doc/api/dgram.markdown b/doc/api/dgram.markdown index bb102b9484..5f8a0a8ccc 100644 --- a/doc/api/dgram.markdown +++ b/doc/api/dgram.markdown @@ -127,13 +127,21 @@ informing the source that the data did not reach its intended recipient). * `port` Integer * `address` String, Optional -* `callback` Function, Optional +* `callback` Function with no parameters, Optional. Callback when + binding is done. -For UDP sockets, listen for datagrams on a named `port` and optional `address`. -If `address` is not specified, the OS will try to listen on all addresses. +For UDP sockets, listen for datagrams on a named `port` and optional +`address`. If `address` is not specified, the OS will try to listen on +all addresses. After binding is done, an "listening" event is emitted +and the `callback`(if specified) is called. Specifying both an +"listening" event listener and `callback` is not harmful but not very +useful. -The `callback` argument, if provided, is added as a one-shot `'listening'` -event listener. +A bound datagram socket keeps the node process running to receive +datagrams. + +If binding fails, an "error" event is generated. In rare case (e.g. +binding a closed socket), an `Error` may be thrown by this method. Example of a UDP server listening on port 41234: @@ -141,6 +149,11 @@ Example of a UDP server listening on port 41234: var server = dgram.createSocket("udp4"); + server.on("error", function (err) { + console.log("server error:\n" + err.stack); + server.close(); + }); + server.on("message", function (msg, rinfo) { console.log("server got: " + msg + " from " + rinfo.address + ":" + rinfo.port); From 26a8c0c6b8f9ed51a574a0bbaebe95e8f36706d5 Mon Sep 17 00:00:00 2001 From: isaacs Date: Mon, 19 Aug 2013 17:55:58 -0700 Subject: [PATCH 5/8] doc: Minor typos in dgram doc a/an usage. Thanks @KenanSulayman --- doc/api/dgram.markdown | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/api/dgram.markdown b/doc/api/dgram.markdown index 5f8a0a8ccc..6e8f73fe49 100644 --- a/doc/api/dgram.markdown +++ b/doc/api/dgram.markdown @@ -132,8 +132,8 @@ informing the source that the data did not reach its intended recipient). For UDP sockets, listen for datagrams on a named `port` and optional `address`. If `address` is not specified, the OS will try to listen on -all addresses. After binding is done, an "listening" event is emitted -and the `callback`(if specified) is called. Specifying both an +all addresses. After binding is done, a "listening" event is emitted +and the `callback`(if specified) is called. Specifying both a "listening" event listener and `callback` is not harmful but not very useful. From e04c8a8ee400b6453cdb1133e7dd6791b69c0834 Mon Sep 17 00:00:00 2001 From: Gil Pedersen Date: Tue, 20 Aug 2013 15:53:54 +0200 Subject: [PATCH 6/8] fs: use correct self reference for autoClose test --- lib/fs.js | 2 +- test/simple/test-fs-read-stream.js | 26 ++++++++++++++++---------- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/lib/fs.js b/lib/fs.js index 00496d9ca9..222efd1af6 100644 --- a/lib/fs.js +++ b/lib/fs.js @@ -1494,7 +1494,7 @@ ReadStream.prototype.open = function() { var self = this; fs.open(this.path, this.flags, this.mode, function(er, fd) { if (er) { - if (this.autoClose) { + if (self.autoClose) { self.destroy(); } self.emit('error', er); diff --git a/test/simple/test-fs-read-stream.js b/test/simple/test-fs-read-stream.js index 9452f95c6d..4d1eebb2c1 100644 --- a/test/simple/test-fs-read-stream.js +++ b/test/simple/test-fs-read-stream.js @@ -171,10 +171,6 @@ function file7Next(){ }); file7.on('end', function(err) { assert.equal(file7.data, 'xyz\n'); - process.nextTick(function() { - assert(file7.closed); - assert(file7.destroyed); - }); }); } @@ -182,10 +178,20 @@ function file7Next(){ var file8 = fs.createReadStream(null, {fd: 13337, autoClose: false }); file8.on('data', function() {}); file8.on('error', common.mustCall(function() {})); -file8.on('end', function() { - process.nextTick(function() { - assert(!file8.closed); - assert(!file8.destroyed); - assert(file8.fd); - }); + +// Make sure stream is destroyed when file does not exist. +var file9 = fs.createReadStream('/path/to/file/that/does/not/exist'); +file9.on('data', function() {}); +file9.on('error', common.mustCall(function() {})); + +process.on('exit', function() { + assert(file7.closed); + assert(file7.destroyed); + + assert(!file8.closed); + assert(!file8.destroyed); + assert(file8.fd); + + assert(!file9.closed); + assert(file9.destroyed); }); From af6a2339c56e89d7cf999cd64a69842a531c05dc Mon Sep 17 00:00:00 2001 From: Fedor Indutny Date: Wed, 21 Aug 2013 15:58:33 +0400 Subject: [PATCH 7/8] tls: fix assertion when ssl is destroyed at read `maybeInitFinished()` can emit the 'secure' event which in turn destroys the connection in case of authentication failure and sets `this.pair.ssl` to `null`. If such condition appeared after non-empty read - loop will continue and `clearOut` will be called on `null` object instead of `crypto::Connection` instance. Resulting in the following assertion: ERROR: Error: Hostname/IP doesn't match certificate's altnames Assertion failed: handle->InternalFieldCount() > 0 fix #5756 --- lib/tls.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/tls.js b/lib/tls.js index 0907b290f3..ea3d2e4310 100644 --- a/lib/tls.js +++ b/lib/tls.js @@ -461,7 +461,14 @@ CryptoStream.prototype._read = function read(size) { // Get NPN and Server name when ready this.pair.maybeInitFinished(); - } while (read > 0 && !this._buffer.isFull && bytesRead < size); + + // `maybeInitFinished()` can emit the 'secure' event which + // in turn destroys the connection in case of authentication + // failure and sets `this.pair.ssl` to `null`. + } while (read > 0 && + !this._buffer.isFull && + bytesRead < size && + this.pair.ssl !== null); // Create new buffer if previous was filled up var pool = this._buffer.pool; From 8d42c6344b7a96dbb42dd65e01617028d05d413a Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Wed, 21 Aug 2013 03:33:20 +0200 Subject: [PATCH 8/8] deps: upgrade http_parser to 303c4e4 Upgrade to joyent/http-parser@303c4e4. Changes: * Do not accept PUN/GEM methods as PUT/GET. * Further request method check strengthening. --- deps/http_parser/http_parser.c | 21 +++++++++++++++++++-- deps/http_parser/test.c | 18 +++++++++++------- 2 files changed, 30 insertions(+), 9 deletions(-) diff --git a/deps/http_parser/http_parser.c b/deps/http_parser/http_parser.c index 5e0a950a6f..55d7716228 100644 --- a/deps/http_parser/http_parser.c +++ b/deps/http_parser/http_parser.c @@ -936,6 +936,7 @@ size_t http_parser_execute (http_parser *parser, } else if (parser->index == 2 && ch == 'P') { parser->method = HTTP_COPY; } else { + SET_ERRNO(HPE_INVALID_METHOD); goto error; } } else if (parser->method == HTTP_MKCOL) { @@ -948,12 +949,14 @@ size_t http_parser_execute (http_parser *parser, } else if (parser->index == 2 && ch == 'A') { parser->method = HTTP_MKACTIVITY; } else { + SET_ERRNO(HPE_INVALID_METHOD); goto error; } } else if (parser->method == HTTP_SUBSCRIBE) { if (parser->index == 1 && ch == 'E') { parser->method = HTTP_SEARCH; } else { + SET_ERRNO(HPE_INVALID_METHOD); goto error; } } else if (parser->index == 1 && parser->method == HTTP_POST) { @@ -964,13 +967,27 @@ size_t http_parser_execute (http_parser *parser, } else if (ch == 'A') { parser->method = HTTP_PATCH; } else { + SET_ERRNO(HPE_INVALID_METHOD); goto error; } } else if (parser->index == 2) { if (parser->method == HTTP_PUT) { - if (ch == 'R') parser->method = HTTP_PURGE; + if (ch == 'R') { + parser->method = HTTP_PURGE; + } else { + SET_ERRNO(HPE_INVALID_METHOD); + goto error; + } } else if (parser->method == HTTP_UNLOCK) { - if (ch == 'S') parser->method = HTTP_UNSUBSCRIBE; + if (ch == 'S') { + parser->method = HTTP_UNSUBSCRIBE; + } else { + SET_ERRNO(HPE_INVALID_METHOD); + goto error; + } + } else { + SET_ERRNO(HPE_INVALID_METHOD); + goto error; } } else if (parser->index == 4 && parser->method == HTTP_PROPFIND && ch == 'P') { parser->method = HTTP_PROPPATCH; diff --git a/deps/http_parser/test.c b/deps/http_parser/test.c index 81e0c3bddf..46d817bb38 100644 --- a/deps/http_parser/test.c +++ b/deps/http_parser/test.c @@ -3117,14 +3117,8 @@ main (void) /// REQUESTS - test_simple("hello world", HPE_INVALID_METHOD); test_simple("GET / HTP/1.1\r\n\r\n", HPE_INVALID_VERSION); - - test_simple("ASDF / HTTP/1.1\r\n\r\n", HPE_INVALID_METHOD); - test_simple("PROPPATCHA / HTTP/1.1\r\n\r\n", HPE_INVALID_METHOD); - test_simple("GETA / HTTP/1.1\r\n\r\n", HPE_INVALID_METHOD); - // Well-formed but incomplete test_simple("GET / HTTP/1.1\r\n" "Content-Type: text/plain\r\n" @@ -3167,13 +3161,23 @@ main (void) } static const char *bad_methods[] = { + "ASDF", "C******", + "COLA", + "GEM", + "GETA", "M****", + "MKCOLA", + "PROPPATCHA", + "PUN", + "PX", + "SA", + "hello world", 0 }; for (this_method = bad_methods; *this_method; this_method++) { char buf[200]; sprintf(buf, "%s / HTTP/1.1\r\n\r\n", *this_method); - test_simple(buf, HPE_UNKNOWN); + test_simple(buf, HPE_INVALID_METHOD); } const char *dumbfuck2 =