From: Alex Rousskov Date: Sat, 30 Jul 2016 19:55:15 +0000 (+1200) Subject: Fix crash after rev.14735 X-Git-Tag: SQUID_4_0_13~6 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=9726727bafd28ce5027a18105504e288e9c9b231;p=thirdparty%2Fsquid.git Fix crash after rev.14735 --- diff --git a/src/base/HardFun.h b/src/base/HardFun.h new file mode 100644 index 0000000000..3221fae3ef --- /dev/null +++ b/src/base/HardFun.h @@ -0,0 +1,21 @@ +/* + * Copyright (C) 1996-2016 The Squid Software Foundation and contributors + * + * Squid software is distributed under GPLv2+ license and includes + * contributions from numerous individuals and organizations. + * Please see the COPYING and CONTRIBUTORS files for details. + */ + +#ifndef _SQUID_SRC_BASE_HARDFUN_H +#define _SQUID_SRC_BASE_HARDFUN_H + +/** + * A functor that calls a hard-coded unary function. + */ +template +struct HardFun { + ReturnType operator()(ArgType arg) { fun(arg); } +}; + +#endif /* _SQUID_SRC_BASE_HARDFUN_H */ + diff --git a/src/base/Makefile.am b/src/base/Makefile.am index 7bad2b474b..2e8af8829b 100644 --- a/src/base/Makefile.am +++ b/src/base/Makefile.am @@ -25,6 +25,7 @@ libbase_la_SOURCES = \ CharacterSet.h \ CharacterSet.cc \ EnumIterator.h \ + HardFun.h \ InstanceId.h \ Lock.h \ LookupTable.h \ diff --git a/src/security/cert_generators/file/certificate_db.cc b/src/security/cert_generators/file/certificate_db.cc index 89ec323828..427fe978d2 100644 --- a/src/security/cert_generators/file/certificate_db.cc +++ b/src/security/cert_generators/file/certificate_db.cc @@ -7,6 +7,7 @@ */ #include "squid.h" +#include "base/HardFun.h" #include "security/cert_generators/file/certificate_db.h" #include @@ -287,12 +288,16 @@ bool Ssl::CertificateDb::addCertAndPrivateKey(Security::CertPointer & cert, Ssl: load(); if (!db || !cert || !pkey) return false; + + // Functor to wrap xfree() for std::unique_ptr + typedef HardFun CharDeleter; + Row row; ASN1_INTEGER * ai = X509_get_serialNumber(cert.get()); std::string serial_string; Ssl::BIGNUM_Pointer serial(ASN1_INTEGER_to_BN(ai, NULL)); { - std::unique_ptr> hex_bn(BN_bn2hex(serial.get())); + std::unique_ptr hex_bn(BN_bn2hex(serial.get())); serial_string = std::string(hex_bn.get()); } row.setValue(cnlSerial, serial_string.c_str()); @@ -305,7 +310,7 @@ bool Ssl::CertificateDb::addCertAndPrivateKey(Security::CertPointer & cert, Ssl: } { - std::unique_ptr> subject(X509_NAME_oneline(X509_get_subject_name(cert.get()), nullptr, 0)); + std::unique_ptr subject(X509_NAME_oneline(X509_get_subject_name(cert.get()), nullptr, 0)); Security::CertPointer findCert; Ssl::EVP_PKEY_Pointer findPkey; if (pure_find(useName.empty() ? subject.get() : useName, findCert, findPkey)) { @@ -348,7 +353,7 @@ bool Ssl::CertificateDb::addCertAndPrivateKey(Security::CertPointer & cert, Ssl: if (!useName.empty()) row.setValue(cnlName, useName.c_str()); else { - std::unique_ptr> subject(X509_NAME_oneline(X509_get_subject_name(cert.get()), nullptr, 0)); + std::unique_ptr subject(X509_NAME_oneline(X509_get_subject_name(cert.get()), nullptr, 0)); row.setValue(cnlName, subject.get()); } diff --git a/src/ssl/gadgets.h b/src/ssl/gadgets.h index 15eed635d2..a663f51cf9 100644 --- a/src/ssl/gadgets.h +++ b/src/ssl/gadgets.h @@ -9,6 +9,7 @@ #ifndef SQUID_SSL_GADGETS_H #define SQUID_SSL_GADGETS_H +#include "base/HardFun.h" #include "security/forward.h" #include "ssl/crtd_message.h" @@ -47,33 +48,33 @@ typedef std::unique_ptr X509_STACK_Pointer CtoCpp1(EVP_PKEY_free, EVP_PKEY *) typedef Security::LockingPointer EVP_PKEY_Pointer; -typedef std::unique_ptr> BIGNUM_Pointer; +typedef std::unique_ptr> BIGNUM_Pointer; -typedef std::unique_ptr> BIO_Pointer; +typedef std::unique_ptr> BIO_Pointer; -typedef std::unique_ptr> ASN1_INT_Pointer; +typedef std::unique_ptr> ASN1_INT_Pointer; -typedef std::unique_ptr> ASN1_OCTET_STRING_Pointer; +typedef std::unique_ptr> ASN1_OCTET_STRING_Pointer; -typedef std::unique_ptr> TXT_DB_Pointer; +typedef std::unique_ptr> TXT_DB_Pointer; -typedef std::unique_ptr> X509_NAME_Pointer; +typedef std::unique_ptr> X509_NAME_Pointer; -typedef std::unique_ptr> RSA_Pointer; +typedef std::unique_ptr> RSA_Pointer; -typedef std::unique_ptr> X509_REQ_Pointer; +typedef std::unique_ptr> X509_REQ_Pointer; sk_dtor_wrapper(sk_X509_NAME, STACK_OF(X509_NAME) *, X509_NAME_free); typedef std::unique_ptr X509_NAME_STACK_Pointer; -typedef std::unique_ptr> AUTHORITY_KEYID_Pointer; +typedef std::unique_ptr> AUTHORITY_KEYID_Pointer; sk_dtor_wrapper(sk_GENERAL_NAME, STACK_OF(GENERAL_NAME) *, GENERAL_NAME_free); typedef std::unique_ptr GENERAL_NAME_STACK_Pointer; -typedef std::unique_ptr> GENERAL_NAME_Pointer; +typedef std::unique_ptr> GENERAL_NAME_Pointer; -typedef std::unique_ptr> X509_EXTENSION_Pointer; +typedef std::unique_ptr> X509_EXTENSION_Pointer; /** \ingroup SslCrtdSslAPI