Skip to content

Commit

Permalink
net: http_server: Fix possible buffer underrun
Browse files Browse the repository at this point in the history
Avoid possible underruns when an url is shorter than a handled
extension.

Signed-off-by: Flavio Ceolin <[email protected]>
  • Loading branch information
ceolin committed Oct 24, 2024
1 parent 3d4f83a commit f20fc27
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion subsys/net/lib/http/http_server_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -760,7 +760,13 @@ void http_server_get_content_type_from_extension(char *url, char *content_type,
size_t url_len = strlen(url);

HTTP_SERVER_CONTENT_TYPE_FOREACH(ct) {
char *ext = &url[url_len - ct->extension_len];
char *ext;

if (url_len <= ct->extension_len) {
continue;
}

ext = &url[url_len - ct->extension_len];

if (strncmp(ext, ct->extension, ct->extension_len) == 0) {
strncpy(content_type, ct->content_type, content_type_size);
Expand Down

0 comments on commit f20fc27

Please sign in to comment.