1 From 5c61cdba435096ee6e65cee4dc9a473430643c07 Mon Sep 17 00:00:00 2001
2 From: Elio Maldonado <emaldona@redhat.com>
3 Date: Tue, 12 Apr 2011 09:31:48 -0700
4 Subject: [PATCH] Bug 695011 PEM logging
6 Use NSPR logging facilities for PEM logging to fix a segmenation violation
7 caused when user cannot for write a log file created by root
9 mozilla/security/nss/lib/ckfw/pem/ckpem.h | 7 ++++-
10 mozilla/security/nss/lib/ckfw/pem/util.c | 30 ++++++++++++++++------------
11 2 files changed, 22 insertions(+), 15 deletions(-)
13 diff --git a/mozilla/security/nss/lib/ckfw/pem/ckpem.h b/mozilla/security/nss/lib/ckfw/pem/ckpem.h
14 index 839d40b..720525e 100644
15 --- a/mozilla/security/nss/lib/ckfw/pem/ckpem.h
16 +++ b/mozilla/security/nss/lib/ckfw/pem/ckpem.h
24 @@ -254,8 +257,8 @@ unsigned int pem_PrivateModulusLen(pemLOWKEYPrivateKey *privk);
26 NSSCKMDToken * pem_NewToken(NSSCKFWInstance *fwInstance, CK_RV *pError);
31 void plog(const char *fmt, ...);
35 diff --git a/mozilla/security/nss/lib/ckfw/pem/util.c b/mozilla/security/nss/lib/ckfw/pem/util.c
36 index 853f418..fafb924 100644
37 --- a/mozilla/security/nss/lib/ckfw/pem/util.c
38 +++ b/mozilla/security/nss/lib/ckfw/pem/util.c
56 #define CHUNK_SIZE 512
57 @@ -267,34 +271,34 @@ ReadDERFromFile(SECItem *** derlist, char *filename, PRBool ascii,
63 +#define LOGGING_BUFFER_SIZE 400
64 +#define PEM_DEFAULT_LOG_FILE "/tmp/pkcs11.log"
65 +static const char *pemLogModuleName = "PEM";
66 +static PRLogModuleInfo* pemLogModule;
72 - plogfile = fopen("/tmp/pkcs11.log", "a");
74 + const char *nsprLogFile = PR_GetEnv("NSPR_LOG_FILE");
78 + pemLogModule = PR_NewLogModule(pemLogModuleName);
84 + (void) PR_SetLogFile(nsprLogFile ? nsprLogFile : PEM_DEFAULT_LOG_FILE);
85 + /* If false, the log file will remain what it was before */
90 void plog(const char *fmt, ...)
93 + char buf[LOGGING_BUFFER_SIZE];
97 - vfprintf(plogfile, fmt, ap);
98 + PR_vsnprintf(buf, sizeof(buf), fmt, ap);
102 + PR_LOG(pemLogModule, PR_LOG_DEBUG, ("%s", buf));