From a83d4e0e8f135365b64dc8121dae686d90cbf2fe Mon Sep 17 00:00:00 2001 From: John Lama Date: Wed, 27 Mar 2024 15:39:07 +0100 Subject: [PATCH] hal_stream_create: fix bogus error check hal_stream_create() did not check the return value of halpr_parse_types() properly, so the stream could be created with any kind of invalid cfg string. --- src/hal/hal_lib.c | 2 +- tests/hal-stream/README | 1 + tests/hal-stream/expected | 1 + tests/hal-stream/test.hal | 1 + tests/hal-stream/test.py | 13 +++++++++++++ 5 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 tests/hal-stream/README create mode 100644 tests/hal-stream/expected create mode 100644 tests/hal-stream/test.hal create mode 100755 tests/hal-stream/test.py diff --git a/src/hal/hal_lib.c b/src/hal/hal_lib.c index 32e607c0c63..a113454c53c 100644 --- a/src/hal/hal_lib.c +++ b/src/hal/hal_lib.c @@ -3984,7 +3984,7 @@ int hal_stream_create(hal_stream_t *stream, int comp, int key, int depth, const int result = 0; hal_type_t type[HAL_STREAM_MAX_PINS]; result = halpr_parse_types(type, typestring); - if(result < 0) return result; + if(!result) return -EINVAL; int pin_count = result; size_t size = sizeof(struct hal_stream_shm) + sizeof(union hal_stream_data) * depth * (1+pin_count); diff --git a/tests/hal-stream/README b/tests/hal-stream/README new file mode 100644 index 00000000000..8798555629b --- /dev/null +++ b/tests/hal-stream/README @@ -0,0 +1 @@ +Creating a hal stream should fail if the cfg string is invalid. diff --git a/tests/hal-stream/expected b/tests/hal-stream/expected new file mode 100644 index 00000000000..2ae28399f5f --- /dev/null +++ b/tests/hal-stream/expected @@ -0,0 +1 @@ +pass diff --git a/tests/hal-stream/test.hal b/tests/hal-stream/test.hal new file mode 100644 index 00000000000..a0055ff2cdd --- /dev/null +++ b/tests/hal-stream/test.hal @@ -0,0 +1 @@ +loadusr -w ./test.py diff --git a/tests/hal-stream/test.py b/tests/hal-stream/test.py new file mode 100755 index 00000000000..e96f0f10fa8 --- /dev/null +++ b/tests/hal-stream/test.py @@ -0,0 +1,13 @@ +#!/usr/bin/env python3 +import hal + +c = hal.component("stream_test") +try: + writer = hal.stream(c, hal.streamer_base, 10, "xx") +except: + pass +else: + assert False, "hal.stream should fail with invalid cfg arg" + +c.ready() +print("pass")