Skip to content

Commit 07fcac4

Browse files
committed
Merge branch 'bounds'
2 parents dca1974 + fe41835 commit 07fcac4

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/da14531/da14531.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
#include "da14531.h"
1616
#include "da14531_protocol.h"
17+
#include "hardfault.h"
1718
#include "util.h"
1819
#include "utils_ringbuffer.h"
1920

@@ -53,6 +54,10 @@ void da14531_set_product(
5354
struct ringbuffer* uart_out)
5455
{
5556
uint8_t payload[64] = {0};
57+
if (product_len > sizeof(payload) - 1) {
58+
Abort("product string too large");
59+
return;
60+
}
5661
payload[0] = CTRL_CMD_PRODUCT_STRING;
5762
for (int i = 0; i < product_len; i++) {
5863
payload[1 + i] = product[i];
@@ -71,7 +76,7 @@ void da14531_set_name(const char* name, size_t name_len, struct ringbuffer* uart
7176
{
7277
uint8_t payload[64] = {0};
7378
payload[0] = CTRL_CMD_DEVICE_NAME;
74-
memcpy(&payload[1], name, name_len);
79+
memcpy(&payload[1], name, MIN(name_len, sizeof(payload) - 1));
7580
uint8_t tmp[12 + sizeof(payload) * 2];
7681
uint16_t tmp_len = da14531_protocol_format(
7782
&tmp[0], sizeof(tmp), DA14531_PROTOCOL_PACKET_TYPE_CTRL_DATA, &payload[0], 1 + name_len);

0 commit comments

Comments
 (0)