mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
bug 973048 - replace nsNSSCleaner with Scoped types r=rbarnes
This commit is contained in:
parent
e275a96742
commit
0b8a3c3196
@ -36,7 +36,6 @@ UNIFIED_SOURCES += [
|
||||
'nsNSSCertificateFakeTransport.cpp',
|
||||
'nsNSSCertTrust.cpp',
|
||||
'nsNSSCertValidity.cpp',
|
||||
'nsNSSCleaner.cpp',
|
||||
'nsNSSErrors.cpp',
|
||||
'nsNSSIOLayer.cpp',
|
||||
'nsNSSModule.cpp',
|
||||
|
@ -14,7 +14,6 @@
|
||||
#include "pkix/pkixtypes.h"
|
||||
#include "pkix/ScopedPtr.h"
|
||||
#include "nsNSSComponent.h" // for PIPNSS string bundle calls.
|
||||
#include "nsNSSCleaner.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsIMutableArray.h"
|
||||
#include "nsNSSCertValidity.h"
|
||||
@ -59,8 +58,6 @@ using namespace mozilla::psm;
|
||||
extern PRLogModuleInfo* gPIPNSSLog;
|
||||
#endif
|
||||
|
||||
NSSCleanupAutoPtrClass_WithParam(PLArenaPool, PORT_FreeArena, FalseParam, false)
|
||||
|
||||
// This is being stored in an uint32_t that can otherwise
|
||||
// only take values from nsIX509Cert's list of cert types.
|
||||
// As nsIX509Cert is frozen, we choose a value not contained
|
||||
@ -1155,14 +1152,6 @@ nsNSSCertificate::ExportAsCMS(uint32_t chainMode,
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
};
|
||||
|
||||
PLArenaPool* arena = PORT_NewArena(1024);
|
||||
PLArenaPoolCleanerFalseParam arenaCleaner(arena);
|
||||
if (!arena) {
|
||||
PR_LOG(gPIPNSSLog, PR_LOG_DEBUG,
|
||||
("nsNSSCertificate::ExportAsCMS - out of memory\n"));
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
ScopedNSSCMSMessage cmsg(NSS_CMSMessage_Create(nullptr));
|
||||
if (!cmsg) {
|
||||
PR_LOG(gPIPNSSLog, PR_LOG_DEBUG,
|
||||
@ -1231,6 +1220,13 @@ nsNSSCertificate::ExportAsCMS(uint32_t chainMode,
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
ScopedPLArenaPool arena(PORT_NewArena(1024));
|
||||
if (!arena) {
|
||||
PR_LOG(gPIPNSSLog, PR_LOG_DEBUG,
|
||||
("nsNSSCertificate::ExportAsCMS - out of memory\n"));
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
SECItem certP7 = { siBuffer, nullptr, 0 };
|
||||
NSSCMSEncoderContext* ecx = NSS_CMSEncoder_Start(cmsg, nullptr, nullptr,
|
||||
&certP7, arena, nullptr,
|
||||
|
@ -1,25 +0,0 @@
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#include "nsNSSCleaner.h"
|
||||
#include "cert.h"
|
||||
|
||||
CERTVerifyLogContentsCleaner::CERTVerifyLogContentsCleaner(CERTVerifyLog *&cvl)
|
||||
:m_cvl(cvl)
|
||||
{
|
||||
}
|
||||
|
||||
CERTVerifyLogContentsCleaner::~CERTVerifyLogContentsCleaner()
|
||||
{
|
||||
if (!m_cvl)
|
||||
return;
|
||||
|
||||
CERTVerifyLogNode *i_node;
|
||||
for (i_node = m_cvl->head; i_node; i_node = i_node->next)
|
||||
{
|
||||
if (i_node->cert)
|
||||
CERT_DestroyCertificate(i_node->cert);
|
||||
}
|
||||
}
|
||||
|
@ -1,105 +0,0 @@
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#ifndef _INC_NSSCleaner_H
|
||||
#define _INC_NSSCleaner_H
|
||||
|
||||
/*
|
||||
NSSCleanupAutoPtrClass(CERTCertificate, CERT_DestroyCertificate)
|
||||
|
||||
will produce:
|
||||
|
||||
class CERTCertificateCleaner
|
||||
{
|
||||
private:
|
||||
CERTCertificateCleaner(const CERTCertificateCleaner&);
|
||||
CERTCertificateCleaner();
|
||||
void operator=(const CERTCertificateCleaner&);
|
||||
CERTCertificate *&object;
|
||||
public:
|
||||
CERTCertificateCleaner(CERTCertificate *&a_object)
|
||||
:object(a_object) {}
|
||||
~CERTCertificateCleaner() {
|
||||
if (object) {
|
||||
CERT_DestroyCertificate(object);
|
||||
object = nullptr;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
By making default and copy constructor, and assignment operator
|
||||
private, we will make sure nobody will be able to use it.
|
||||
Not defining bodies for them is an additional safeguard.
|
||||
|
||||
This class is not designed to allow being passed around.
|
||||
It's just for automatic cleanup of a local variable.
|
||||
|
||||
|
||||
By storing a reference to the underlying pointer,
|
||||
we will zero out the given pointer variable,
|
||||
making sure it will not be used after it has been freed.
|
||||
|
||||
Even better, in case the underlying pointer variable gets
|
||||
assigned another value, this will be recognized, and
|
||||
the latest value stored in the pointer will be freed.
|
||||
|
||||
|
||||
In order to not require everybody to have all the NSS
|
||||
includes in their implementation files,
|
||||
we don't declare the classes here.
|
||||
|
||||
*/
|
||||
|
||||
#define NSSCleanupAutoPtrClass(nsstype, cleanfunc) \
|
||||
class nsstype##Cleaner \
|
||||
{ \
|
||||
private: \
|
||||
nsstype##Cleaner(const nsstype##Cleaner&); \
|
||||
nsstype##Cleaner(); \
|
||||
void operator=(const nsstype##Cleaner&); \
|
||||
nsstype *&object; \
|
||||
public: \
|
||||
explicit nsstype##Cleaner(nsstype *&a_object) \
|
||||
:object(a_object) {} \
|
||||
~nsstype##Cleaner() { \
|
||||
if (object) { \
|
||||
cleanfunc(object); \
|
||||
object = nullptr; \
|
||||
} \
|
||||
} \
|
||||
void detach() {object=nullptr;} \
|
||||
};
|
||||
|
||||
#define NSSCleanupAutoPtrClass_WithParam(nsstype, cleanfunc, namesuffix, paramvalue) \
|
||||
class nsstype##Cleaner##namesuffix \
|
||||
{ \
|
||||
private: \
|
||||
nsstype##Cleaner##namesuffix(const nsstype##Cleaner##namesuffix &); \
|
||||
nsstype##Cleaner##namesuffix(); \
|
||||
void operator=(const nsstype##Cleaner##namesuffix &); \
|
||||
nsstype *&object; \
|
||||
public: \
|
||||
explicit nsstype##Cleaner##namesuffix(nsstype *&a_object) \
|
||||
:object(a_object) {} \
|
||||
~nsstype##Cleaner##namesuffix() { \
|
||||
if (object) { \
|
||||
cleanfunc(object, paramvalue); \
|
||||
object = nullptr; \
|
||||
} \
|
||||
} \
|
||||
void detach() {object=nullptr;} \
|
||||
};
|
||||
|
||||
#include "certt.h"
|
||||
|
||||
class CERTVerifyLogContentsCleaner
|
||||
{
|
||||
public:
|
||||
explicit CERTVerifyLogContentsCleaner(CERTVerifyLog *&cvl);
|
||||
~CERTVerifyLogContentsCleaner();
|
||||
private:
|
||||
CERTVerifyLog *&m_cvl;
|
||||
};
|
||||
|
||||
#endif
|
@ -24,7 +24,6 @@
|
||||
#include "nsPrintfCString.h"
|
||||
#include "SSLServerCertVerification.h"
|
||||
#include "nsNSSCertHelper.h"
|
||||
#include "nsNSSCleaner.h"
|
||||
|
||||
#ifndef MOZ_NO_EV_CERTS
|
||||
#include "nsIDocShell.h"
|
||||
@ -66,8 +65,6 @@ using namespace mozilla::psm;
|
||||
|
||||
namespace {
|
||||
|
||||
NSSCleanupAutoPtrClass(void, PR_FREEIF)
|
||||
|
||||
void
|
||||
getSiteKey(const nsACString& hostName, uint16_t port,
|
||||
/*out*/ nsCSubstring& key)
|
||||
@ -2164,16 +2161,15 @@ ClientAuthDataRunnable::RunOnTargetThread()
|
||||
NS_ASSERTION(nicknames->numnicknames == NumberOfCerts, "nicknames->numnicknames != NumberOfCerts");
|
||||
|
||||
// Get CN and O of the subject and O of the issuer
|
||||
char* ccn = CERT_GetCommonName(&mServerCert->subject);
|
||||
void* v = ccn;
|
||||
voidCleaner ccnCleaner(v);
|
||||
NS_ConvertUTF8toUTF16 cn(ccn);
|
||||
mozilla::pkix::ScopedPtr<char, PORT_Free_string> ccn(
|
||||
CERT_GetCommonName(&mServerCert->subject));
|
||||
NS_ConvertUTF8toUTF16 cn(ccn.get());
|
||||
|
||||
int32_t port;
|
||||
mSocketInfo->GetPort(&port);
|
||||
|
||||
nsString cn_host_port;
|
||||
if (ccn && strcmp(ccn, hostname) == 0) {
|
||||
if (ccn && strcmp(ccn.get(), hostname) == 0) {
|
||||
cn_host_port.Append(cn);
|
||||
cn_host_port.Append(':');
|
||||
cn_host_port.AppendInt(port);
|
||||
|
Loading…
Reference in New Issue
Block a user