Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Primitaint: Inconsistent behavior in switch-cases #5

Merged
merged 1 commit into from
Aug 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions js/src/tests/non262/taint/switch-case.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
function taintSwitchCaseTest() {

let tableSwitchOptimized = 1;
let tableSwitchOptimizedTainted = Number.tainted(tableSwitchOptimized);

switch (tableSwitchOptimizedTainted) {
case tableSwitchOptimized:
break;
default:
throw new Error("Taints should not be propagated in optimized switch cases");
}

let tableSwitchUnoptimized = 123456789;
let tableSwitchUnoptimizedTainted = Number.tainted(tableSwitchUnoptimized);

switch (tableSwitchUnoptimizedTainted) {
case tableSwitchUnoptimized:
break;
default:
throw new Error("Taints should not be propagated in optimized switch cases");
}
}

runTaintTest(taintSwitchCaseTest);

if (typeof reportCompare === 'function')
reportCompare(true, true);

3 changes: 3 additions & 0 deletions js/src/vm/Interpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3330,6 +3330,9 @@ bool MOZ_NEVER_INLINE JS_HAZ_JSNATIVE_CALLER js::Interpret(JSContext* cx,
int32_t i;
if (rref.isInt32()) {
i = rref.toInt32();
}
else if (isTaintedNumber(rref)) {
i = rref.toObject().as<NumberObject>().unbox();
} else {
/* Use mozilla::NumberEqualsInt32 to treat -0 (double) as 0. */
if (!rref.isDouble() || !NumberEqualsInt32(rref.toDouble(), &i)) {
Expand Down