From 0809527b9ddd41d565a3e79395405ffeacf1b8eb Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Fri, 10 Feb 2012 13:26:19 +0100 Subject: [PATCH] * util/grub-editenv.c (argp_parser): Make static. (create_envblk_file): Use xmalloc. (open_envblk_file): Likewise. Resepect format security. (set_variables): Respect format security. --- ChangeLog | 8 ++++++++ util/grub-editenv.c | 14 +++++--------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/ChangeLog b/ChangeLog index e444e15d2..e94090b34 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2012-02-10 Vladimir Serbinenko + + * util/grub-editenv.c (argp_parser): Make static. + (create_envblk_file): Use xmalloc. + (open_envblk_file): Likewise. + Resepect format security. + (set_variables): Respect format security. + 2012-02-10 Vladimir Serbinenko * util/getroot.c (grub_find_device): Respect format security. diff --git a/util/grub-editenv.c b/util/grub-editenv.c index 2a710a8fb..cb212f0b9 100644 --- a/util/grub-editenv.c +++ b/util/grub-editenv.c @@ -63,7 +63,7 @@ void (*argp_program_version_hook) (FILE *, struct argp_state *) = print_version; /* Set the bug report address */ const char *argp_program_bug_address = "<"PACKAGE_BUGREPORT">"; -error_t argp_parser (int key, char *arg, struct argp_state *state) +static error_t argp_parser (int key, char *arg, struct argp_state *state) { switch (key) { @@ -113,9 +113,7 @@ create_envblk_file (const char *name) char *buf; char *namenew; - buf = malloc (DEFAULT_ENVBLK_SIZE); - if (! buf) - grub_util_error (_("out of memory")); + buf = xmalloc (DEFAULT_ENVBLK_SIZE); namenew = xasprintf ("%s.new", name); fp = fopen (namenew, "wb"); @@ -169,9 +167,7 @@ open_envblk_file (const char *name) grub_util_error (_("cannot seek `%s': %s"), name, strerror (errno)); - buf = malloc (size); - if (! buf) - grub_util_error (_("out of memory")); + buf = xmalloc (size); if (fread (buf, 1, size, fp) != size) grub_util_error (_("cannot read `%s': %s"), name, @@ -181,7 +177,7 @@ open_envblk_file (const char *name) envblk = grub_envblk_open (buf, size); if (! envblk) - grub_util_error (_("invalid environment block")); + grub_util_error ("%s", _("invalid environment block")); return envblk; } @@ -239,7 +235,7 @@ set_variables (const char *name, int argc, char *argv[]) *(p++) = 0; if (! grub_envblk_set (envblk, argv[0], p)) - grub_util_error (_("environment block too small")); + grub_util_error ("%s", _("environment block too small")); argc--; argv++;