From f181c1c7a22809176c4046c146f535234e3b0eec Mon Sep 17 00:00:00 2001 From: "relyea%netscape.com" Date: Sat, 13 Jul 2002 02:45:04 +0000 Subject: [PATCH] Fix solaris signed/unsigned warnings. On updating nicknames, create a nickname record if one doesn't exist (that is somehow the database got corrupted). --- security/nss/lib/softoken/lowcert.c | 8 ++++---- security/nss/lib/softoken/pcertdb.c | 25 ++++++++++++++++++++++--- security/nss/lib/softoken/pcertt.h | 4 ++-- 3 files changed, 28 insertions(+), 9 deletions(-) diff --git a/security/nss/lib/softoken/lowcert.c b/security/nss/lib/softoken/lowcert.c index cb0d441aa650..f186314b7aef 100644 --- a/security/nss/lib/softoken/lowcert.c +++ b/security/nss/lib/softoken/lowcert.c @@ -34,7 +34,7 @@ /* * Certificate handling code * - * $Id: lowcert.c,v 1.9 2002/06/24 21:54:39 relyea%netscape.com Exp $ + * $Id: lowcert.c,v 1.10 2002/07/13 02:45:04 relyea%netscape.com Exp $ */ #include "seccomon.h" @@ -175,7 +175,7 @@ nsslowcert_GetDefaultCertDB(void) */ static unsigned char * nsslowcert_dataStart(unsigned char *buf, int length, - int *data_length, PRBool includeTag) { + unsigned int *data_length, PRBool includeTag) { unsigned char tag; int used_length= 0; @@ -228,9 +228,9 @@ nsslowcert_GetCertFields(unsigned char *cert,int cert_length, SECItem *valid, SECItem *subjkey) { unsigned char *buf; - int buf_length; + unsigned int buf_length; unsigned char *dummy; - int dummylen; + unsigned int dummylen; /* get past the signature wrap */ buf = nsslowcert_dataStart(cert,cert_length,&buf_length,PR_FALSE); diff --git a/security/nss/lib/softoken/pcertdb.c b/security/nss/lib/softoken/pcertdb.c index 26ce1c71b08a..7b12b5a8038c 100644 --- a/security/nss/lib/softoken/pcertdb.c +++ b/security/nss/lib/softoken/pcertdb.c @@ -34,7 +34,7 @@ /* * Permanent Certificate database handling code * - * $Id: pcertdb.c,v 1.26 2002/07/10 01:04:10 relyea%netscape.com Exp $ + * $Id: pcertdb.c,v 1.27 2002/07/13 02:45:04 relyea%netscape.com Exp $ */ #include "prtime.h" @@ -755,7 +755,8 @@ DecodeDBCertEntry(certDBEntryCert *entry, SECItem *dbentry) if ( nnlen > 1 ) { entry->nickname = (char *)pkcs11_copyStaticData( &dbentry->data[headerlen+entry->derCert.len], nnlen, - entry->nicknameSpace, sizeof(entry->nicknameSpace)); + (unsigned char *)entry->nicknameSpace, + sizeof(entry->nicknameSpace)); if ( entry->nickname == NULL ) { PORT_SetError(SEC_ERROR_NO_MEMORY); goto loser; @@ -3160,6 +3161,7 @@ nsslowcert_AddPermNickname(NSSLOWCERTCertDBHandle *dbhandle, { SECStatus rv = SECFailure; certDBEntrySubject *entry = NULL; + certDBEntryNickname *nicknameEntry = NULL; nsslowcert_LockDB(dbhandle); @@ -3174,7 +3176,6 @@ nsslowcert_AddPermNickname(NSSLOWCERTCertDBHandle *dbhandle, if (entry == NULL) goto loser; if ( entry->nickname == NULL ) { - certDBEntryNickname *nicknameEntry = NULL; /* no nickname for subject */ rv = AddNicknameToSubject(dbhandle, cert, nickname); @@ -3200,6 +3201,21 @@ nsslowcert_AddPermNickname(NSSLOWCERTCertDBHandle *dbhandle, if ( rv != SECSuccess ) { goto loser; } + /* make sure nickname entry exists. If the database was corrupted, + * we may have lost the nickname entry. Add it back now */ + nicknameEntry = ReadDBNicknameEntry(dbhandle, entry->nickname); + if (nicknameEntry == NULL ) { + nicknameEntry = NewDBNicknameEntry(entry->nickname, + &cert->derSubject, 0); + if ( nicknameEntry == NULL ) { + goto loser; + } + + rv = WriteDBNicknameEntry(dbhandle, nicknameEntry); + if ( rv != SECSuccess ) { + goto loser; + } + } } rv = SECSuccess; @@ -3207,6 +3223,9 @@ loser: if (entry) { DestroyDBEntry((certDBEntry *)entry); } + if (nicknameEntry) { + DestroyDBEntry((certDBEntry *)nicknameEntry); + } nsslowcert_UnlockDB(dbhandle); return(rv); } diff --git a/security/nss/lib/softoken/pcertt.h b/security/nss/lib/softoken/pcertt.h index 2c5e966ba82e..0d2249075ad7 100644 --- a/security/nss/lib/softoken/pcertt.h +++ b/security/nss/lib/softoken/pcertt.h @@ -33,7 +33,7 @@ /* * certt.h - public data structures for the certificate library * - * $Id: pcertt.h,v 1.6 2002/06/24 21:54:40 relyea%netscape.com Exp $ + * $Id: pcertt.h,v 1.7 2002/07/13 02:45:04 relyea%netscape.com Exp $ */ #ifndef _PCERTT_H_ #define _PCERTT_H_ @@ -154,7 +154,7 @@ struct NSSLOWCERTCertificateStr { int referenceCount; char nicknameSpace[200]; - char certKeySpace[512]; + unsigned char certKeySpace[512]; }; #define SEC_CERTIFICATE_VERSION_1 0 /* default created */