Closed Bug 103011 Opened 23 years ago Closed 23 years ago

nsNSSComponent::GetPK11String leaks

Categories

(Core Graveyard :: Security: UI, defect, P1)

1.0 Branch
x86
Linux
defect

Tracking

(Not tracked)

VERIFIED FIXED
psm2.2

People

(Reporter: dbaron, Assigned: KaiE)

Details

(Keywords: memory-leak)

Attachments

(2 files, 1 obsolete file)

I'm seeing leaks of the PR_Malloc in nsNSSComponent::GetPK11String. I'm not sure if it's the caller's fault or that function, but that function could use some cleanup. The leak stack is: PR_Malloc[/builds/trunk/obj/debug/dist/bin/libnspr4.so +0x1742D] nsNSSComponent::GetPK11String(unsigned short const*, unsigned)[/builds/trunk/obj/debug/dist/bin/components/libpipnss.so +0x5DEC0] nsNSSComponent::ConfigureInternalPKCS11Token()[/builds/trunk/obj/debug/dist/bin/components/libpipnss.so +0x5E1C9] nsNSSComponent::Init()[/builds/trunk/obj/debug/dist/bin/components/libpipnss.so +0x5ED1D] nsSSLIOLayerAddToSocket(char const*, int, char const*, int, PRFileDesc*, nsISupports**, int)[/builds/trunk/obj/debug/dist/bin/components/libpipnss.so +0x67B83] nsGenericFactory::CreateInstance(nsISupports*, nsID const&, void**)[/builds/trunk/obj/debug/dist/bin/libxpcom.so +0xEA529] ...
Well, I wish NSS used |const char*| when appropriate. I did find one bug in NSS that this code was working around and becoming very complicated, so I was able to simplify things quite a bit.
cc PSM team. David, can you review. Thanks to David Baron
Keywords: patch, review
Priority: -- → P1
Target Milestone: --- → 2.2
Version: unspecified → 2.1
r=ddrinan.
there are a bunch of changes to NSS in here. Have those changes been run by/approved by the NSS team?
Adding relyea to the cc-list. Bob, please review the NSS changes in this patch. Thanks.
Note that attachment 51974 [details] [diff] [review] makes only the minimal changes to NSS (correcting an obvious mistake to avoid lots of complexity in the PSM code), whereas attachment 52597 [details] [diff] [review] fixes a tiny part of bug 103736 to avoid NS_CONST_CAST all over the PSM changes.
The NSS changes (mozilla/security/nss/lib/*) attachment (id=52597)looks fine. r=relyea
Comment on attachment 52597 [details] [diff] [review] previous patch with NS_CONST_CASTs removed /* The next two strings must be exactly 64 characters long, with the first 32 characters meaningful */ -static char *slotDescription = +static const char *slotDescription = "Netscape Internal FIPS-140-1 Cryptographic Services "; -static char *privSlotDescription = +static const char *privSlotDescription = "Netscape FIPS-140-1 User Private Key Services "; These should be const char arrays ([] after the declarator name), not pointers to const chars (* before the declarator). Fix that and sr=brendan@mozilla.org. /be
Attachment #52597 - Flags: superreview+
Brendan, slotDescription and privSlotDescription must be pointers to const chars so that they can point to other strings.
So could someone check the NSS part of the patch in?
Regarding comment #11, just an idea. Instead of: static const char *slotDescription = "Netscape Internal FIPS-140-1 Cryptographic Services "; Could we use the following? static const char slotDescriptionDefault[] = { "Netscape Internal FIPS-140-1 Cryptographic Services " }; static const char *slotDescription = slotDescriptionDefault;
No, because the string can be changes. It's actually Moot for most of the strings. In 3.4 they only static strings left are the ManufactureID and the Library description. The token and slot descriptions are now stored in the PK11Slot structure.
Giving this to default PSM owner because I'm not going to be able to check in the NSS changes.
Assignee: dbaron → ssaux
and neither can I so over to kaie
Assignee: ssaux → kaie
I checked in the NSS part of the patch on the NSS_3_3_BRANCH. However, I can't move the NSS_CLIENT_TAG until I have verified the other changes that have been checked in on the NSS_3_3_BRANCH. Bob, could you merge the NSS part of the patch into the tip of NSS? The nss/lib/softoken directory has changed so much that the patch fails to apply to the tip of NSS.
Assignee: kaie → wtc
Yes, I've made them in my tree now and I'll check them in as soon as I have them tested. I think now would also be a good time to stop checking in NSS fixes to the 3.3 branch. NSS 3.4 has been integrated with PSM, so at this point I think the PSM team should start using 3.4. Once we are happy with this we can create a tag from the 3.4 branch and land that. bob
Assigned the bug back to Kai. Kai, please work with Bob Relyea and me to get the NSS changes in NSS_CLIENT_TAG. Depending on the PSM 2.2 schedule, we can either do this in the NSS 3.3 branch or in NSS 3.4. It seems that Bob prefers to do this in NSS 3.4.
Assignee: wtc → kaie
Wan-Teh, I see that you meanwhile have moved the NSS_CLIENT_TAG, so the current Mozilla trunk has the NSS changes from the patch. That means we can now check in the PSM portion of the patch, I will do it.
Kai, Yes, the fix is in NSS_CLIENT_TAG. I forgot to notify you. Sorry about that.
checked in => fixed
Status: NEW → RESOLVED
Closed: 23 years ago
Resolution: --- → FIXED
Verified per kaie's comment.
Status: RESOLVED → VERIFIED
Triggered by researching a different bug, I by chance looked at this patch again. Once thing I noted, but which has not been discussed here: Before this patch, the strings given to PK11_ConfigurePKCS11 were truncated to a maximum length, i.e. SHORT_PK11_STRING. But now they can be of any length, whatever the locale string defines. Is that a problem?
pk11_SetStringName just ignores the excess, right?
> pk11_SetStringName just ignores the excess, right? I realize that in the past the implementation of PK11_ConfigurePKCS11 called pk11_SetStringName with the available storage space, so you are right, the patch was correct. Now with NSS 3.4, PK11_ConfigurePKCS11 builds a dynamic string. I suppose NSS has no longer that size restriction.
No, there is still a size restriction. It's based on the PKCS #11 interface. The truncation would happen inside the softoken now. bob
Just for tracking purposes, the truncation will be cared for in bug 125728.
Product: PSM → Core
Version: psm2.1 → 1.0 Branch
Product: Core → Core Graveyard
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: