Closed
Bug 270248
Opened 20 years ago
Closed 19 years ago
Cleanup string usage in wallet code
Categories
(Toolkit :: Form Manager, enhancement)
Toolkit
Form Manager
Tracking
()
RESOLVED
FIXED
People
(Reporter: darin.moz, Assigned: pkwarren)
References
Details
Attachments
(2 files, 3 obsolete files)
22.62 KB,
patch
|
Biesinger
:
review+
darin.moz
:
superreview+
|
Details | Diff | Splinter Review |
11.58 KB,
patch
|
Biesinger
:
review+
darin.moz
:
superreview+
|
Details | Diff | Splinter Review |
Cleanup string usage in wallet code The wallet code uses raw character pointers for a lot of things, and as was shown in bug 270215, the wallet code had some memory leaks as a result of mismanaged heap pointers. The fix for that bug was to make use of nsCString and friends, but there's still more work that could be done to simplify the string usage in wallet. For example, wallet_Sublist's item member should be a nsCString instead of a raw character pointer.
Assignee | ||
Updated•20 years ago
|
Assignee: dveditz → pkwarren
Assignee | ||
Comment 1•20 years ago
|
||
This starts a general cleanup of the wallet string usage, although there is still a lot that can be done. Also after fixing the usage of nsAutoString in the interface, nothing needs to be marked noscript, which could remove the need for the nsISignonViewer interface and implementation. The only three functions in that interface only call methods on nsIWalletService.
Assignee | ||
Updated•20 years ago
|
Attachment #166915 -
Flags: superreview?(darin)
Reporter | ||
Comment 2•20 years ago
|
||
Comment on attachment 166915 [details] [diff] [review] Patch v1 >Index: extensions/wallet/src/singsign.cpp >+ if (NS_FAILED(Wallet_Encrypt(nsAutoString(username), data1.value))) { >+ if (NS_FAILED(Wallet_Encrypt(nsAutoString(password), data2.value))) { Is it possible to use nsDependentString instead of nsAutoString here? >Index: extensions/wallet/src/wallet.cpp >-const char* previousElementState = nsnull; >+static nsCString previousElementState; watch out! the string classes cannot be declared as global/file-static variables. on OSX this can cause crashes in certain configurations due to static initialization ordering problems :-( See for example bug 234916 >- if (!PL_strcasecmp(sublistPtr->item, previousElementState)) { >+ if (sublistPtr->item.Equals(previousElementState)) { Do you need to use a case insensitive compare? Otherwise, this patch looks great. Thanks!
Attachment #166915 -
Flags: superreview?(darin) → superreview-
Assignee | ||
Comment 3•20 years ago
|
||
(In reply to comment #2) > >-const char* previousElementState = nsnull; > >+static nsCString previousElementState; > watch out! the string classes cannot be declared as global/file-static > variables. on OSX this can cause crashes in certain configurations due > to static initialization ordering problems :-( > See for example bug 234916 What if I have a struct which is declared globally which has a nsCString member?
Status: NEW → ASSIGNED
Reporter | ||
Comment 5•20 years ago
|
||
pkw: yeah, what timeless said... that'll trigger the same problem.
Assignee | ||
Comment 6•20 years ago
|
||
This is a more extensive patch which also fixes some string usage in singsign.cpp.
Attachment #166915 -
Attachment is obsolete: true
Assignee | ||
Updated•20 years ago
|
Attachment #167377 -
Flags: superreview?(darin)
Reporter | ||
Comment 7•20 years ago
|
||
Comment on attachment 167377 [details] [diff] [review] Patch v2 >Index: extensions/wallet/src/wallet.cpp >+ crypt.Append(PREFIX); can this use AppendLiteral? >+ text = str; >+ nsMemory::Free(str); how about |text.Adopt(str);|? >+ text = str; >+ nsMemory::Free(str); same here. >+const char permission_NoCapture_NoPreview[] = "yy"; >+const char permission_NoCapture_Preview[] = "yn"; >+const char permission_Capture_NoPreview[] = "ny"; >+const char permission_Capture_Preview[] = "nn"; can these be declared static? good work! but, it's generally a good idea to keep patches small, though it can be tempting to fix everything in one swoop ;-) ... just want to watch out for regressions
Assignee | ||
Comment 8•20 years ago
|
||
I will drop these changes in smaller parts to simplify the work for reviewers and to minimize any regressions. In this patch I remove the usage of nsAutoString from the IDL file, change function declarations to match the IDL changes, and remove unused/unneeded functions.
Attachment #167377 -
Attachment is obsolete: true
Assignee | ||
Updated•20 years ago
|
Attachment #167377 -
Flags: superreview?(darin)
Assignee | ||
Updated•20 years ago
|
Attachment #167470 -
Flags: superreview?(darin)
Reporter | ||
Comment 9•20 years ago
|
||
Comment on attachment 167470 [details] [diff] [review] IDL Changes v1 sr=darin
Attachment #167470 -
Flags: superreview?(darin) → superreview+
Assignee | ||
Updated•20 years ago
|
Attachment #167470 -
Flags: review?(cbiesinger)
Comment 10•20 years ago
|
||
Comment on attachment 167470 [details] [diff] [review] IDL Changes v1 hmm, why do all the methods of nsIWalletService start with WALLET_ or SI_... it would seem like the class name would imply that... ah well extensions/wallet/src/wallet.cpp +Wallet_Encrypt (const nsAString& textUCS2, nsAString& cryptUCS2) { hmm, nsAString is actually in UTF-16, not UCS-2... feel free to fix this if you want; or leave it as-is. looks good, thanks! sorry for the delay.
Attachment #167470 -
Flags: review?(cbiesinger) → review+
Assignee | ||
Comment 11•20 years ago
|
||
IDL patch checked in. Checking in editor/nsWalletEditor.cpp; /cvsroot/mozilla/extensions/wallet/editor/nsWalletEditor.cpp,v <-- nsWalletEditor.cpp new revision: 1.26; previous revision: 1.25 done Checking in public/nsIWalletService.idl; /cvsroot/mozilla/extensions/wallet/public/nsIWalletService.idl,v <-- nsIWalletService.idl new revision: 1.36; previous revision: 1.35 done Checking in signonviewer/nsSignonViewer.cpp; /cvsroot/mozilla/extensions/wallet/signonviewer/nsSignonViewer.cpp,v <-- nsSignonViewer.cpp new revision: 1.25; previous revision: 1.24 done Checking in src/nsWalletService.cpp; /cvsroot/mozilla/extensions/wallet/src/nsWalletService.cpp,v <-- nsWalletService.cpp new revision: 1.156; previous revision: 1.155 done Checking in src/singsign.cpp; /cvsroot/mozilla/extensions/wallet/src/singsign.cpp,v <-- singsign.cpp new revision: 1.251; previous revision: 1.250 done Checking in src/singsign.h; /cvsroot/mozilla/extensions/wallet/src/singsign.h,v <-- singsign.h new revision: 1.55; previous revision: 1.54 done Checking in src/wallet.cpp; /cvsroot/mozilla/extensions/wallet/src/wallet.cpp,v <-- wallet.cpp new revision: 1.372; previous revision: 1.371 done Checking in src/wallet.h; /cvsroot/mozilla/extensions/wallet/src/wallet.h,v <-- wallet.h new revision: 1.50; previous revision: 1.49 done Checking in walletpreview/nsWalletPreview.cpp; /cvsroot/mozilla/extensions/wallet/walletpreview/nsWalletPreview.cpp,v <-- nsWalletPreview.cpp new revision: 1.24; previous revision: 1.23 done
Assignee | ||
Comment 12•20 years ago
|
||
Use nsString, nsDependentString, and EmptyString instead of nsAutoString where appropriate.
Assignee | ||
Updated•20 years ago
|
Attachment #168062 -
Flags: superreview?(darin)
Attachment #168062 -
Flags: review?(cbiesinger)
Reporter | ||
Comment 13•20 years ago
|
||
Comment on attachment 168062 [details] [diff] [review] singsign changes >Index: extensions/wallet/src/singsign.cpp >-si_StripLF(nsAutoString buffer) { >+si_StripLF(nsString & buffer) { > buffer.Trim("\n\r", PR_FALSE, PR_TRUE, PR_FALSE); well this is fun! do we have to worry about regressions now that this function will actually do something? sr=darin
Attachment #168062 -
Flags: superreview?(darin) → superreview+
Assignee | ||
Comment 14•20 years ago
|
||
(In reply to comment #13) > well this is fun! do we have to worry about regressions now > that this function will actually do something? Ugh. I guess it was always a no-op anyway. si_StripLF is only called on strings returned from wallet_GetLine, which is just a wrapper around nsILineInputStream->GetLine(). Those strings shouldn't ever have trailing newlines, so I think all of the calls to stripLF can be removed. What do you think?
Reporter | ||
Comment 15•20 years ago
|
||
sounds like a plan to me :)
Comment 16•20 years ago
|
||
Comment on attachment 168062 [details] [diff] [review] singsign changes hm... could you use the -p flag when creating patches? helps seeing which function changes are in...
Attachment #168062 -
Flags: review?(cbiesinger) → review+
Assignee | ||
Comment 17•20 years ago
|
||
singsign.cpp changes checked in (with removal of stripLF function). Checking in src/singsign.cpp; /cvsroot/mozilla/extensions/wallet/src/singsign.cpp,v <-- singsign.cpp new revision: 1.252; previous revision: 1.251 done
Comment 18•20 years ago
|
||
Hum, could this one cause the regression from Bug 274169 which is crashing Mozilla while try to send Account-Information?
Assignee | ||
Comment 19•20 years ago
|
||
Backed out singsign.cpp changes from yesterday due to regressions.
Assignee | ||
Comment 20•20 years ago
|
||
I think the reason for the regression is that there are two places where the si_SignonDataStruct class is defined - once in wallet.cpp and once in singsign.cpp. Since one of the classes had name/value as nsAutoString and the other had name/value as type nsString, and it appears that having them defined in both places caused this issue. There should only be one definition of this class in a header file that is shared by all code using it. As far as I can tell, all of the crashes occurred when passing an array of si_SignonDataStruct classes from wallet to singsign in the SINGSIGN_RestoreSignonData function. For more information, see: http://lxr.mozilla.org/seamonkey/ident?i=si_SignonDataStruct
Assignee | ||
Updated•20 years ago
|
Attachment #168062 -
Attachment is obsolete: true
Reporter | ||
Comment 21•20 years ago
|
||
wow! i knew this code was bad, but i didn't know it was that bad :(
Assignee | ||
Comment 22•20 years ago
|
||
- Remove duplicate declaration of si_SignonDataStruct. I have tested this patch thoroughly with saving passwords to the password manager and there are no longer any crashes. Sorry for neglecting to do so before - I wasn't expecting two declarations of the si_SignonDataStruct class.
Attachment #168708 -
Flags: superreview?(darin)
Attachment #168708 -
Flags: review?(cbiesinger)
Comment 23•20 years ago
|
||
Comment on attachment 168708 [details] [diff] [review] singsign changes v2 r=biesi
Attachment #168708 -
Flags: review?(cbiesinger) → review+
Reporter | ||
Updated•20 years ago
|
Attachment #168708 -
Flags: superreview?(darin) → superreview+
Assignee | ||
Comment 24•20 years ago
|
||
Updated singsign changes checked in. Checking in singsign.cpp; /cvsroot/mozilla/extensions/wallet/src/singsign.cpp,v <-- singsign.cpp new revision: 1.254; previous revision: 1.253 done Checking in singsign.h; /cvsroot/mozilla/extensions/wallet/src/singsign.h,v <-- singsign.h new revision: 1.56; previous revision: 1.55 done Checking in wallet.cpp; /cvsroot/mozilla/extensions/wallet/src/wallet.cpp,v <-- wallet.cpp new revision: 1.373; previous revision: 1.372 done
I believe this caused bug 275786, but am not sure.
Assignee | ||
Comment 26•19 years ago
|
||
Resolving this bug as fixed - my experiments in the wallet code are done for now =). Feel free to open additional bugs to fix any other issues.
Status: ASSIGNED → RESOLVED
Closed: 19 years ago
Resolution: --- → FIXED
You need to log in
before you can comment on or make changes to this bug.
Description
•