Skip to content

Commit df79f10

Browse files
rlubosfabiobaltieri
authored andcommitted
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 <[email protected]>
1 parent 9533370 commit df79f10

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

subsys/net/lib/http/http_server_http1.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,11 @@ int handle_http1_static_fs_resource(struct http_resource_detail_static_fs *stati
450450
remaining = file_size;
451451
while (remaining > 0) {
452452
len = fs_read(&file, http_response, sizeof(http_response));
453+
if (len < 0) {
454+
LOG_ERR("Filesystem read error (%d)", len);
455+
goto close;
456+
}
457+
453458
ret = http_server_sendall(client, http_response, len);
454459
if (ret < 0) {
455460
goto close;

subsys/net/lib/http/http_server_http2.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,10 @@ static int handle_http2_static_fs_resource(struct http_resource_detail_static_fs
470470
remaining = client->data_len;
471471
while (remaining > 0) {
472472
len = fs_read(&file, tmp, sizeof(tmp));
473+
if (len < 0) {
474+
LOG_ERR("Filesystem read error (%d)", len);
475+
goto out;
476+
}
473477

474478
remaining -= len;
475479
ret = send_data_frame(client, tmp, len, frame->stream_identifier,

0 commit comments

Comments
 (0)