Closed Bug 811355 Opened 12 years ago Closed 11 years ago

Signed integer overflow in js::random_next

Categories

(Core :: JavaScript Engine, defect)

x86_64
Linux
defect
Not set
critical

Tracking

()

RESOLVED FIXED

People

(Reporter: decoder, Unassigned)

References

(Blocks 1 open bug)

Details

(Keywords: sec-want, Whiteboard: [-fsanitize=signed-integer-overflow])

Attachments

(1 file)

Attached patch PatchSplinter Review
The following code in js/src/jsmath.cpp performs unchecked multiplication of a signed integer (which can actually be large enough to overflow):

> extern uint64_t
> random_next(int64_t *rngSeed, int bits)
> {
>     uint64_t nextseed = *rngSeed * RNG_MULTIPLIER;
>     nextseed += RNG_ADDEND;
>     nextseed &= RNG_MASK;
>     *rngSeed = nextseed;
>     return nextseed >> (48 - bits);
> }

This won't lead to an immediate failure here, but signed integer overflowing is not defined according to the C standard and should not be used (INT32-C, CERT Secure Coding Standard).

jorendorff suggested to just make rngSeed unsigned in the JSContext. Patch for this is attached.
Attachment #681100 - Flags: review?(jorendorff)
Attachment #681100 - Flags: review?(jorendorff) → review+
Whiteboard: [-fsanitize=signed-integer-overflow]
This got fixed in 7702047b003f for bug 820180.
Status: NEW → RESOLVED
Closed: 11 years ago
Resolution: --- → FIXED
Blocks: 919486
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: