Skip to content

Commit d9be126

Browse files
nealjackkartben
authored andcommitted
mgmt: hawkbit: add check for valid domain name length
This commit adds a `strnlen` length check for `server_addr` to ensure that it will not be truncated and result in a silent failure. Instead, the call to `hawkbit_set_config` will return -EINVAL if the supplied `server_addr` is too long for the internal buffer. Signed-off-by: Neal Jackson <neal@blueirislabs.com>
1 parent f75a11d commit d9be126

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

include/zephyr/mgmt/hawkbit/config.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ struct hawkbit_runtime_config {
4545
* @param config Configuration settings to set.
4646
* @retval 0 on success.
4747
* @retval -EAGAIN if probe is currently running.
48+
* @retval -EINVAL if config parameters are invalid.
4849
*/
4950
int hawkbit_set_config(struct hawkbit_runtime_config *config);
5051

@@ -61,6 +62,7 @@ struct hawkbit_runtime_config hawkbit_get_config(void);
6162
* @param addr_str Server address to set.
6263
* @retval 0 on success.
6364
* @retval -EAGAIN if probe is currently running.
65+
* @retval -EINVAL if config parameters are invalid.
6466
*/
6567
static inline int hawkbit_set_server_addr(char *addr_str)
6668
{

subsys/mgmt/hawkbit/hawkbit.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -780,6 +780,12 @@ int hawkbit_set_config(struct hawkbit_runtime_config *config)
780780
{
781781
if (k_sem_take(&probe_sem, HAWKBIT_SET_SERVER_TIMEOUT) == 0) {
782782
if (config->server_addr != NULL) {
783+
if (strnlen(config->server_addr, sizeof(hb_cfg.server_addr)) ==
784+
sizeof(hb_cfg.server_addr)) {
785+
LOG_ERR("%s too long: %s", "hawkbit/server_addr",
786+
config->server_addr);
787+
return -EINVAL;
788+
}
783789
strncpy(hb_cfg.server_addr, config->server_addr,
784790
sizeof(hb_cfg.server_addr));
785791
LOG_DBG("configured %s: %s", "hawkbit/server_addr", hb_cfg.server_addr);

0 commit comments

Comments
 (0)