codemod: ASN1_STRING_data -> ASN1_STRING_get0_data
authorJude Taylor <judet@fb.com>
Wed, 12 Apr 2017 17:57:54 +0000 (10:57 -0700)
committerFacebook Github Bot <facebook-github-bot@users.noreply.github.com>
Wed, 12 Apr 2017 18:05:29 +0000 (11:05 -0700)
Reviewed By: anirudhvr

Differential Revision: D4830205

fbshipit-source-id: 55f34c3bddead8a73174c403f76572248c541a10

folly/portability/OpenSSL.cpp
folly/portability/OpenSSL.h
folly/ssl/OpenSSLCertUtils.cpp

index b1052dba00bef6273faad50b68fb8e540602e189..b5a638d28e62d29eb8f12a405b0b04133f79d369 100644 (file)
@@ -83,7 +83,11 @@ const char* SSL_SESSION_get0_hostname(const SSL_SESSION* s) {
   return s->tlsext_hostname;
 }
 
-EVP_MD_CTX* EVP_MD_CTX_new() {
+unsigned char* ASN1_STRING_get0_data(const ASN1_STRING* x) {
+  return ASN1_STRING_data((ASN1_STRING*)x);
+}
+
+EVP_MD_CTX* EVP_MD_CTX_new(void) {
   EVP_MD_CTX* ctx = (EVP_MD_CTX*)OPENSSL_malloc(sizeof(EVP_MD_CTX));
   if (!ctx) {
     throw std::runtime_error("Cannot allocate EVP_MD_CTX");
index d5d0b0f6c579d2de8a47dfd6b216860113b701f6..fdcec290eb12041c58459ebfa8d06818d5df55d5 100644 (file)
@@ -116,6 +116,7 @@ int BIO_meth_set_read(BIO_METHOD* biom, int (*read)(BIO*, char*, int));
 int BIO_meth_set_write(BIO_METHOD* biom, int (*write)(BIO*, const char*, int));
 
 const char* SSL_SESSION_get0_hostname(const SSL_SESSION* s);
+unsigned char* ASN1_STRING_get0_data(const ASN1_STRING* x);
 
 EVP_MD_CTX* EVP_MD_CTX_new();
 void EVP_MD_CTX_free(EVP_MD_CTX* ctx);
index 79800df88be483a389bc37cadfddc60a6065f729..9dbbe46a4bc4e3003750a82ec956d8665fb90095 100644 (file)
@@ -43,7 +43,7 @@ Optional<std::string> OpenSSLCertUtils::getCommonName(X509& x509) {
     return none;
   }
 
-  auto cnData = reinterpret_cast<const char*>(ASN1_STRING_data(cnAsn));
+  auto cnData = reinterpret_cast<const char*>(ASN1_STRING_get0_data(cnAsn));
   auto cnLen = ASN1_STRING_length(cnAsn);
   if (!cnData || cnLen <= 0) {
     return none;
@@ -69,8 +69,8 @@ std::vector<std::string> OpenSSLCertUtils::getSubjectAltNames(X509& x509) {
     if (!genName || genName->type != GEN_DNS) {
       continue;
     }
-    auto nameData =
-        reinterpret_cast<const char*>(ASN1_STRING_data(genName->d.dNSName));
+    auto nameData = reinterpret_cast<const char*>(
+        ASN1_STRING_get0_data(genName->d.dNSName));
     auto nameLen = ASN1_STRING_length(genName->d.dNSName);
     if (!nameData || nameLen <= 0) {
       continue;