From bbf7e8ed5ee48852a2adb97de3056ef067343500 Mon Sep 17 00:00:00 2001 From: Trent Mick Date: Wed, 20 Jul 2011 22:42:10 -0700 Subject: [PATCH 01/12] http: fix setting ServerResponse.statusCode in writeHead Fixes #1374. --- lib/http.js | 1 + test/simple/test-http-status-code.js | 66 ++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+) create mode 100644 test/simple/test-http-status-code.js diff --git a/lib/http.js b/lib/http.js index e5291fbf9a9..e9e1f486f74 100644 --- a/lib/http.js +++ b/lib/http.js @@ -805,6 +805,7 @@ ServerResponse.prototype.writeHead = function(statusCode) { reasonPhrase = STATUS_CODES[statusCode] || 'unknown'; headerIndex = 1; } + this.statusCode = statusCode; var obj = arguments[headerIndex]; diff --git a/test/simple/test-http-status-code.js b/test/simple/test-http-status-code.js new file mode 100644 index 00000000000..5edd81f959f --- /dev/null +++ b/test/simple/test-http-status-code.js @@ -0,0 +1,66 @@ +// Copyright Joyent, Inc. and other Node contributors. +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to permit +// persons to whom the Software is furnished to do so, subject to the +// following conditions: +// +// The above copyright notice and this permission notice shall be included +// in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN +// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE +// USE OR OTHER DEALINGS IN THE SOFTWARE. + +var common = require('../common'); +var assert = require('assert'); +var http = require('http'); + +// Simple test of Node's HTTP ServerResponse.statusCode +// ServerResponse.prototype.statusCode + +var testsComplete = 0; +var tests = [200, 202, 300, 404, 500]; +var testIdx = 0; + +var s = http.createServer(function(req, res) { + var t = tests[testIdx]; + res.writeHead(t, {'Content-Type': 'text/plain'}); + console.log('--\nserver: statusCode after writeHead: '+res.statusCode); + assert.equal(res.statusCode, t); + res.end('hello world\n'); +}); + +s.listen(common.PORT, nextTest); + + +function nextTest () { + if (testIdx + 1 === tests.length) { + return s.close(); + } + var test = tests[testIdx]; + + http.get({ port: common.PORT }, function(response) { + console.log('client: expected status: ' + test); + console.log('client: statusCode: ' + response.statusCode); + assert.equal(response.statusCode, test); + response.on('end', function() { + testsComplete++; + testIdx += 1; + nextTest(); + }); + }); +} + + +process.on('exit', function() { + assert.equal(4, testsComplete); +}); + From 691497babe6ea1c59d3556acab743479e7a1efb9 Mon Sep 17 00:00:00 2001 From: koichik Date: Fri, 22 Jul 2011 00:20:47 +0900 Subject: [PATCH 02/12] Doc improvements corresponds to #1374 and #1334. --- doc/api/http.markdown | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/doc/api/http.markdown b/doc/api/http.markdown index d789ce7bef8..5838a0b3dbe 100644 --- a/doc/api/http.markdown +++ b/doc/api/http.markdown @@ -42,7 +42,7 @@ per connection (in the case of keep-alive connections). When a new TCP stream is established. `socket` is an object of type `net.Socket`. Usually users will not want to access this event. The - `stream` can also be accessed at `request.connection`. + `socket` can also be accessed at `request.connection`. ### Event: 'close' @@ -294,6 +294,9 @@ Example: response.statusCode = 404; +After response header was sent to the client, this property indicates the +status code which was sent out. + ### response.setHeader(name, value) Sets a single header value for implicit headers. If this header already exists From 78487b6256ebbd8c3c0e16abe18f26c2db23d0a4 Mon Sep 17 00:00:00 2001 From: Bert Belder Date: Fri, 22 Jul 2011 16:28:56 +0200 Subject: [PATCH 03/12] Windows/cygwin: no more GetConsoleTitleW errors on XP --- src/platform_cygwin.cc | 47 +++++++++++++---------------------------- src/platform_win32.cc | 48 +++++++++++++----------------------------- 2 files changed, 30 insertions(+), 65 deletions(-) diff --git a/src/platform_cygwin.cc b/src/platform_cygwin.cc index 93e7d856e20..f8cc0091b64 100644 --- a/src/platform_cygwin.cc +++ b/src/platform_cygwin.cc @@ -64,15 +64,21 @@ char** Platform::SetupArgs(int argc, char *argv[]) { } +// Max title length; the only thing MSDN tells us about the maximum length +// of the console title is that it is smaller than 64K. However in practice +// it is much smaller, and there is no way to figure out what the exact length +// of the title is or can be, at least not on XP. To make it even more +// annoying, GetConsoleTitle failes when the buffer to be read into is bigger +// than the actual maximum length. So we make a conservative guess here; +// just don't put the novel you're writing in the title, unless the plot +// survives truncation. +#define MAX_TITLE_LENGTH 8192 + void Platform::SetProcessTitle(char *title) { // We need to convert _title_ to UTF-16 first, because that's what windows uses internally. // It would be more efficient to use the UTF-16 value that we can obtain from v8, // but it's not accessible from here. - // Max title length; according to the specs it should be 64K but in practice it's a little over 30000, - // but who needs titles that long anyway? - const int MAX_TITLE_LENGTH = 30001; - int length; WCHAR *title_w; @@ -109,60 +115,37 @@ void Platform::SetProcessTitle(char *title) { static inline char* _getProcessTitle() { - WCHAR *title_w; + WCHAR title_w[MAX_TITLE_LENGTH]; char *title; - int length, length_w; + int result, length; - length_w = GetConsoleTitleW((WCHAR*)L"\0", sizeof(WCHAR)); + result = GetConsoleTitleW(title_w, sizeof(title_w) / sizeof(WCHAR)); - // If length is zero, there may be an error or the title may be empty - if (!length_w) { - if (GetLastError()) { - _winapi_perror("GetConsoleTitleW"); - return NULL; - } else { - // The title is empty, so return empty string - process_title = strdup("\0"); - return process_title; - } - } - - // Room for \0 terminator - length_w++; - - title_w = new WCHAR[length_w]; - - if (!GetConsoleTitleW(title_w, length_w * sizeof(WCHAR))) { + if (result == 0) { _winapi_perror("GetConsoleTitleW"); - delete title_w; return NULL; } // Find out what the size of the buffer is that we need - length = WideCharToMultiByte(CP_UTF8, 0, title_w, length_w, NULL, 0, NULL, NULL); + length = WideCharToMultiByte(CP_UTF8, 0, title_w, -1, NULL, 0, NULL, NULL); if (!length) { _winapi_perror("WideCharToMultiByte"); - delete title_w; return NULL; } title = (char *) malloc(length); if (!title) { perror("malloc"); - delete title_w; return NULL; } // Do utf16 -> utf8 conversion here if (!WideCharToMultiByte(CP_UTF8, 0, title_w, -1, title, length, NULL, NULL)) { _winapi_perror("WideCharToMultiByte"); - delete title_w; free(title); return NULL; } - delete title_w; - return title; } diff --git a/src/platform_win32.cc b/src/platform_win32.cc index 4792addafe8..316dd8fe1db 100644 --- a/src/platform_win32.cc +++ b/src/platform_win32.cc @@ -93,15 +93,21 @@ char** Platform::SetupArgs(int argc, char *argv[]) { } +// Max title length; the only thing MSDN tells us about the maximum length +// of the console title is that it is smaller than 64K. However in practice +// it is much smaller, and there is no way to figure out what the exact length +// of the title is or can be, at least not on XP. To make it even more +// annoying, GetConsoleTitle failes when the buffer to be read into is bigger +// than the actual maximum length. So we make a conservative guess here; +// just don't put the novel you're writing in the title, unless the plot +// survives truncation. +#define MAX_TITLE_LENGTH 8192 + void Platform::SetProcessTitle(char *title) { // We need to convert _title_ to UTF-16 first, because that's what windows uses internally. // It would be more efficient to use the UTF-16 value that we can obtain from v8, // but it's not accessible from here. - // Max title length; according to the specs it should be 64K but in practice it's a little over 30000, - // but who needs titles that long anyway? - const int MAX_TITLE_LENGTH = 30001; - int length; WCHAR *title_w; @@ -138,61 +144,37 @@ void Platform::SetProcessTitle(char *title) { static inline char* _getProcessTitle() { - WCHAR *title_w; + WCHAR title_w[MAX_TITLE_LENGTH]; char *title; - int length, length_w; + int result, length; - length_w = GetConsoleTitleW((WCHAR*)L"\0", sizeof(WCHAR)); + result = GetConsoleTitleW(title_w, sizeof(title_w) / sizeof(WCHAR)); - // If length is zero, there may be an error or the title may be empty - if (!length_w) { - if (GetLastError()) { - winapi_perror("GetConsoleTitleW"); - return NULL; - } - else { - // The title is empty, so return empty string - process_title = strdup("\0"); - return process_title; - } - } - - // Room for \0 terminator - length_w++; - - title_w = new WCHAR[length_w]; - - if (!GetConsoleTitleW(title_w, length_w * sizeof(WCHAR))) { + if (result == 0) { winapi_perror("GetConsoleTitleW"); - delete title_w; return NULL; } // Find out what the size of the buffer is that we need - length = WideCharToMultiByte(CP_UTF8, 0, title_w, length_w, NULL, 0, NULL, NULL); + length = WideCharToMultiByte(CP_UTF8, 0, title_w, -1, NULL, 0, NULL, NULL); if (!length) { winapi_perror("WideCharToMultiByte"); - delete title_w; return NULL; } title = (char *) malloc(length); if (!title) { perror("malloc"); - delete title_w; return NULL; } // Do utf16 -> utf8 conversion here if (!WideCharToMultiByte(CP_UTF8, 0, title_w, -1, title, length, NULL, NULL)) { winapi_perror("WideCharToMultiByte"); - delete title_w; free(title); return NULL; } - delete title_w; - return title; } From b8e9bf0993ebf59d995bdea7d0d44fb8643b783d Mon Sep 17 00:00:00 2001 From: Vicente Jimenez Aguilar Date: Thu, 4 Nov 2010 18:48:35 +0100 Subject: [PATCH 04/12] Typos in ChangeLog file. Fixes #968. --- ChangeLog | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/ChangeLog b/ChangeLog index 37102d7c554..c46dd61f9e3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -128,10 +128,10 @@ * http response.readable should be false after 'end' #867 (Abe Fettig) -* Implemenet os.cpus() and os.uptime() on Solaris (Scott McWhirter) +* Implement os.cpus() and os.uptime() on Solaris (Scott McWhirter) * fs.ReadStream: Allow omission of end option for range reads #801 - (Felix Geisendörfer) + (Felix Geisendörfer) * Buffer.write() with UCS-2 should not be write partial char #916 (koichik) @@ -217,11 +217,11 @@ * Pragma HTTP header comma separation * In addition to 'aborted' emit 'close' from incoming requests - (Felix Geisendörfer) + (Felix Geisendörfer) * Fix memleak in vm.runInNewContext -* Do not cache modules that throw exceptions (Felix Geisendörfer) +* Do not cache modules that throw exceptions (Felix Geisendörfer) * Build system changes for libnode (Aria Stewart) @@ -239,7 +239,7 @@ * URL parse more safely (isaacs) -* Expose errno with a string for dns/cares (Felix Geisendörfer) +* Expose errno with a string for dns/cares (Felix Geisendörfer) * Fix tty.setWindowSize @@ -263,7 +263,7 @@ * Improve V8 support for Cygwin (Bert Belder) -* Fix fs.open param parsing. (Felix Geisendörfer) +* Fix fs.open param parsing. (Felix Geisendörfer) * Fixed null signal. @@ -394,12 +394,12 @@ * Allow third party hooks before main module load. (See 496be457b6a2bc5b01ec13644b9c9783976159b2) -* Don't stat() on cached modules. (Felix Geisendörfer) +* Don't stat() on cached modules. (Felix Geisendörfer) 2011.01.08, Version 0.3.4 (unstable) -* Primordal mingw build (Bert Belder) +* Primordial mingw build (Bert Belder) * HTTPS server @@ -429,7 +429,7 @@ functions for OSX, Linux, and Cygwin. (Brian White) * Fix REPL syntax error bug (GH-543), improve how REPL commands are - evaulated. + evaluated. * Use process.stdin instead of process.openStdin(). @@ -470,7 +470,7 @@ 2010.11.16, Version 0.3.1 (unstable), ce9a54aa1fbf709dd30316af8a2f14d83150e947 -* TLS improvments (Paul Querna) +* TLS improvements (Paul Querna) - Centralize error handling in SecureStream - Add SecurePair for handling of a ssl/tls stream. @@ -532,9 +532,9 @@ 2010.10.23, Version 0.3.0 (unstable) 1582cfebd6719b2d2373547994b3dca5c8c569c0 -* Bugfix: Do not spin on aceept() with EMFILE +* Bugfix: Do not spin on accept() with EMFILE -* Improvments to readline.js (Trent Mick, Johan Euphrosine, Brian White) +* Improvements to readline.js (Trent Mick, Johan Euphrosine, Brian White) * Safe constructors (missing 'new' doesn't segfault) @@ -570,7 +570,7 @@ * Commas last in sys.inspect -* Constatnts moved from process object to require('constants') +* Constants moved from process object to require('constants') * Fix parsing of linux memory (Vitali Lovich) From e357acc55b8126e1b8b78edcf4ac09dfa3217146 Mon Sep 17 00:00:00 2001 From: SAWADA Tadashi Date: Sun, 19 Jun 2011 16:54:34 +0900 Subject: [PATCH 05/12] Fix crypto encryption/decryption with Base64. Fixes #738. Fixes #1205. --- src/node_crypto.cc | 13 +++++++++++++ test/simple/test-crypto.js | 19 +++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/src/node_crypto.cc b/src/node_crypto.cc index 6f35a571d8a..5b1bd34eed6 100644 --- a/src/node_crypto.cc +++ b/src/node_crypto.cc @@ -1673,6 +1673,19 @@ class Cipher : public ObjectWrap { outString = Encode(out_hexdigest, out_hex_len, BINARY); delete [] out_hexdigest; } else if (strcasecmp(*encoding, "base64") == 0) { + // Check to see if we need to add in previous base64 overhang + if (cipher->incomplete_base64!=NULL){ + unsigned char* complete_base64 = new unsigned char[out_len+cipher->incomplete_base64_len+1]; + memcpy(complete_base64, cipher->incomplete_base64, cipher->incomplete_base64_len); + memcpy(&complete_base64[cipher->incomplete_base64_len], out_value, out_len); + delete [] out_value; + + delete [] cipher->incomplete_base64; + cipher->incomplete_base64=NULL; + + out_value=complete_base64; + out_len += cipher->incomplete_base64_len; + } base64(out_value, out_len, &out_hexdigest, &out_hex_len); outString = Encode(out_hexdigest, out_hex_len, BINARY); delete [] out_hexdigest; diff --git a/test/simple/test-crypto.js b/test/simple/test-crypto.js index df5bd3719a7..01054828f66 100644 --- a/test/simple/test-crypto.js +++ b/test/simple/test-crypto.js @@ -128,6 +128,25 @@ txt += decipher.final('utf8'); assert.equal(txt, plaintext, 'encryption and decryption'); +// encryption and decryption with Base64 +// reported in https://github.com/joyent/node/issues/738 +var plaintext = + '32|RmVZZkFUVmpRRkp0TmJaUm56ZU9qcnJkaXNNWVNpTTU*|iXmckfRWZBGWWELw' + + 'eCBsThSsfUHLeRe0KCsK8ooHgxie0zOINpXxfZi/oNG7uq9JWFVCk70gfzQH8ZUJjAfaFg**'; +var cipher = crypto.createCipher('aes256', '0123456789abcdef'); + +// encrypt plaintext which is in utf8 format +// to a ciphertext which will be in Base64 +var ciph = cipher.update(plaintext, 'utf8', 'base64'); +ciph += cipher.final('base64'); + +var decipher = crypto.createDecipher('aes256', '0123456789abcdef'); +var txt = decipher.update(ciph, 'base64', 'utf8'); +txt += decipher.final('utf8'); + +assert.equal(txt, plaintext, 'encryption and decryption with Base64'); + + // Test encyrption and decryption with explicit key and iv var encryption_key = '0123456789abcd0123456789'; var iv = '12345678'; From bf0802402d52f0ca78885f579b91014a859939d5 Mon Sep 17 00:00:00 2001 From: isaacs Date: Sun, 24 Jul 2011 17:18:33 -0700 Subject: [PATCH 06/12] Note that require.paths is gone in 0.5 Rather than say it "may disappear", let's just be clear that it *has* disappeared, and exactly how long it'll be supported for. --- doc/api/modules.markdown | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/doc/api/modules.markdown b/doc/api/modules.markdown index 59f545e8a1e..080630696ac 100644 --- a/doc/api/modules.markdown +++ b/doc/api/modules.markdown @@ -248,9 +248,10 @@ Loading from the `require.paths` locations is only performed if the module could not be found using the `node_modules` algorithm above. Global modules are lower priority than bundled dependencies. -#### **Note:** Please Avoid Modifying `require.paths` +#### **Note:** Please Avoid Using `require.paths` -`require.paths` may disappear in a future release. +`require.paths` will only be supported through the end of the v0.4 +stable branch. It is removed from node as of v0.5. While it seemed like a good idea at the time, and enabled a lot of useful experimentation, in practice a mutable `require.paths` list is From deb100fb176a40d59d4b961be7aef90ef7361b52 Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Mon, 25 Jul 2011 15:37:21 +0200 Subject: [PATCH 07/12] eio: remove trailing comma from enumerations Fixes compile-time error in strict mode. Fixes #567. --- deps/libeio/eio.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/deps/libeio/eio.h b/deps/libeio/eio.h index 1d597e1fa44..3dd3267678a 100644 --- a/deps/libeio/eio.h +++ b/deps/libeio/eio.h @@ -176,7 +176,7 @@ enum enum { EIO_MCL_CURRENT = 1, - EIO_MCL_FUTURE = 2, + EIO_MCL_FUTURE = 2 }; /* request priorities */ @@ -184,7 +184,7 @@ enum enum { EIO_PRI_MIN = -4, EIO_PRI_MAX = 4, - EIO_PRI_DEFAULT = 0, + EIO_PRI_DEFAULT = 0 }; /* eio request structure */ From d32971a8cbc0ac6ab7a044e25ff400587bc1294f Mon Sep 17 00:00:00 2001 From: koichik Date: Sun, 24 Jul 2011 15:56:23 +0900 Subject: [PATCH 08/12] Doc improvements and change argument name. Fixes #1318. --- doc/api/crypto.markdown | 26 +++++++++++++++++++++----- lib/crypto.js | 8 ++++---- 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/doc/api/crypto.markdown b/doc/api/crypto.markdown index 90d55952931..8a7e5efac32 100644 --- a/doc/api/crypto.markdown +++ b/doc/api/crypto.markdown @@ -76,12 +76,23 @@ Calculates the digest of all of the passed data to the hmac. The `encoding` can be `'hex'`, `'binary'` or `'base64'`. -### crypto.createCipher(algorithm, key) +### crypto.createCipher(algorithm, password) -Creates and returns a cipher object, with the given algorithm and key. +Creates and returns a cipher object, with the given algorithm and password. `algorithm` is dependent on OpenSSL, examples are `'aes192'`, etc. -On recent releases, `openssl list-cipher-algorithms` will display the available cipher algorithms. +On recent releases, `openssl list-cipher-algorithms` will display the +available cipher algorithms. +`password` is used to derive key and IV, which must be `'binary'` encoded +string (See the [Buffers](buffers.html) for more information). + +### crypto.createCipheriv(algorithm, key, iv) + +Creates and returns a cipher object, with the given algorithm, key and iv. + +`algorithm` is the same as the `createCipher()`. `key` is a raw key used in +algorithm. `iv` is an Initialization vector. `key` and `iv` must be `'binary'` +encoded string (See the [Buffers](buffers.html) for more information). ### cipher.update(data, input_encoding='binary', output_encoding='binary') @@ -95,10 +106,15 @@ Returns the enciphered contents, and can be called many times with new data as i Returns any remaining enciphered contents, with `output_encoding` being one of: `'binary'`, `'base64'` or `'hex'`. -### crypto.createDecipher(algorithm, key) +### crypto.createDecipher(algorithm, password) Creates and returns a decipher object, with the given algorithm and key. -This is the mirror of the cipher object above. +This is the mirror of the [createCipher()](#crypto.createCipher) above. + +### crypto.createDecipheriv(algorithm, key, iv) + +Creates and returns a decipher object, with the given algorithm, key and iv. +This is the mirror of the [createCipheriv()](#crypto.createCipheriv) above. ### decipher.update(data, input_encoding='binary', output_encoding='binary') diff --git a/lib/crypto.js b/lib/crypto.js index 25aceaff4c6..c7bb57b7f49 100644 --- a/lib/crypto.js +++ b/lib/crypto.js @@ -110,8 +110,8 @@ exports.createHmac = function(hmac, key) { exports.Cipher = Cipher; -exports.createCipher = function(cipher, key) { - return (new Cipher).init(cipher, key); +exports.createCipher = function(cipher, password) { + return (new Cipher).init(cipher, password); }; @@ -121,8 +121,8 @@ exports.createCipheriv = function(cipher, key, iv) { exports.Decipher = Decipher; -exports.createDecipher = function(cipher, key) { - return (new Decipher).init(cipher, key); +exports.createDecipher = function(cipher, password) { + return (new Decipher).init(cipher, password); }; From 2d65f3c59a33730a2aed47070e4ac32bd2791aa5 Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Tue, 26 Jul 2011 22:05:08 +0200 Subject: [PATCH 09/12] Include "platform.h", not - conflicts with system headers Fixes #1003. --- src/node.cc | 2 +- src/node_buffer.cc | 2 +- src/node_os.cc | 2 +- src/platform_win32.cc | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/node.cc b/src/node.cc index 22c278835a8..527d11ca8e6 100644 --- a/src/node.cc +++ b/src/node.cc @@ -47,7 +47,7 @@ # include /* getgrnam() */ #endif -#include +#include "platform.h" #include #include #include diff --git a/src/node_buffer.cc b/src/node_buffer.cc index 4520548aba2..75573920e06 100644 --- a/src/node_buffer.cc +++ b/src/node_buffer.cc @@ -30,7 +30,7 @@ #include // memcpy #ifdef __MINGW32__ -# include +# include "platform.h" # include // htons, htonl #endif diff --git a/src/node_os.cc b/src/node_os.cc index 1b985276c40..919f2951daf 100644 --- a/src/node_os.cc +++ b/src/node_os.cc @@ -22,7 +22,7 @@ #include #include -#include +#include "platform.h" #include diff --git a/src/platform_win32.cc b/src/platform_win32.cc index 316dd8fe1db..970986c47c4 100644 --- a/src/platform_win32.cc +++ b/src/platform_win32.cc @@ -21,7 +21,7 @@ #include -#include +#include "platform.h" #include From eab8bebcedd2d6ae46a25166964974bca263e616 Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Wed, 27 Jul 2011 13:58:39 -0700 Subject: [PATCH 10/12] Fix memleak in libeio. --- deps/libeio/eio.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/deps/libeio/eio.c b/deps/libeio/eio.c index 1929cf6eead..3057152489f 100644 --- a/deps/libeio/eio.c +++ b/deps/libeio/eio.c @@ -1265,6 +1265,10 @@ eio__scandir (eio_req *req, etp_worker *self) X_LOCK (wrklock); /* the corresponding closedir is in ETP_WORKER_CLEAR */ self->dirp = dirp = opendir (req->ptr1); + + if (req->flags & EIO_FLAG_PTR1_FREE) + free (req->ptr1); + req->flags |= EIO_FLAG_PTR1_FREE | EIO_FLAG_PTR2_FREE; req->ptr1 = dents = flags ? malloc (dentalloc * sizeof (eio_dirent)) : 0; req->ptr2 = names = malloc (namesalloc); From 8b3ba47f88e5f59256818e3173c75c66ff5a82df Mon Sep 17 00:00:00 2001 From: koichik Date: Fri, 29 Jul 2011 23:49:48 +0900 Subject: [PATCH 11/12] Fix http.ClientRequest crashes if end() was called twice Fixes #1417. Fixes #1223. --- lib/http.js | 3 ++ test/simple/test-http-request-end-twice.js | 38 ++++++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 test/simple/test-http-request-end-twice.js diff --git a/lib/http.js b/lib/http.js index e9e1f486f74..d532eddf0cc 100644 --- a/lib/http.js +++ b/lib/http.js @@ -648,6 +648,9 @@ OutgoingMessage.prototype.addTrailers = function(headers) { OutgoingMessage.prototype.end = function(data, encoding) { + if (this.finished) { + return false; + } if (!this._header) { this._implicitHeader(); } diff --git a/test/simple/test-http-request-end-twice.js b/test/simple/test-http-request-end-twice.js new file mode 100644 index 00000000000..5ab529e4809 --- /dev/null +++ b/test/simple/test-http-request-end-twice.js @@ -0,0 +1,38 @@ +// Copyright Joyent, Inc. and other Node contributors. +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to permit +// persons to whom the Software is furnished to do so, subject to the +// following conditions: +// +// The above copyright notice and this permission notice shall be included +// in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN +// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE +// USE OR OTHER DEALINGS IN THE SOFTWARE. + +var common = require('../common'); +var assert = require('assert'); +var http = require('http'); + +var server = http.Server(function(req, res) { + res.writeHead(200, {'Content-Type': 'text/plain'}); + res.end("hello world\n"); +}); +server.listen(common.PORT, function() { + var req = http.get({port: common.PORT}, function(res) { + res.on('end', function() { + assert.ok(!req.end()); + server.close(); + }); + }); +}); + From c72223e2a9aae2d5c20825562657c50a644d8a59 Mon Sep 17 00:00:00 2001 From: koichik Date: Sat, 30 Jul 2011 03:03:58 +0900 Subject: [PATCH 12/12] Doc improvements related to #1391, #1415. --- doc/api/crypto.markdown | 15 +++++++++++++++ doc/api/http.markdown | 4 ++++ 2 files changed, 19 insertions(+) diff --git a/doc/api/crypto.markdown b/doc/api/crypto.markdown index 8a7e5efac32..b979d30e8a0 100644 --- a/doc/api/crypto.markdown +++ b/doc/api/crypto.markdown @@ -57,6 +57,8 @@ This can be called many times with new data as it is streamed. Calculates the digest of all of the passed data to be hashed. The `encoding` can be `'hex'`, `'binary'` or `'base64'`. +Note: `hash` object can not be used after `digest()` method been called. + ### crypto.createHmac(algorithm, key) @@ -75,6 +77,8 @@ This can be called many times with new data as it is streamed. Calculates the digest of all of the passed data to the hmac. The `encoding` can be `'hex'`, `'binary'` or `'base64'`. +Note: `hmac` object can not be used after `digest()` method been called. + ### crypto.createCipher(algorithm, password) @@ -106,6 +110,9 @@ Returns the enciphered contents, and can be called many times with new data as i Returns any remaining enciphered contents, with `output_encoding` being one of: `'binary'`, `'base64'` or `'hex'`. +Note: `cipher` object can not be used after `final()` method been called. + + ### crypto.createDecipher(algorithm, password) Creates and returns a decipher object, with the given algorithm and key. @@ -126,6 +133,8 @@ The `output_decoding` specifies in what format to return the deciphered plaintex Returns any remaining plaintext which is deciphered, with `output_encoding` being one of: `'binary'`, `'ascii'` or `'utf8'`. +Note: `decipher` object can not be used after `final()` method been called. + ### crypto.createSign(algorithm) @@ -145,6 +154,9 @@ Calculates the signature on all the updated data passed through the signer. Returns the signature in `output_format` which can be `'binary'`, `'hex'` or `'base64'`. +Note: `signer` object can not be used after `sign()` method been called. + + ### crypto.createVerify(algorithm) Creates and returns a verification object, with the given algorithm. @@ -164,3 +176,6 @@ signature for the data, in the `signature_format` which can be `'binary'`, `'hex'` or `'base64'`. Returns true or false depending on the validity of the signature for the data and public key. + +Note: `verifier` object can not be used after `verify()` method been called. + diff --git a/doc/api/http.markdown b/doc/api/http.markdown index 5838a0b3dbe..bacfbe2288b 100644 --- a/doc/api/http.markdown +++ b/doc/api/http.markdown @@ -283,6 +283,8 @@ Note: that Content-Length is given in bytes not characters. The above example works because the string `'hello world'` contains only single byte characters. If the body contains higher coded characters then `Buffer.byteLength()` should be used to determine the number of bytes in a given encoding. +And Node does not check whether Content-Length and the length of the body +which has been transmitted are equal or not. ### response.statusCode @@ -589,6 +591,8 @@ event, the entire body will be caught. }); This is a `Writable Stream`. +Note: Node does not check whether Content-Length and the length of the body +which has been transmitted are equal or not. This is an `EventEmitter` with the following events: