File CVE-2019-15604.patch of Package nodejs6.15383

ported from

commit f940bee3b7da865e28093472dee9ce664f273f6d
Author: Fedor Indutny <fedor@indutny.com>
Date:   Tue Nov 26 12:47:00 2019 -0800

    crypto: fix assertion caused by unsupported ext
    
    `X509V3_EXT_print` can return value different from `1` if the X509
    extension does not support printing to a buffer. Instead of failing with
    an unrecoverable assertion - replace the relevant value in the hashmap
    with a JS null value.
    
    Fixes: https://hackerone.com/reports/746733
    
    Backport-PR-URL: https://github.com/nodejs-private/node-private/pull/193
    PR-URL: https://github.com/nodejs-private/node-private/pull/175
    Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
    Reviewed-By: Beth Griggs <Bethany.Griggs@uk.ibm.com>

Index: node-v6.17.1/src/node_crypto.cc
===================================================================
--- node-v6.17.1.orig/src/node_crypto.cc
+++ node-v6.17.1/src/node_crypto.cc
@@ -1502,9 +1502,11 @@ static Local<Object> X509ToObject(Enviro
     ext = X509_get_ext(cert, index);
     CHECK_NE(ext, nullptr);
 
-    if (!SafeX509ExtPrint(bio, ext)) {
-      rv = X509V3_EXT_print(bio, ext, 0, 0);
-      CHECK_EQ(rv, 1);
+    if (!SafeX509ExtPrint(bio, ext) &&
+        X509V3_EXT_print(bio, ext, 0, 0) != 1) {
+      info->Set(keys[i], Null(env->isolate()));
+      (void) BIO_reset(bio);
+      continue;
     }
 
     BIO_get_mem_ptr(bio, &mem);
Index: node-v6.17.1/test/parallel/test-tls-cert-ext-encoding.js
===================================================================
--- /dev/null
+++ node-v6.17.1/test/parallel/test-tls-cert-ext-encoding.js
@@ -0,0 +1,79 @@
+'use strict';
+const common = require('../common');
+if (!common.hasCrypto)
+  common.skip('missing crypto');
+
+// NOTE: This certificate is hand-generated, hence it is not located in
+// `test/fixtures/keys` to avoid confusion.
+//
+// The key property of this cert is that subjectAltName contains a string with
+// a type `23` which cannot be encoded into string by `X509V3_EXT_print`.
+const pem = `
+-----BEGIN RSA PRIVATE KEY-----
+MIIEowIBAAKCAQEAzrmf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aGGLIF2h5UlVpr0bdBVVUg+uVX3y/Qmu2Qv4CrAO2IPV6JER9Ni
+wl3ktzNjOMAUQG6BCRSqRQIDAQABoxswGTAXBgNVHREEEDAOlwwqLmxvY2FsLmhv
+c3QwDQYJKoZIhvcNAQENBQADggEBAH5ThRLDLwOGuhKsifyiq7k8gbx1FqRegO7H
+SIiIYYB35v5Pk0ZPN8QBJwNQzJEjUMjCpHXNdBxknBXRaA8vkbnryMfJm37gPTwA
+m6r0uEG78WgcEAe8bgf9iKtQGP/iydKXpSSpDgKoHbswIxD5qtzT+o6VNnkRTSfK
+/OGwakluFSoJ/Q9rLpR8lKjA01BhetXMmHbETiY8LSkxOymMldXSzUTD1WdrVn8U
+L3dobxT//R/0GraKXG02mf3gZNlb0MMTvW0pVwVy39YmcPEGh8L0hWh1rpAA/VXC
+f79uOowv3lLTzQ9na5EThA0tp8d837hdYrrIHh5cfTqBDxG0Tu8=
+-----END CERTIFICATE-----
+`;
+
+const tls = require('tls');
+
+const options = {
+  key: pem,
+  cert: pem,
+};
+
+const server = tls.createServer(options, (socket) => {
+  socket.end();
+});
+server.listen(0, common.mustCall(function() {
+  const client = tls.connect({
+    port: this.address().port,
+    rejectUnauthorized: false
+  }, common.mustCall(() => {
+    // This should not crash process:
+    client.getPeerCertificate();
+
+    server.close();
+    client.end();
+  }));
+}));