Closed Bug 160122 Opened 23 years ago Closed 9 years ago

Stop using PR_smprintf in PSM

Categories

(Core :: Security: PSM, defect)

defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla49
Tracking Status
firefox49 --- fixed

People

(Reporter: KaiE, Assigned: Cykesiopka)

Details

(Whiteboard: [kerh-cuz][psm-easy][psm-logic][psm-assigned])

Attachments

(1 file)

Avoid extra allocations, replace PR_smprintf with nsCAutoString Change requested by alecf. See bug 74339 comment 20.
kaie Is this something you need to do now?
Assignee: ssaux → kaie
Priority: -- → P2
Target Milestone: --- → 2.4
Product: PSM → Core
Whiteboard: [kerh-cuz]
changing obsolete psm* target to --- (unspecified)
Target Milestone: psm2.4 → ---
QA Contact: junruh → ui
Assignee: kaie → nobody
Whiteboard: [kerh-cuz] → [kerh-cuz][psm-easy][psm-logic]
Component: Security: UI → Security: PSM
Priority: P2 → --
Summary: Avoid extra allocations, replace PR_smprintf with nsCAutoString → Replace PR_smprintf with nsAutoCString in DefaultServerNicknameForCert()
Whiteboard: [kerh-cuz][psm-easy][psm-logic] → [kerh-cuz][psm-easy][psm-logic][psm-cleanup]
Version: Other Branch → unspecified
Actually, let's go a step further and stop using PR_smprintf entirely. We can use the (more) modern Mozilla string classes instead, which at the very least provide built in automatic memory management and performance improvements.
Assignee: nobody → cykesiopka.bmo
Status: NEW → ASSIGNED
Summary: Replace PR_smprintf with nsAutoCString in DefaultServerNicknameForCert() → Stop using PR_smprintf in PSM
Whiteboard: [kerh-cuz][psm-easy][psm-logic][psm-cleanup] → [kerh-cuz][psm-easy][psm-logic][psm-assigned]
PSM can use the (more) modern Mozilla string classes instead, which at the very least provide built in automatic memory management and performance improvements. Review commit: https://reviewboard.mozilla.org/r/51659/diff/#index_header See other reviews: https://reviewboard.mozilla.org/r/51659/
Attachment #8750828 - Flags: review?(dkeeler)
Comment on attachment 8750828 [details] MozReview Request: Bug 160122 - Stop using PR_smprintf in PSM. r=keeler https://reviewboard.mozilla.org/r/51659/#review48467 LGTM. ::: security/certverifier/NSSCertDBTrustDomain.cpp:1009 (Diff revision 1) > fullLibraryPath(PR_GetLibraryName(dir, "nssckbi"), PR_FreeLibraryName); > if (!fullLibraryPath) { > return SECFailure; > } > > UniquePORTString escapedFullLibraryPath(nss_addEscape(fullLibraryPath.get(), This should be a follow-up, but another candidate for modernization would be nss_addEscape. ::: security/certverifier/NSSCertDBTrustDomain.cpp:1027 (Diff revision 1) > - if (!pkcs11ModuleSpec) { > return SECFailure; > } > > - UniqueSECMODModule rootsModule(SECMOD_LoadUserModule(pkcs11ModuleSpec.get(), > - nullptr, false)); > + UniqueSECMODModule rootsModule( > + SECMOD_LoadUserModule(const_cast<char*>(pkcs11ModuleSpec.get()), nullptr, I think we can avoid the const_cast if we use GetMutableData, but since this is really a result of a poorly stated API rather than that we're actually modifying the data, I'm not sure it's worth it. ::: security/certverifier/NSSCertDBTrustDomain.cpp:1079 (Diff revision 1) > - } > + } > + if (!baseName) { > + return NS_ERROR_FAILURE; > } > > - count = 1; > + // XXX: Give up after a certain number of tries? Yeah, we can probably give up after 500 or so here. Looks like this is only used in caching encountered intermediate certificates and keeping a copy of server certificates corresponding to certificate error overrides. If either fail, it's not a big deal (the overall task will still succeed). If they take forever, it's more of a problem. ::: security/certverifier/NSSCertDBTrustDomain.cpp:1131 (Diff revision 1) > // We have found a signer cert that we want to remember. > - char* nickname = DefaultServerNicknameForCert(node->cert); > - if (nickname && *nickname) { > + nsAutoCString nickname; > + nsresult rv = DefaultServerNicknameForCert(node->cert, nickname); > + if (NS_SUCCEEDED(rv)) { > UniquePK11SlotInfo slot(PK11_GetInternalKeySlot()); > if (slot) { If I recall correctly, other areas of code generally treat PK11_GetInternalKeySlot failure as fatal - it might be good to be consistent.
Attachment #8750828 - Flags: review?(dkeeler) → review+
https://reviewboard.mozilla.org/r/51659/#review48467 Thanks! > This should be a follow-up, but another candidate for modernization would be nss_addEscape. I filed Bug 1271953. > I think we can avoid the const_cast if we use GetMutableData, but since this is really a result of a poorly stated API rather than that we're actually modifying the data, I'm not sure it's worth it. Yeah, I think using const_cast here is slightly better - we don't actually want the string to be modified, so GetMutableData would be misleading. > Yeah, we can probably give up after 500 or so here. Looks like this is only used in caching encountered intermediate certificates and keeping a copy of server certificates corresponding to certificate error overrides. If either fail, it's not a big deal (the overall task will still succeed). If they take forever, it's more of a problem. Sounds good. > If I recall correctly, other areas of code generally treat PK11_GetInternalKeySlot failure as fatal - it might be good to be consistent. Yes, I believe you're correct - I'll make the error fatal. While I'm here, I'll also move the PK11_GetInternalKeySlot() call outside the loop since it doesn't seem to need to be inside the loop, and I'll add a comment about why it's OK to ignore the return value of PK11_ImportCert().
Comment on attachment 8750828 [details] MozReview Request: Bug 160122 - Stop using PR_smprintf in PSM. r=keeler Review request updated; see interdiff: https://reviewboard.mozilla.org/r/51659/diff/1-2/
Attachment #8750828 - Attachment description: MozReview Request: Bug 160122 - Stop using PR_smprintf in PSM. → MozReview Request: Bug 160122 - Stop using PR_smprintf in PSM. r=keeler
Status: ASSIGNED → RESOLVED
Closed: 9 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla49
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: