1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-12-14 17:13:50 +01:00

sys/uri_parser: fixing potential out of bounds read when consuming ports

This commit is contained in:
Teufelchen1 2022-12-05 15:21:22 +01:00
parent 945af26648
commit cc6327bf1b
3 changed files with 8 additions and 8 deletions

View File

@ -1006,4 +1006,8 @@ ifneq (,$(filter auto_init%,$(USEMODULE)))
USEMODULE += preprocessor_successor
endif
ifneq (,$(filter uri_parser,$(USEMODULE)))
USEMODULE += fmt
endif
include $(RIOTBASE)/sys/test_utils/Makefile.dep

View File

@ -7,4 +7,5 @@
config MODULE_URI_PARSER
bool "URI parser"
select MODULE_FMT
depends on TEST_KCONFIG

View File

@ -21,6 +21,8 @@
#include <assert.h>
#include <stdlib.h>
#include "fmt.h"
#include "uri_parser.h"
#define MAX_PORT_STR_LEN (5)
@ -129,15 +131,8 @@ bool _consume_port(uri_parser_result_t *result, const char *ipv6_end,
}
}
/* Verify that the next character, after the port, is an invalid
* character for the atol function. Preventing it from reading out-
* side of the port section */
if ((authority_end[0] >= '0') && (authority_end[0] <= '9')) {
return false;
}
/* Verify that the port is smaller or equal to UINT16_MAX. */
uint32_t port = atol(port_begin);
uint32_t port = scn_u32_dec(port_begin, port_str_len);
if (port > UINT16_MAX) {
return false;
}