Closed Bug 46898 Opened 25 years ago Closed 25 years ago

potential segfault in nsString.cpp, function ToInteger

Categories

(SeaMonkey :: General, defect, P3)

defect

Tracking

(Not tracked)

VERIFIED FIXED

People

(Reporter: jag+mozbugs, Assigned: scc)

Details

Attachments

(2 files)

In nsString.cpp, function ToInteger, there's a potential for a segfault when ToInteger is called on an empty string. Attaching patch which fixes that and does some related code clean-up.
And accepting it! r=scc, need approval for check-in.
Status: NEW → ASSIGNED
Keywords: approval
a=waterson
OK, I'll take it; checkin jag's patch; and close the bug when I'm done.
Assignee: disttsc → scc
Status: ASSIGNED → NEW
fix checked in with version 3.127 of nsString.cpp
Status: NEW → RESOLVED
Closed: 25 years ago
Resolution: --- → FIXED
Please, let nsString::ToInteger return an error when called on an empty string. Just returning zero is sometimes OK, but I think it should be up to client code to interpret empty strings. BTW, I filed bug 42930 on this some time ago...
Hmmm, if client code should interpret empty strings, shouldn't it be doing so through str.IsEmpty() or str.Length()? Aside from that, I think you're right that an error should be returned. As a matter of fact, I missed another case in my patch, for example "zyx" in base 10. In that case *anErrorCode gets set to NS_OK too, which really doesn't seem right, though that is what happened in the original code. Your patches touched those cases too. Moving |*anErrorCode = NS_OK;| to inside the |if (done)| makes the code behave a bit more logical. Since this bug was fixed, I'll attach a patch to bug 42930.
Keywords: approval
need to apply this fix to |nsString| as well
Status: RESOLVED → REOPENED
Resolution: FIXED → ---
jag also supplies a fix for problems relating to correctly interpreting the radix
Status: REOPENED → ASSIGNED
your new patches are checked in, jag
Status: ASSIGNED → RESOLVED
Closed: 25 years ago25 years ago
Resolution: --- → FIXED
jag - could you verify this?
Doh. Fixed!
Status: RESOLVED → VERIFIED
Product: Browser → Seamonkey
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: