66 lines
2.6 KiB
Diff
66 lines
2.6 KiB
Diff
|
From 6704d7715b6303f4b7e2cb9da7c6dcc3bfdd5726 Mon Sep 17 00:00:00 2001
|
||
|
From: Michael Chang <mchang@suse.com>
|
||
|
Date: Mon, 14 Jul 2025 22:10:18 +0800
|
||
|
Subject: [PATCH 2/4] http: Return HTTP status code in http_establish
|
||
|
|
||
|
Previously, using "test -s ..." or "test -f ..." on files served via
|
||
|
HTTP would always return true, regardless of whether the target file
|
||
|
actually existed. This is incorrect behavior, whereas the same tests
|
||
|
work as expected with TFTP.
|
||
|
|
||
|
The issue stems from http_establish returning success (GRUB_ERR_NONE) as
|
||
|
long as the HTTP connection was established, without considering the
|
||
|
HTTP status code returned in the response. As a result, http_open would
|
||
|
always report success, discarding error responses such as 404 Not Found.
|
||
|
|
||
|
The patch makes http_establish to return the HTTP status code as its
|
||
|
return value when an error or unknown status code is encountered. It
|
||
|
also sets data->first_line_recv = 1 in the parse_line()'s error code
|
||
|
path to correctly reflect the parsing state and prevent reprocessing.
|
||
|
|
||
|
With this change, both -s and -f tests now behave correctly when used
|
||
|
with the HTTP protocol, as http_establish returns error for failed HTTP
|
||
|
status codes as well. As a result, http_open is no longer considered
|
||
|
successful solely based on establishing the connection, it now also
|
||
|
takes the HTTP status code into account.
|
||
|
|
||
|
Signed-off-by: Michael Chang <mchang@suse.com>
|
||
|
---
|
||
|
grub-core/net/http.c | 6 ++++++
|
||
|
1 file changed, 6 insertions(+)
|
||
|
|
||
|
diff --git a/grub-core/net/http.c b/grub-core/net/http.c
|
||
|
index 686949c17..c5509dc45 100644
|
||
|
--- a/grub-core/net/http.c
|
||
|
+++ b/grub-core/net/http.c
|
||
|
@@ -125,6 +125,7 @@ parse_line (grub_file_t file, http_data_t data, char *ptr, grub_size_t len)
|
||
|
case 404:
|
||
|
data->err = GRUB_ERR_FILE_NOT_FOUND;
|
||
|
data->errmsg = grub_xasprintf (_("file `%s' not found"), data->filename);
|
||
|
+ data->first_line_recv = 1;
|
||
|
return GRUB_ERR_NONE;
|
||
|
default:
|
||
|
data->err = GRUB_ERR_NET_UNKNOWN_ERROR;
|
||
|
@@ -132,6 +133,7 @@ parse_line (grub_file_t file, http_data_t data, char *ptr, grub_size_t len)
|
||
|
valid answers like 403 will trigger this very generic message. */
|
||
|
data->errmsg = grub_xasprintf (_("unsupported HTTP error %d: %s"),
|
||
|
code, ptr);
|
||
|
+ data->first_line_recv = 1;
|
||
|
return GRUB_ERR_NONE;
|
||
|
}
|
||
|
data->first_line_recv = 1;
|
||
|
@@ -444,6 +446,10 @@ http_establish (struct grub_file *file, grub_off_t offset, int initial)
|
||
|
}
|
||
|
return grub_error (GRUB_ERR_TIMEOUT, N_("time out opening `%s'"), data->filename);
|
||
|
}
|
||
|
+
|
||
|
+ if (data->err)
|
||
|
+ return grub_error (data->err, N_("%s"), data->errmsg);
|
||
|
+
|
||
|
return GRUB_ERR_NONE;
|
||
|
}
|
||
|
|
||
|
--
|
||
|
2.50.0
|
||
|
|