Closed Bug 375639 Opened 17 years ago Closed 17 years ago

Incorrect uneval of string containing null character

Categories

(Core :: JavaScript Engine, defect)

x86
macOS
defect
Not set
normal

Tracking

()

VERIFIED FIXED

People

(Reporter: jruderman, Assigned: mrbkap)

References

Details

(Keywords: regression, testcase)

Attachments

(1 file, 1 obsolete file)

js> uneval("a\0b") 
"a\b"

js> function() { return "a\0b"; }
function () {
    return "a\b";
}
No longer blocks: 351449
MOZILLA_1_8_BRANCH gets this right (using "\x00"), so this is a regression.
Keywords: regression
Flags: blocking1.9?
Attached patch Minimal patch (obsolete) — Splinter Review
Apparently strchr will happily match the null at the end of the target string so we have to make sure we don't pass it the null character, which breaks the Sprint statement below.
Assignee: general → mrbkap
Status: NEW → ASSIGNED
Attachment #280792 - Flags: review?(brendan)
Comment on attachment 280792 [details] [diff] [review]
Minimal patch

If I'm reading right, more context would show that this change leads to a %hc format conversion of '\0' in c, which puts a NUL byte into the result buffer. That is not valid UTF-8.

We need to get JS_C_STRINGS_ARE_UTF8 better tested, ideally by defining it for Firefox.

/be
Attachment #280792 - Flags: review?(brendan) → review-
This seems a little sneaky, sticking something in the char array that strchr won't see, but it fixes the bug.
Attachment #280792 - Attachment is obsolete: true
Attachment #281217 - Flags: review?(brendan)
Comment on attachment 281217 [details] [diff] [review]
How 'bout this then

No, that's the right fix -- data-driven logic should suffice here, no need for more ad-hoc logic.

/be
Attachment #281217 - Flags: review?(brendan)
Attachment #281217 - Flags: review+
Attachment #281217 - Flags: approval1.9+
Fixed on trunk -- we should now use the \0 escape for this case.
Status: ASSIGNED → RESOLVED
Closed: 17 years ago
Resolution: --- → FIXED
Please land a test?  Should be easy to do as either JS eng test or mochitest...
Flags: in-testsuite?
/cvsroot/mozilla/js/tests/js1_5/decompilation/regress-375639.js,v  <--  regress-375639.js
initial revision: 1.1
Flags: in-testsuite? → in-testsuite+
verified fixed 1.9.0 linux|mac|win
Status: RESOLVED → VERIFIED
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: