* 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.
This commit is contained in:
Vladimir 'phcoder' Serbinenko 2012-02-10 13:26:19 +01:00
parent 45b0c8b797
commit 0809527b9d
2 changed files with 13 additions and 9 deletions

View file

@ -1,3 +1,11 @@
2012-02-10 Vladimir Serbinenko <phcoder@gmail.com>
* 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 <phcoder@gmail.com> 2012-02-10 Vladimir Serbinenko <phcoder@gmail.com>
* util/getroot.c (grub_find_device): Respect format security. * util/getroot.c (grub_find_device): Respect format security.

View file

@ -63,7 +63,7 @@ void (*argp_program_version_hook) (FILE *, struct argp_state *) = print_version;
/* Set the bug report address */ /* Set the bug report address */
const char *argp_program_bug_address = "<"PACKAGE_BUGREPORT">"; 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) switch (key)
{ {
@ -113,9 +113,7 @@ create_envblk_file (const char *name)
char *buf; char *buf;
char *namenew; char *namenew;
buf = malloc (DEFAULT_ENVBLK_SIZE); buf = xmalloc (DEFAULT_ENVBLK_SIZE);
if (! buf)
grub_util_error (_("out of memory"));
namenew = xasprintf ("%s.new", name); namenew = xasprintf ("%s.new", name);
fp = fopen (namenew, "wb"); fp = fopen (namenew, "wb");
@ -169,9 +167,7 @@ open_envblk_file (const char *name)
grub_util_error (_("cannot seek `%s': %s"), name, grub_util_error (_("cannot seek `%s': %s"), name,
strerror (errno)); strerror (errno));
buf = malloc (size); buf = xmalloc (size);
if (! buf)
grub_util_error (_("out of memory"));
if (fread (buf, 1, size, fp) != size) if (fread (buf, 1, size, fp) != size)
grub_util_error (_("cannot read `%s': %s"), name, grub_util_error (_("cannot read `%s': %s"), name,
@ -181,7 +177,7 @@ open_envblk_file (const char *name)
envblk = grub_envblk_open (buf, size); envblk = grub_envblk_open (buf, size);
if (! envblk) if (! envblk)
grub_util_error (_("invalid environment block")); grub_util_error ("%s", _("invalid environment block"));
return envblk; return envblk;
} }
@ -239,7 +235,7 @@ set_variables (const char *name, int argc, char *argv[])
*(p++) = 0; *(p++) = 0;
if (! grub_envblk_set (envblk, argv[0], p)) if (! grub_envblk_set (envblk, argv[0], p))
grub_util_error (_("environment block too small")); grub_util_error ("%s", _("environment block too small"));
argc--; argc--;
argv++; argv++;