forked from M-Labs/artiq
sven-oxionics
b3dc199e6a
Receiving an empty string in an RPC call currently panics. When `length` is zero, a call to the `alloc` function (as implemented in `artiq/firmware/runtime/session.rs`) returns a null pointer. Constructing a `CMutSlice` from a null pointer panics. A `CMutSlice` consists of a pointer and the length. Rust's documentation of the `core::ptr` module states: "The canonical way to obtain a pointer that is valid for zero-sized accesses is `NonNull::dangling`." This commits adds a check for the length of a string received in an RPC call. Only for lengths greater than zero a memory allocation is performed. For zero-length strings, a dangling pointer is used. Test plan: Invoke the following experiment, which returns an empty string over RPC: ``` class ReturnEmptyString(artiq.experiment.EnvExperiment): def build(self): self.core: Core = self.get_device("core") @kernel def run(self): x = self.do_rpc() print(x) @rpc def do_rpc(self) -> TStr: return "" ``` Signed-off-by: Sven Over (Oxford Ionics) <sven.over@oxionics.com> |
||
---|---|---|
.. | ||
applets | ||
browser | ||
compiler | ||
coredevice | ||
dashboard | ||
examples | ||
firmware | ||
frontend | ||
gateware | ||
gui | ||
language | ||
master | ||
sim | ||
test | ||
wavesynth | ||
__init__.py | ||
_version.py | ||
appdirs.py | ||
build_soc.py | ||
experiment.py | ||
remoting.py | ||
tools.py |