artiq/artiq
sven-oxionics b3dc199e6a Fix panic when receiving empty strings in rpc calls
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>
2023-07-18 04:00:32 +00:00
..
applets progress_bar: refactor data_changed 2023-07-12 08:28:28 +00:00
browser browser: refactor upload_clicked for dataset metadata 2023-07-10 04:26:08 +00:00
compiler compiler: skip demangling list of empty names 2023-06-09 13:24:10 +08:00
coredevice artiq_ddb_template: use the clk_div field 2023-06-29 03:29:18 +00:00
dashboard gui/experiments: cast Qt timestamp to int preventing float type error 2023-07-14 08:33:27 +00:00
examples remove Sayma and Metlino support 2023-01-06 17:41:12 +08:00
firmware Fix panic when receiving empty strings in rpc calls 2023-07-18 04:00:32 +00:00
frontend artiq_client: refactor set_dataset, show_datasets 2023-07-10 04:50:54 +00:00
gateware eem_7series: fix typo in 77293d5 2023-07-11 23:09:15 +00:00
gui applets: add metadata param to set_dataset 2023-07-12 08:28:28 +00:00
language environment: add get_dataset_metadata 2023-07-10 02:33:59 +00:00
master databases: read and save metadata in lmdb 2023-07-10 02:33:59 +00:00
sim ttl: Add target RTIO time argument to timestamp/count functions 2018-11-03 20:33:19 +08:00
test test_datasets: add metadata tests 2023-07-10 02:33:59 +00:00
wavesynth wavesynth: np.int is deprecated 2021-09-13 07:02:35 +08:00
__init__.py simplify versioneer 2020-07-30 00:54:07 +08:00
_version.py PEP440 compliant version numbers 2023-04-30 16:55:49 +08:00
appdirs.py add appdirs 2016-07-18 16:40:18 +02:00
build_soc.py satellites: add kernel cpu 2023-06-16 15:44:31 +08:00
experiment.py artiq.experiment: merge language and coredevice namespaces 2016-01-25 17:24:00 -07:00
remoting.py artiq_flash: wrap paramiko commands in bash login shell 2021-05-27 21:44:10 +08:00
tools.py tools: refactor short_format with metadata 2023-07-10 02:33:59 +00:00