Skip to content

Commit

Permalink
hal_stream_create: fix bogus error check
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jlama authored and andypugh committed Mar 27, 2024
1 parent 29f006a commit a83d4e0
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/hal/hal_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions tests/hal-stream/README
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Creating a hal stream should fail if the cfg string is invalid.
1 change: 1 addition & 0 deletions tests/hal-stream/expected
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pass
1 change: 1 addition & 0 deletions tests/hal-stream/test.hal
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
loadusr -w ./test.py
13 changes: 13 additions & 0 deletions tests/hal-stream/test.py
Original file line number Diff line number Diff line change
@@ -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")

0 comments on commit a83d4e0

Please sign in to comment.