11b49b
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
11b49b
From: Masayoshi Mizuma <m.mizuma@jp.fujitsu.com>
11b49b
Date: Tue, 18 Dec 2018 21:27:45 -0500
11b49b
Subject: [PATCH] Fix the looking up grub.cfg-XXX while tftp booting.
11b49b
11b49b
Currently, grub doesn't look up grub.cfg-UUID, grub.cfg-MAC and grub.cfg-IP
11b49b
while the boot is from tftp. That is because the uuid size is got by
11b49b
grub_snprintf(, 0, ,), but the grub_snprintf() always returns 0,
11b49b
so grub judges there's no available uuid in the client and give up
11b49b
the looking up grub.cfg-XXX.
11b49b
11b49b
This issue can be fixed by changing grub_snprintf(, 0, ,) behaivior
11b49b
to like as snprintf() from glibc, however, somewhere may expect
11b49b
such argument as the error, so it's risky.
11b49b
11b49b
Let's use sizeof() and grub_strlen() to calculate the uuid size
11b49b
instead of grub_snprintf().
11b49b
11b49b
Resolves: rhbz#1658500
11b49b
---
11b49b
 grub-core/net/net.c | 8 +++-----
11b49b
 1 file changed, 3 insertions(+), 5 deletions(-)
11b49b
11b49b
diff --git a/grub-core/net/net.c b/grub-core/net/net.c
11b49b
index a011b940100..19ff2d486a1 100644
11b49b
--- a/grub-core/net/net.c
11b49b
+++ b/grub-core/net/net.c
11b49b
@@ -1942,11 +1942,9 @@ grub_net_search_configfile (char *config)
11b49b
       char *client_uuid_var;
11b49b
       grub_size_t client_uuid_var_size;
11b49b
 
11b49b
-      client_uuid_var_size = grub_snprintf (NULL, 0,
11b49b
-                     "net_%s_clientuuid", inf->name);
11b49b
-      if (client_uuid_var_size <= 0)
11b49b
-	continue;
11b49b
-      client_uuid_var_size += 1;
11b49b
+      client_uuid_var_size = sizeof ("net_") + grub_strlen (inf->name) +
11b49b
+                     sizeof ("_clientuuid") + 1;
11b49b
+
11b49b
       client_uuid_var = grub_malloc(client_uuid_var_size);
11b49b
       if (!client_uuid_var)
11b49b
 	continue;