All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Warn the user to edit environment block by grub-editenv
@ 2019-11-05  9:20 Michael Chang
  2019-11-05 11:49 ` Javier Martinez Canillas
  2019-11-05 11:58 ` Daniel Kiper
  0 siblings, 2 replies; 4+ messages in thread
From: Michael Chang @ 2019-11-05  9:20 UTC (permalink / raw)
  To: grub-devel@gnu.org

The environment block is a preallocated 1024-byte file serves as persistent
storage for environment variables. It has its own format which is sensitive to
corruption if using editor doesn't know how to process it. Besides the editor
may inadvertantly change size allocation that could have it sparse the
filesystem which could lead to unexpected outcome.

This patch adds message in grubenv file to warn the user from editing it by
tools other than grub-editenv.

Signed-off-by: Michael Chang <mchang@suse.com>
---
 util/editenv.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/util/editenv.c b/util/editenv.c
index eb2d0c03a..ee4c9e53f 100644
--- a/util/editenv.c
+++ b/util/editenv.c
@@ -30,12 +30,14 @@
 #include <string.h>
 
 #define DEFAULT_ENVBLK_SIZE	1024
+#define GRUB_ENVBLK_MESSAGE	"# WARNING: Do not edit this file other than by "PACKAGE"-editenv\n"
 
 void
 grub_util_create_envblk_file (const char *name)
 {
   FILE *fp;
   char *buf;
+  char *pbuf;
   char *namenew;
 
   buf = xmalloc (DEFAULT_ENVBLK_SIZE);
@@ -46,9 +48,13 @@ grub_util_create_envblk_file (const char *name)
     grub_util_error (_("cannot open `%s': %s"), namenew,
 		     strerror (errno));
 
-  memcpy (buf, GRUB_ENVBLK_SIGNATURE, sizeof (GRUB_ENVBLK_SIGNATURE) - 1);
-  memset (buf + sizeof (GRUB_ENVBLK_SIGNATURE) - 1, '#',
-          DEFAULT_ENVBLK_SIZE - sizeof (GRUB_ENVBLK_SIGNATURE) + 1);
+  pbuf = buf;
+  memcpy (pbuf, GRUB_ENVBLK_SIGNATURE, sizeof (GRUB_ENVBLK_SIGNATURE) - 1);
+  pbuf += sizeof (GRUB_ENVBLK_SIGNATURE) - 1;
+  memcpy (pbuf, GRUB_ENVBLK_MESSAGE, sizeof (GRUB_ENVBLK_MESSAGE) - 1);
+  pbuf += sizeof (GRUB_ENVBLK_MESSAGE) - 1;
+  memset (pbuf , '#',
+          DEFAULT_ENVBLK_SIZE - sizeof (GRUB_ENVBLK_SIGNATURE) - sizeof (GRUB_ENVBLK_MESSAGE) + 2);
 
   if (fwrite (buf, 1, DEFAULT_ENVBLK_SIZE, fp) != DEFAULT_ENVBLK_SIZE)
     grub_util_error (_("cannot write to `%s': %s"), namenew,
-- 
2.16.4



^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2019-11-07  8:50 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-11-05  9:20 [PATCH] Warn the user to edit environment block by grub-editenv Michael Chang
2019-11-05 11:49 ` Javier Martinez Canillas
2019-11-07  8:48   ` Michael Chang
2019-11-05 11:58 ` Daniel Kiper

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.