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