summaryrefslogtreecommitdiff
path: root/src/node_crypto_bio.cc
diff options
context:
space:
mode:
authorAdam Langley <agl@google.com>2016-02-05 11:22:49 -0800
committerFedor Indutny <fedor@indutny.com>2016-02-11 16:30:03 -0500
commit773b9016aab9ccaf4eb6acdde07bbeef309e4647 (patch)
treefa1abb530a4059dc5a87cf97fe33e2197d8754d1 /src/node_crypto_bio.cc
parentcd720f816a86afa47afe4369e41a9c6c607a6f70 (diff)
downloadnode-new-773b9016aab9ccaf4eb6acdde07bbeef309e4647.tar.gz
crypto: have fixed NodeBIOs return EOF
Prior to this change, the NodeBIO objects used to wrap fixed data had `num` equal to -1. This caused them to return -1 and set the retry flags when they ran out of data. Since the data is fixed, that's incorrect. Instead they should return zero to signal EOF. This change adds a new, static function, NodeBIO::NewFixed to create a BIO that wraps fixed data and which returns zero when exhausted. The practical impact of this is limited since most (all?) the parsing functions that these BIOs get passed to consider any return value less than one to be EOF and ignore the retry flags anyway. PR-URL: https://github.com/nodejs/node/pull/5105 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Fedor Indutny <fedor@indutny.com>
Diffstat (limited to 'src/node_crypto_bio.cc')
-rw-r--r--src/node_crypto_bio.cc16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/node_crypto_bio.cc b/src/node_crypto_bio.cc
index ca0d0ba97e..d155eaf79a 100644
--- a/src/node_crypto_bio.cc
+++ b/src/node_crypto_bio.cc
@@ -2,6 +2,7 @@
#include "openssl/bio.h"
#include "util.h"
#include "util-inl.h"
+#include <limits.h>
#include <string.h>
namespace node {
@@ -27,6 +28,21 @@ BIO* NodeBIO::New() {
}
+BIO* NodeBIO::NewFixed(const char* data, size_t len) {
+ BIO* bio = New();
+
+ if (bio == nullptr ||
+ len > INT_MAX ||
+ BIO_write(bio, data, len) != static_cast<int>(len) ||
+ BIO_set_mem_eof_return(bio, 0) != 1) {
+ BIO_free(bio);
+ return nullptr;
+ }
+
+ return bio;
+}
+
+
void NodeBIO::AssignEnvironment(Environment* env) {
env_ = env;
}