Closed Bug 232380 Opened 21 years ago Closed 21 years ago

A cert may be destroyed twice in CERT_FindExpiredIssuer and cert_VerifyCertChain

Categories

(NSS :: Libraries, defect, P1)

defect

Tracking

(Not tracked)

RESOLVED FIXED

People

(Reporter: wtc, Assigned: wtc)

Details

Attachments

(1 file)

I found these problems during code inspection.

In lib/certhigh/certfvy.c, search for the string 
"subjectCert = issuerCert", you will find two for 
loops. 

The first for loop (in CERT_FindExpiredIssuer) 
has the following problem: 

When the for loop exits because
count >= CERT_MAX_CERT_CHAIN, subjectCert equals
issuerCert and both are non-NULL. So we will
destroy that cert twice before we return from
the function.

Note: Nelson pointed out that test for a root CA
(self signed) cert is incorrect.  However, he found
that this function is dead code, so the solution
for this function is to delete it.

The second for loop (in cert_VerifyCertChain) has
the following problem: 

The "subjectCert = NULL;" assignment statement after 
the for loop defends against the problem above. 
However, if we take the "goto loser;" jump inside 
the if (subjectCertIsSelfIssued == PR_FALSE) {...} 
block at the beginning of the for loop, we also end 
up with the same condition: subjectCert equals 
issuerCert and both are non-NULL, and we will destroy 
that cert twice before we return from the function.
Attached patch Proposed patchSplinter Review
1. Removed dead function CERT_FindExpiredIssuer.
Please make sure that we do not plan to export
this function.

2. In cert_VerifyCertChain, fix the double-destroy
problem by never having subjectCert and issuerCert
point at the same cert at any time.
Attachment #140038 - Flags: superreview?(jpierre)
Attachment #140038 - Flags: review?(MisterSSL)
Comment on attachment 140038 [details] [diff] [review]
Proposed patch

I agree with this fix.
Attachment #140038 - Flags: superreview?(jpierre) → superreview+
Comment on attachment 140038 [details] [diff] [review]
Proposed patch

Good catch!
Attachment #140038 - Flags: review?(MisterSSL) → review+
Patch checked in.

Checking in certdb/cert.h;
/cvsroot/mozilla/security/nss/lib/certdb/cert.h,v  <--  cert.h
new revision: 1.44; previous revision: 1.43
done
Checking in certhigh/certvfy.c;
/cvsroot/mozilla/security/nss/lib/certhigh/certvfy.c,v  <--  certvfy.c
new revision: 1.40; previous revision: 1.39
done
Status: NEW → RESOLVED
Closed: 21 years ago
Resolution: --- → FIXED
Target Milestone: --- → 3.10
Setting priorities on unprioritized bugs resolved fixed for NSS 3.10.
Marking P1 since this fixes a double-free.
Priority: -- → P1
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: