From: Mathieu Pilato Date: Fri, 31 Mar 2023 08:02:20 +0000 (+0200) Subject: binary_helpers: Rename bv_get_value to reflect it's length checking X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=48b7c90166221e69aee1b618fe8ecced8be90f9b;p=libsigrok.git binary_helpers: Rename bv_get_value to reflect it's length checking Rename the bv_get_value() routine to bv_get_value_len() to better reflect that this implementation checks the input data image's length. A version which doesn't check length will get introduced soon. [ gsi: use a shorter name than in the initial submission ] --- diff --git a/src/binary_helpers.c b/src/binary_helpers.c index e8547a01..72c05ef1 100644 --- a/src/binary_helpers.c +++ b/src/binary_helpers.c @@ -22,7 +22,7 @@ #include #include "libsigrok-internal.h" -SR_PRIV int bv_get_value(float *out, const struct binary_value_spec *spec, +SR_PRIV int bv_get_value_len(float *out, const struct binary_value_spec *spec, const uint8_t *data, size_t length) { float value; diff --git a/src/hardware/rdtech-tc/protocol.c b/src/hardware/rdtech-tc/protocol.c index dc35ca52..99297ba6 100644 --- a/src/hardware/rdtech-tc/protocol.c +++ b/src/hardware/rdtech-tc/protocol.c @@ -265,7 +265,7 @@ static int handle_poll_data(struct sr_dev_inst *sdi) std_session_send_df_frame_begin(sdi); for (ch_idx = 0; ch_idx < devc->channel_count; ch_idx++) { pch = &devc->channels[ch_idx]; - ret = bv_get_value(&v, &pch->spec, poll_pkt, TC_POLL_LEN); + ret = bv_get_value_len(&v, &pch->spec, poll_pkt, TC_POLL_LEN); if (ret != SR_OK) break; ret = feed_queue_analog_submit(devc->feeds[ch_idx], v, 1); diff --git a/src/hardware/rdtech-um/protocol.c b/src/hardware/rdtech-um/protocol.c index 321457c6..aa32768a 100644 --- a/src/hardware/rdtech-um/protocol.c +++ b/src/hardware/rdtech-um/protocol.c @@ -211,7 +211,7 @@ static int process_data(struct sr_dev_inst *sdi, ret = SR_OK; std_session_send_df_frame_begin(sdi); for (ch_idx = 0; ch_idx < p->channel_count; ch_idx++) { - ret = bv_get_value(&v, &p->channels[ch_idx].spec, data, dlen); + ret = bv_get_value_len(&v, &p->channels[ch_idx].spec, data, dlen); if (ret != SR_OK) break; ret = feed_queue_analog_submit(devc->feeds[ch_idx], v, 1); diff --git a/src/libsigrok-internal.h b/src/libsigrok-internal.h index 46865efc..b47a8e5d 100644 --- a/src/libsigrok-internal.h +++ b/src/libsigrok-internal.h @@ -2240,7 +2240,8 @@ struct binary_value_spec { }; /** - * Read extract a value from a binary data image. + * Read extract a value from a binary data image, ensuring no out-of-bounds + * read happens. * * @param[out] out Pointer to output buffer (conversion result) * @param[in] spec Binary value specification @@ -2249,7 +2250,7 @@ struct binary_value_spec { * * @return SR_OK on success, SR_ERR_* error code on failure. */ -SR_PRIV int bv_get_value(float *out, const struct binary_value_spec *spec, +SR_PRIV int bv_get_value_len(float *out, const struct binary_value_spec *spec, const uint8_t *data, size_t length); /*--- crc.c -----------------------------------------------------------------*/