-
Notifications
You must be signed in to change notification settings - Fork 226
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: have liveSlots reject Promise arguments in D() invocations
This is in addition to the kernel-side translator killing the vat if one gets through. Using a promise in `syscall.callNow()` is vat-fatal. Using one in `D()` merely throws an Error (thrown by liveslots before the syscall is made). closes #1358
- Loading branch information
Showing
4 changed files
with
98 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { assert } from '@agoric/assert'; | ||
import { QCLASS } from '@agoric/marshal'; | ||
import { insistVatType } from '../../src/parseVatSlots'; | ||
|
||
// to exercise the error we get when syscall.callNow() is given a promise | ||
// identifier, we must bypass liveslots, which would otherwise protect us | ||
// against the vat-fatal mistake | ||
|
||
function capdata(body, slots = []) { | ||
return harden({ body, slots }); | ||
} | ||
|
||
function capargs(args, slots = []) { | ||
return capdata(JSON.stringify(args), slots); | ||
} | ||
|
||
export default function setup(syscall, state, _helpers, vatPowers) { | ||
const { callNow } = syscall; | ||
const { testLog } = vatPowers; | ||
const dispatch = harden({ | ||
deliver(facetid, method, args, _result) { | ||
if (method === 'bootstrap') { | ||
// find the device slot | ||
const [_vats, devices] = JSON.parse(args.body); | ||
const qnode = devices.d0; | ||
assert.equal(qnode[QCLASS], 'slot'); | ||
const slot = args.slots[qnode.index]; | ||
insistVatType('device', slot); | ||
|
||
const vpid = 'p+1'; // pretend we're exporting a promise | ||
const pnode = { [QCLASS]: 'slot', index: 0 }; | ||
const callNowArgs = capargs([pnode], [vpid]); | ||
|
||
testLog('sending Promise'); | ||
try { | ||
// this will throw an exception, but is also (eventually) vat-fatal | ||
callNow(slot, 'send', callNowArgs); | ||
testLog('oops: survived sending Promise'); | ||
} catch (e) { | ||
testLog('good: callNow failed'); | ||
} | ||
} else if (method === 'ping') { | ||
testLog('oops: still alive'); | ||
} | ||
}, | ||
}); | ||
return dispatch; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters