Commit d9be126e authored by Neal Jackson's avatar Neal Jackson Committed by Benjamin Cabé
Browse files

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: default avatarNeal Jackson <neal@blueirislabs.com>
parent f75a11d2
Loading
Loading
Loading
Loading
+2 −0
Changes for include/zephyr/mgmt/hawkbit/config.h: 2 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -45,6 +45,7 @@ struct hawkbit_runtime_config {
 * @param config Configuration settings to set.
 * @retval 0 on success.
 * @retval -EAGAIN if probe is currently running.
 * @retval -EINVAL if config parameters are invalid.
 */
int hawkbit_set_config(struct hawkbit_runtime_config *config);

@@ -61,6 +62,7 @@ struct hawkbit_runtime_config hawkbit_get_config(void);
 * @param addr_str Server address to set.
 * @retval 0 on success.
 * @retval -EAGAIN if probe is currently running.
 * @retval -EINVAL if config parameters are invalid.
 */
static inline int hawkbit_set_server_addr(char *addr_str)
{
+6 −0
Changes for subsys/mgmt/hawkbit/hawkbit.c: 6 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -780,6 +780,12 @@ int hawkbit_set_config(struct hawkbit_runtime_config *config)
{
	if (k_sem_take(&probe_sem, HAWKBIT_SET_SERVER_TIMEOUT) == 0) {
		if (config->server_addr != NULL) {
			if (strnlen(config->server_addr, sizeof(hb_cfg.server_addr)) ==
			    sizeof(hb_cfg.server_addr)) {
				LOG_ERR("%s too long: %s", "hawkbit/server_addr",
					config->server_addr);
				return -EINVAL;
			}
			strncpy(hb_cfg.server_addr, config->server_addr,
				sizeof(hb_cfg.server_addr));
			LOG_DBG("configured %s: %s", "hawkbit/server_addr", hb_cfg.server_addr);