Skip to content

Commit

Permalink
check string lengths
Browse files Browse the repository at this point in the history
  • Loading branch information
maxd-nordic committed Jul 7, 2023
1 parent a922397 commit 79ded34
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions subsys/dap/cmsis_dap.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <zephyr/init.h>
#include <zephyr/sys/byteorder.h>
#include <zephyr/drivers/swdp.h>
#include <stdint.h>

#include <cmsis_dap.h>

Expand Down Expand Up @@ -46,6 +47,25 @@ struct dap_context {

static struct dap_context dap_ctx[1];

BUILD_ASSERT(sizeof(CONFIG_CMSIS_DAP_PROBE_VENDOR) <=
MIN(CONFIG_CMSIS_DAP_PACKET_SIZE - 2, UINT8_MAX -2),
"PROBE_VENDOR string is too long.");
BUILD_ASSERT(sizeof(CONFIG_CMSIS_DAP_PROBE_NAME) <=
MIN(CONFIG_CMSIS_DAP_PACKET_SIZE - 2, UINT8_MAX -2),
"PROBE_NAME string is too long.");
BUILD_ASSERT(sizeof(CONFIG_CMSIS_DAP_BOARD_VENDOR) <=
MIN(CONFIG_CMSIS_DAP_PACKET_SIZE - 2, UINT8_MAX -2),
"BOARD_VENDOR string is too long.");
BUILD_ASSERT(sizeof(CONFIG_CMSIS_DAP_BOARD_NAME) <=
MIN(CONFIG_CMSIS_DAP_PACKET_SIZE - 2, UINT8_MAX -2),
"BOARD_NAME string is too long.");
BUILD_ASSERT(sizeof(CONFIG_CMSIS_DAP_DEVICE_VENDOR) <=
MIN(CONFIG_CMSIS_DAP_PACKET_SIZE - 2, UINT8_MAX -2),
"DEVICE_VENDOR string is too long.");
BUILD_ASSERT(sizeof(CONFIG_CMSIS_DAP_DEVICE_NAME) <=
MIN(CONFIG_CMSIS_DAP_PACKET_SIZE - 2, UINT8_MAX -2),
"DEVICE_NAME string is too long.");

/* Get DAP Information */
static uint16_t dap_info(struct dap_context *const ctx,
const uint8_t *const request,
Expand Down

0 comments on commit 79ded34

Please sign in to comment.