tools: ctl: bound csv data write against abi header size#10977
tools: ctl: bound csv data write against abi header size#10977jmestwa-coder wants to merge 1 commit into
Conversation
|
Can one of the admins verify this patch?
|
lyakh
left a comment
There was a problem hiding this comment.
that loop could benefit from some clarity improvements - mixing size in bytes and index into a 32-bit array makes it a bit hard to follow
| data_int_index = data_start_int_index; | ||
| while (fscanf(fh, "%u", &x) != EOF) { | ||
| if (n < n_max) | ||
| if (n < n_max - abi_size) |
There was a problem hiding this comment.
is alignment guaranteed? E.g. if the buffer size is initialised from the file size in like
Line 368 in a36b4c7
n <= n_max - abi_size - sizeof(uint32_t)?
There was a problem hiding this comment.
good catch, alignment isn't guaranteed and that's an overflow on its own. with ctrl_size = 257 the old bound let the last store write 3 bytes past the 265-byte buffer.
- went with counting values rather than
n <= n_max - abi_size - sizeof(uint32_t), because sizeof makes the rhs size_t, so a bytes control with count < 36 wraps it to a huge unsigned and the guard always passes - the loop now walks a uint32_t index bounded by
val_max = (n_max - abi_size) / sizeof(uint32_t), which floors off the unaligned tail - n is computed once after the loop instead of being carried alongside the index
that also drops the bytes vs u32 index mixing you pointed at. the binary branch already lands exactly on the buffer end, so it's unchanged. pushed.
The ascii csv branch of read_setup() advances the write index past the 32-byte abi header for -r (no_abi) input but still bounds each write with n < n_max, while the binary branch stops at n_max - abi_size. A csv tuning file with ctrl_size/4 values then writes sizeof(struct sof_abi_hdr) bytes past the end of the tlv buffer. ctrl_size is not guaranteed to be a multiple of sizeof(uint32_t) either, so bounding the byte count alone still lets the final 4-byte store run up to 3 bytes past the buffer. Count the csv values and stop after the last whole uint32_t that fits in the data area, which also keeps the loop from mixing a size in bytes with an index into a uint32_t array. Signed-off-by: Syed Mohammed Nayyar <jmestwa@gmail.com>
a36b4c7 to
218f57c
Compare
ascii csv input in read_setup() overflows the tlv buffer with -r:
Bounded the csv write with n < n_max - abi_size like the binary branch.