Script 'mail_helper' called by obssrc
Hello community,

here is the log from the commit of package grub2 for openSUSE:Factory checked 
in at 2025-07-20 15:28:03
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Comparing /work/SRC/openSUSE:Factory/grub2 (Old)
 and      /work/SRC/openSUSE:Factory/.grub2.new.8875 (New)
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Package is "grub2"

Sun Jul 20 15:28:03 2025 rev:366 rq:1294250 version:2.12

Changes:
--------
--- /work/SRC/openSUSE:Factory/grub2/grub2.changes      2025-07-11 
21:29:35.551763027 +0200
+++ /work/SRC/openSUSE:Factory/.grub2.new.8875/grub2.changes    2025-07-20 
15:28:19.922232150 +0200
@@ -1,0 +2,10 @@
+Wed Jul 16 11:19:21 UTC 2025 - Michael Chang <mch...@suse.com>
+
+- Fix test -f and -s do not work properly over the network files served via
+  tftp and http (bsc#1246157) (bsc#1246237)
+  * 0001-test-Fix-f-test-on-files-over-network.patch
+  * 0002-http-Return-HTTP-status-code-in-http_establish.patch
+  * 0003-docs-Clarify-test-for-files-on-TFTP-and-HTTP.patch
+  * 0004-tftp-Fix-hang-when-file-is-a-directory.patch
+
+-------------------------------------------------------------------

New:
----
  0001-test-Fix-f-test-on-files-over-network.patch
  0002-http-Return-HTTP-status-code-in-http_establish.patch
  0003-docs-Clarify-test-for-files-on-TFTP-and-HTTP.patch
  0004-tftp-Fix-hang-when-file-is-a-directory.patch

----------(New B)----------
  New:  tftp and http (bsc#1246157) (bsc#1246237)
  * 0001-test-Fix-f-test-on-files-over-network.patch
  * 0002-http-Return-HTTP-status-code-in-http_establish.patch
  New:  * 0001-test-Fix-f-test-on-files-over-network.patch
  * 0002-http-Return-HTTP-status-code-in-http_establish.patch
  * 0003-docs-Clarify-test-for-files-on-TFTP-and-HTTP.patch
  New:  * 0002-http-Return-HTTP-status-code-in-http_establish.patch
  * 0003-docs-Clarify-test-for-files-on-TFTP-and-HTTP.patch
  * 0004-tftp-Fix-hang-when-file-is-a-directory.patch
  New:  * 0003-docs-Clarify-test-for-files-on-TFTP-and-HTTP.patch
  * 0004-tftp-Fix-hang-when-file-is-a-directory.patch
----------(New E)----------

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Other differences:
------------------
++++++ grub2.spec ++++++
--- /var/tmp/diff_new_pack.L2tzkK/_old  2025-07-20 15:28:24.126406124 +0200
+++ /var/tmp/diff_new_pack.L2tzkK/_new  2025-07-20 15:28:24.126406124 +0200
@@ -489,6 +489,10 @@
 Patch312:       0001-mkconfig-Determine-GRUB_DISTRIBUTOR-from-etc-SUSE-br.patch
 Patch313:       grub2-blsbumpcounter-menu.patch
 Patch314:       0001-disk-cryptodisk-Allow-user-to-retry-failed-passphras.patch
+Patch315:       0001-test-Fix-f-test-on-files-over-network.patch
+Patch316:       0002-http-Return-HTTP-status-code-in-http_establish.patch
+Patch317:       0003-docs-Clarify-test-for-files-on-TFTP-and-HTTP.patch
+Patch318:       0004-tftp-Fix-hang-when-file-is-a-directory.patch
 
 %if 0%{?suse_version} < 1600
 Requires:       gettext-runtime

++++++ 0001-test-Fix-f-test-on-files-over-network.patch ++++++
>From 0a8f0e75151067a8b7c09a6ffdfa9558aa040d3b Mon Sep 17 00:00:00 2001
From: Michael Chang <mch...@suse.com>
Date: Mon, 14 Jul 2025 17:59:20 +0800
Subject: [PATCH 1/4] test: Fix -f test on files over network

The "test -f ..." aka "if [ -f ... ]; " does not work for files over
network in both TFTP and HTTP and always evaluates to false.

It is caused by network protocols like TFTP and HTTP are designed for
transferring files and not a file system over network. In that way they
do not have a way to list files in a directory and test their properties
individually. The current logic in grub assumes that directory and file
listing must be implemented, which applies to local file systems but not
to file reading over the network. This logic should be adjusted to test
network files.

This patch updates the logic to detect when the underlying device is a
network device. If so, it attempts to test the file using
grub_file_open. If the file opens successfully, the ctx->file_exists
flag is set accordingly to true. Other properties that cannot be
determined over the network, such as whether the file is a directory or
whether the modification time is set, are conservatively set to false.

This means that -d cannot reliably detect directories on network
devices, and -e may not work as expected if the target is a directory.
In addition, comparisons such as -nt and -ot will not function
correctly, since file timestamps are not available. Despite these
limitations, this patch ensures that the -f test behaves correctly in
the most common case: checking whether a "file" exists on a network
device.

Signed-off-by: Michael Chang <mch...@suse.com>
---
 grub-core/commands/test.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/grub-core/commands/test.c b/grub-core/commands/test.c
index 62d3fb398..541f36daf 100644
--- a/grub-core/commands/test.c
+++ b/grub-core/commands/test.c
@@ -91,6 +91,23 @@ get_fileinfo (char *path, struct test_parse_ctx *ctx)
       return;
     }
 
+  if (! dev->disk && dev->net)
+    {
+      grub_file_t file;
+
+      file = grub_file_open (path , GRUB_FILE_TYPE_GET_SIZE
+                            | GRUB_FILE_TYPE_NO_DECOMPRESS);
+      ctx->file_exists = file ? 1 : 0;
+      ctx->file_info.dir = 0;
+      ctx->file_info.mtimeset = 0;
+      grub_errno = GRUB_ERR_NONE;
+      if (file)
+       grub_file_close (file);
+      grub_free (device_name);
+      grub_device_close (dev);
+      return;
+    }
+
   fs = grub_fs_probe (dev);
   if (! fs)
     {
-- 
2.50.0


++++++ 0002-http-Return-HTTP-status-code-in-http_establish.patch ++++++
>From 6704d7715b6303f4b7e2cb9da7c6dcc3bfdd5726 Mon Sep 17 00:00:00 2001
From: Michael Chang <mch...@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 <mch...@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


++++++ 0003-docs-Clarify-test-for-files-on-TFTP-and-HTTP.patch ++++++
>From a0bcce49bc285fb71c572963e662db3d88bcd563 Mon Sep 17 00:00:00 2001
From: Michael Chang <mch...@suse.com>
Date: Wed, 16 Jul 2025 17:52:03 +0800
Subject: [PATCH 3/4] docs: Clarify test for files on TFTP and HTTP

---
 docs/grub.texi | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/docs/grub.texi b/docs/grub.texi
index 9aaea7282..4b947e942 100644
--- a/docs/grub.texi
+++ b/docs/grub.texi
@@ -5887,13 +5887,13 @@ the strings are not equal
 @item @var{prefix}@var{integer1} @code{-plt} @var{prefix}@var{integer2}
 @var{integer1} is less than @var{integer2} after stripping off common 
non-numeric @var{prefix}.
 @item @var{file1} @code{-nt} @var{file2}
-@var{file1} is newer than @var{file2} (modification time). Optionally numeric 
@var{bias} may be directly appended to @code{-nt} in which case it is added to 
the first file modification time.
+@var{file1} is newer than @var{file2} (modification time). Optionally numeric 
@var{bias} may be directly appended to @code{-nt} in which case it is added to 
the first file modification time. For @var{file} on TFTP or HTTP servers, this 
operation may not work as expected.
 @item @var{file1} @code{-ot} @var{file2}
-@var{file1} is older than @var{file2} (modification time). Optionally numeric 
@var{bias} may be directly appended to @code{-ot} in which case it is added to 
the first file modification time.
+@var{file1} is older than @var{file2} (modification time). Optionally numeric 
@var{bias} may be directly appended to @code{-ot} in which case it is added to 
the first file modification time. For @var{file} on TFTP or HTTP servers, this 
operation may not work as expected.
 @item @code{-d} @var{file}
-@var{file} exists and is a directory
+@var{file} exists and is a directory. For @var{file} on TFTP or HTTP servers, 
the test is unreliable because these protocols are designed for file transport, 
and GRUB’s netfs does not implement directory listing for them.
 @item @code{-e} @var{file}
-@var{file} exists
+@var{file} exists. For @var{file} on TFTP or HTTP servers, the result is the 
same as @code{-f} because these protocols are designed for file transport, and 
GRUB’s netfs lacks directory support to distinguish between files and 
directories.
 @item @code{-f} @var{file}
 @var{file} exists and is not a directory
 @item @code{-s} @var{file}
-- 
2.50.0


++++++ 0004-tftp-Fix-hang-when-file-is-a-directory.patch ++++++
>From 9f8f5e0d45165b99d0f3ce9bf37382738e0bddb7 Mon Sep 17 00:00:00 2001
From: Michael Chang <mch...@suse.com>
Date: Thu, 17 Jul 2025 13:29:48 +0800
Subject: [PATCH 4/4] tftp: Fix hang when file is a directory

We observed an issue when accessing a remote directory via TFTP: GRUB
hangs indefinitely instead of returning an error immediately.

The packet capture [1] shows that the server doesn't send an error
packet right after the RRQ. Instead, it first replies with an OACK
indicating tsize=22, as if the target were a regular file. After GRUB
sends its ACK, the server then sends an error "Is a directory". GRUB
ignores this delayed error and hangs while waiting for data that never
arrives.

This happens because GRUB currently assumes any error must follow the
RRQ immediately, before data transfer begins. Once it receives an OACK,
it switches to expecting data packets and neglects any error that
arrives afterward.

To work around this, we detect an error on block 0 immediately after
OACK, set the eof and stall flags to break out of the receive loop, and
close the socket (so that tftp_close() won't send another error). GRUB
will then report the error and exit properly.

[1]
Source          Destination     Info
192.168.100.122 192.168.100.2   Read Request, File: /grub/i386-pc, Transfer 
type: octet, blksize=1024, tsize=0
192.168.100.2   192.168.100.122 Option Acknowledgement, blksize=1024, tsize=22
192.168.100.122 192.168.100.2   Acknowledgement, Block: 0
192.168.100.2   192.168.100.122 Error Code, Code: Not defined, Message: Is a 
directory

Signed-off-by: Michael Chang <mch...@suse.com>
---
 grub-core/net/tftp.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/grub-core/net/tftp.c b/grub-core/net/tftp.c
index 409b1d09b..93452fe3b 100644
--- a/grub-core/net/tftp.c
+++ b/grub-core/net/tftp.c
@@ -250,6 +250,14 @@ tftp_receive (grub_net_udp_socket_t sock __attribute__ 
((unused)),
       grub_netbuff_free (nb);
       return GRUB_ERR_NONE;
     case TFTP_ERROR:
+      if (data->have_oack == 1 && data->block == 0)
+       {
+         file->device->net->eof = 1;
+         file->device->net->stall = 1;
+         /* Do not send closed error code back to server in tftp_close() */
+         grub_net_udp_close (data->sock);
+         data->sock = NULL;
+       }
       data->have_oack = 1;
       grub_error (GRUB_ERR_IO, "%s", tftph->u.err.errmsg);
       grub_error_save (&data->save_err);
-- 
2.50.0

Reply via email to