net: lib: http_server: Verify fs_read result for filesystem resources

Verify the result of the fs_read() operation when handling filesystem
resources, and abort processing the resource in case of errors.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
This commit is contained in:
Robert Lubos 2024-11-26 14:21:55 +01:00 committed by Fabio Baltieri
commit df79f10513
2 changed files with 9 additions and 0 deletions

View file

@ -450,6 +450,11 @@ int handle_http1_static_fs_resource(struct http_resource_detail_static_fs *stati
remaining = file_size;
while (remaining > 0) {
len = fs_read(&file, http_response, sizeof(http_response));
if (len < 0) {
LOG_ERR("Filesystem read error (%d)", len);
goto close;
}
ret = http_server_sendall(client, http_response, len);
if (ret < 0) {
goto close;

View file

@ -470,6 +470,10 @@ static int handle_http2_static_fs_resource(struct http_resource_detail_static_fs
remaining = client->data_len;
while (remaining > 0) {
len = fs_read(&file, tmp, sizeof(tmp));
if (len < 0) {
LOG_ERR("Filesystem read error (%d)", len);
goto out;
}
remaining -= len;
ret = send_data_frame(client, tmp, len, frame->stream_identifier,