From 5dbfe8fa3bed1a4c4f60ced15c878c3606ade0b5 Mon Sep 17 00:00:00 2001 From: Jukka Rissanen Date: Wed, 5 Mar 2025 10:25:21 +0200 Subject: [PATCH 1/2] net: http: server: The detail length of wildcard detail was wrong The path length of the detail resource was not set properly. Signed-off-by: Jukka Rissanen (cherry picked from commit 33cf7dc78a976677f8693018eae90c0d0024d07b) --- subsys/net/lib/http/http_server_core.c | 2 +- tests/net/lib/http_server/common/src/main.c | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/subsys/net/lib/http/http_server_core.c b/subsys/net/lib/http/http_server_core.c index 52f4a5249a83a..c5e4ba61f04ad 100644 --- a/subsys/net/lib/http/http_server_core.c +++ b/subsys/net/lib/http/http_server_core.c @@ -762,7 +762,7 @@ struct http_resource_detail *get_resource_detail(const struct http_service_desc ret = fnmatch(resource->resource, path, (FNM_PATHNAME | FNM_LEADING_DIR)); if (ret == 0) { - *path_len = strlen(resource->resource); + *path_len = path_len_without_query(path); return resource->detail; } } diff --git a/tests/net/lib/http_server/common/src/main.c b/tests/net/lib/http_server/common/src/main.c index f0342e34fca83..ffd1f011ba6b8 100644 --- a/tests/net/lib/http_server/common/src/main.c +++ b/tests/net/lib/http_server/common/src/main.c @@ -77,6 +77,8 @@ HTTP_RESOURCE_DEFINE(resource_6, service_D, "/fo*", RES(1)); HTTP_RESOURCE_DEFINE(resource_7, service_D, "/f[ob]o3.html", RES(1)); HTTP_RESOURCE_DEFINE(resource_8, service_D, "/fb?3.htm", RES(0)); HTTP_RESOURCE_DEFINE(resource_9, service_D, "/f*4.html", RES(3)); +HTTP_RESOURCE_DEFINE(resource_11, service_D, "/foo/*", RES(3)); +HTTP_RESOURCE_DEFINE(resource_12, service_D, "/foo/b?r", RES(3)); /* Default resource in case of no match */ static uint16_t service_E_port = 8080; @@ -373,6 +375,25 @@ ZTEST(http_service, test_HTTP_RESOURCE_WILDCARD) res = CHECK_PATH(service_A, "/fbo3.htm", &len); zassert_is_null(res, "Resource found"); zassert_equal(len, 0, "Length set"); + + res = CHECK_PATH(service_D, "/foo/bar", &len); + zassert_not_null(res, "Resource not found"); + zassert_true(len == (sizeof("/foo/bar") - 1), "Length not set correctly"); + zassert_equal(res, RES(3), "Resource mismatch"); + + res = CHECK_PATH(service_D, "/foo/bar?param=value", &len); + zassert_not_null(res, "Resource not found"); + zassert_true(len == (sizeof("/foo/bar") - 1), "Length not set correctly"); + zassert_equal(res, RES(3), "Resource mismatch"); + + res = CHECK_PATH(service_D, "/bar?foo=value", &len); + zassert_is_null(res, "Resource found"); + zassert_equal(len, 0, "Length set"); + + res = CHECK_PATH(service_D, "/foo/bar?param=value", &len); + zassert_not_null(res, "Resource not found"); + zassert_true(len == (sizeof("/foo/bar") - 1), "Length not set correctly"); + zassert_equal(res, RES(3), "Resource mismatch"); } ZTEST(http_service, test_HTTP_RESOURCE_DEFAULT) From 6b3587c059bbbc202c29213a027dcd994d33e409 Mon Sep 17 00:00:00 2001 From: Jukka Rissanen Date: Wed, 5 Mar 2025 10:44:09 +0200 Subject: [PATCH 2/2] net: http: server: Select POSIX_C_LIB_EXT instead of FNMATCH The CONFIG_POSIX_C_LIB_EXT will get support for fnmatch() function. The old CONFIG_FNMATCH is deprecated. Signed-off-by: Jukka Rissanen (cherry picked from commit 0f90affcdfd376f0360317d34b44ce85f28c4294) --- subsys/net/lib/http/Kconfig | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/subsys/net/lib/http/Kconfig b/subsys/net/lib/http/Kconfig index a706f9cbe4c08..60263af89dfb3 100644 --- a/subsys/net/lib/http/Kconfig +++ b/subsys/net/lib/http/Kconfig @@ -163,7 +163,8 @@ config HTTP_SERVER_WEBSOCKET config HTTP_SERVER_RESOURCE_WILDCARD bool "Allow wildcard matching of resources" - select FNMATCH + # The POSIX_C_LIB_EXT will get fnmatch() support + select POSIX_C_LIB_EXT help Allow user to specify wildcards when setting up resource strings. This means that instead of specifying multiple resources with exact