Skip to content

Commit 78b8950

Browse files
schweigstillkartben
authored andcommitted
net: http_server: Fix crash when cb refuses new websocket connection
Zephyr crashes when a new websocket connection is refused by the user supplied callback function. This is caused by multiple calls of close_client_connection(). After the first call the file handle and the client->service pointer are invalid. This fix checks if the file handle is valid. Signed-off-by: Andreas Schweigstill <[email protected]>
1 parent d6e940e commit 78b8950

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

subsys/net/lib/http/http_server_core.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -383,9 +383,11 @@ static void close_client_connection(struct http_client_ctx *client)
383383
{
384384
int fd = client->fd;
385385

386-
http_server_release_client(client);
386+
if (fd >= 0) {
387+
http_server_release_client(client);
387388

388-
(void)zsock_close(fd);
389+
(void)zsock_close(fd);
390+
}
389391
}
390392

391393
static void client_timeout(struct k_work *work)

0 commit comments

Comments
 (0)