Skip to content

Commit

Permalink
fix: options is null on Linux
Browse files Browse the repository at this point in the history
  • Loading branch information
hans00 committed Dec 6, 2019
1 parent 6af830b commit 0b07b45
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 4 deletions.
6 changes: 3 additions & 3 deletions binding.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@
],
'conditions': [
[ 'OS=="linux"', {
'cflags+': [ '-flto', '-O3' ],
'cflags_c+': [ '-flto', '-O3' ],
'cflags_cc+': [ '-flto', '-O3' ],
'cflags+': [ '-flto', '-O3' ],
'cflags_c+': [ '-flto', '-O3' ],
'cflags_cc+': [ '-flto', '-O3' ],
} ],
[ 'OS=="win"', {
'msvs_settings': {
Expand Down
62 changes: 62 additions & 0 deletions fix-bug.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
diff --git a/src/uWebSockets.js/src/AppWrapper.h b/src/uWebSockets.js/src/AppWrapper.h
index 30af474..63b5fe5 100644
--- a/src/uWebSockets.js/src/AppWrapper.h
+++ b/src/uWebSockets.js/src/AppWrapper.h
@@ -3,6 +3,12 @@
#include "Utilities.h"
using namespace v8;

+char *copyString(const char* string) {
+ char *cstr = new char[strlen(string) + 1];
+ std::strcpy(cstr, string);
+ return cstr;
+}
+
/* uWS.App.ws('/pattern', behavior) */
template <typename APP>
void uWS_App_ws(const FunctionCallbackInfo<Value> &args) {
@@ -278,7 +284,7 @@ void uWS_App(const FunctionCallbackInfo<Value> &args) {
}
if (keyFileNameValue.getString().length()) {
keyFileName = keyFileNameValue.getString();
- options.key_file_name = keyFileName.c_str();
+ options.key_file_name = copyString(keyFileName.c_str());
}

/* Cert file name */
@@ -288,7 +294,7 @@ void uWS_App(const FunctionCallbackInfo<Value> &args) {
}
if (certFileNameValue.getString().length()) {
certFileName = certFileNameValue.getString();
- options.cert_file_name = certFileName.c_str();
+ options.cert_file_name = copyString(certFileName.c_str());
}

/* Passphrase */
@@ -298,7 +304,7 @@ void uWS_App(const FunctionCallbackInfo<Value> &args) {
}
if (passphraseValue.getString().length()) {
passphrase = passphraseValue.getString();
- options.passphrase = passphrase.c_str();
+ options.passphrase = copyString(passphrase.c_str());
}

/* DH params file name */
@@ -308,7 +314,7 @@ void uWS_App(const FunctionCallbackInfo<Value> &args) {
}
if (dhParamsFileNameValue.getString().length()) {
dhParamsFileName = dhParamsFileNameValue.getString();
- options.dh_params_file_name = dhParamsFileName.c_str();
+ options.dh_params_file_name = copyString(dhParamsFileName.c_str());
}

/* CA file name */
@@ -318,7 +324,7 @@ void uWS_App(const FunctionCallbackInfo<Value> &args) {
}
if (caFileNameValue.getString().length()) {
caFileName = caFileNameValue.getString();
- options.ca_file_name = caFileName.c_str();
+ options.ca_file_name = copyString(caFileName.c_str());
}

/* ssl_prefer_low_memory_usage */
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"node": ">=10.0.0"
},
"scripts": {
"install": "prebuild-install || node-gyp rebuild",
"install": "prebuild-install || npm run build",
"build": "patch -f -p1 < fix-bug.patch && node-gyp rebuild",
"prebuild-node": "prebuild -t 10.17.0 -t 11.15.0 -t 12.13.0 --strip",
"prebuild-upload": "prebuild --upload-all $GITHUB_TOKEN",
"prebuild-upload:win": "prebuild --upload-all %GITHUB_TOKEN%",
Expand Down

0 comments on commit 0b07b45

Please sign in to comment.