* util/grub-fstest.c (execute_command): Make first argument
a const char *. (read_file): Avoid shadowing. Reuse underlying error message if device open fails. (cmd_cmp): Respect format security. (root): Make const char *. (fstest): Remove args argument and use global copy. Respect format security. (argp_parser): Make static. (main): Make default_root const char *.
This commit is contained in:
parent
5d1d4e288f
commit
1b024b4ea0
2 changed files with 57 additions and 39 deletions
13
ChangeLog
13
ChangeLog
|
@ -1,3 +1,16 @@
|
||||||
|
2012-02-10 Vladimir Serbinenko <phcoder@gmail.com>
|
||||||
|
|
||||||
|
* util/grub-fstest.c (execute_command): Make first argument
|
||||||
|
a const char *.
|
||||||
|
(read_file): Avoid shadowing.
|
||||||
|
Reuse underlying error message if device open fails.
|
||||||
|
(cmd_cmp): Respect format security.
|
||||||
|
(root): Make const char *.
|
||||||
|
(fstest): Remove args argument and use global copy.
|
||||||
|
Respect format security.
|
||||||
|
(argp_parser): Make static.
|
||||||
|
(main): Make default_root const char *.
|
||||||
|
|
||||||
2012-02-10 Vladimir Serbinenko <phcoder@gmail.com>
|
2012-02-10 Vladimir Serbinenko <phcoder@gmail.com>
|
||||||
|
|
||||||
* util/grub-mount.c (root): Make const char *.
|
* util/grub-mount.c (root): Make const char *.
|
||||||
|
|
|
@ -44,7 +44,7 @@
|
||||||
#include "argp.h"
|
#include "argp.h"
|
||||||
|
|
||||||
static grub_err_t
|
static grub_err_t
|
||||||
execute_command (char *name, int n, char **args)
|
execute_command (const char *name, int n, char **args)
|
||||||
{
|
{
|
||||||
grub_command_t cmd;
|
grub_command_t cmd;
|
||||||
|
|
||||||
|
@ -77,7 +77,6 @@ read_file (char *pathname, int (*hook) (grub_off_t ofs, char *buf, int len))
|
||||||
{
|
{
|
||||||
static char buf[BUF_SIZE];
|
static char buf[BUF_SIZE];
|
||||||
grub_file_t file;
|
grub_file_t file;
|
||||||
grub_off_t ofs, len;
|
|
||||||
|
|
||||||
if ((pathname[0] == '-') && (pathname[1] == 0))
|
if ((pathname[0] == '-') && (pathname[1] == 0))
|
||||||
{
|
{
|
||||||
|
@ -85,7 +84,7 @@ read_file (char *pathname, int (*hook) (grub_off_t ofs, char *buf, int len))
|
||||||
|
|
||||||
dev = grub_device_open (0);
|
dev = grub_device_open (0);
|
||||||
if ((! dev) || (! dev->disk))
|
if ((! dev) || (! dev->disk))
|
||||||
grub_util_error (_("can\'t open device"));
|
grub_util_error ("%s", grub_errmsg);
|
||||||
|
|
||||||
grub_util_info ("total sectors : %lld",
|
grub_util_info ("total sectors : %lld",
|
||||||
(unsigned long long) dev->disk->total_sectors);
|
(unsigned long long) dev->disk->total_sectors);
|
||||||
|
@ -132,31 +131,34 @@ read_file (char *pathname, int (*hook) (grub_off_t ofs, char *buf, int len))
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ofs = skip;
|
{
|
||||||
len = file->size - skip;
|
grub_off_t ofs, len;
|
||||||
if ((leng) && (leng < len))
|
ofs = skip;
|
||||||
len = leng;
|
len = file->size - skip;
|
||||||
|
if ((leng) && (leng < len))
|
||||||
|
len = leng;
|
||||||
|
|
||||||
file->offset = skip;
|
file->offset = skip;
|
||||||
|
|
||||||
while (len)
|
while (len)
|
||||||
{
|
{
|
||||||
grub_ssize_t sz;
|
grub_ssize_t sz;
|
||||||
|
|
||||||
sz = grub_file_read (file, buf, (len > BUF_SIZE) ? BUF_SIZE : len);
|
sz = grub_file_read (file, buf, (len > BUF_SIZE) ? BUF_SIZE : len);
|
||||||
if (sz < 0)
|
if (sz < 0)
|
||||||
{
|
{
|
||||||
grub_util_error (_("read error at offset %llu: %s"), ofs,
|
grub_util_error (_("read error at offset %llu: %s"), ofs,
|
||||||
grub_errmsg);
|
grub_errmsg);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((sz == 0) || (hook (ofs, buf, sz)))
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
|
|
||||||
if ((sz == 0) || (hook (ofs, buf, sz)))
|
ofs += sz;
|
||||||
break;
|
len -= sz;
|
||||||
|
}
|
||||||
ofs += sz;
|
}
|
||||||
len -= sz;
|
|
||||||
}
|
|
||||||
|
|
||||||
grub_file_close (file);
|
grub_file_close (file);
|
||||||
}
|
}
|
||||||
|
@ -224,7 +226,8 @@ cmd_cmp (char *src, char *dest)
|
||||||
{
|
{
|
||||||
if ((int) fread (buf_1, 1, len, ff) != len)
|
if ((int) fread (buf_1, 1, len, ff) != len)
|
||||||
{
|
{
|
||||||
grub_util_error (_("read error at offset %llu: %s"), ofs, grub_errmsg);
|
grub_util_error (_("read error at offset %llu: %s"), ofs,
|
||||||
|
grub_errmsg);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -261,7 +264,7 @@ cmd_cmp (char *src, char *dest)
|
||||||
pre = ftell (ff);
|
pre = ftell (ff);
|
||||||
fseek (ff, 0, SEEK_END);
|
fseek (ff, 0, SEEK_END);
|
||||||
if (pre != ftell (ff))
|
if (pre != ftell (ff))
|
||||||
grub_util_error (_("unexpected end of file"));
|
grub_util_error ("%s", _("unexpected end of file"));
|
||||||
}
|
}
|
||||||
fclose (ff);
|
fclose (ff);
|
||||||
}
|
}
|
||||||
|
@ -300,7 +303,7 @@ cmd_crc (char *pathname)
|
||||||
grub_be_to_cpu32(*(grub_uint32_t*)GRUB_MD_CRC32->read(crc32_context)));
|
grub_be_to_cpu32(*(grub_uint32_t*)GRUB_MD_CRC32->read(crc32_context)));
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *root = NULL;
|
static const char *root = NULL;
|
||||||
static int args_count = 0;
|
static int args_count = 0;
|
||||||
static int nparm = 0;
|
static int nparm = 0;
|
||||||
static int num_disks = 1;
|
static int num_disks = 1;
|
||||||
|
@ -311,7 +314,7 @@ static char **args = NULL;
|
||||||
static int mount_crypt = 0;
|
static int mount_crypt = 0;
|
||||||
|
|
||||||
static void
|
static void
|
||||||
fstest (int n, char **args)
|
fstest (int n)
|
||||||
{
|
{
|
||||||
char *host_file;
|
char *host_file;
|
||||||
char *loop_name;
|
char *loop_name;
|
||||||
|
@ -322,11 +325,11 @@ fstest (int n, char **args)
|
||||||
char *argv[2];
|
char *argv[2];
|
||||||
loop_name = grub_xasprintf ("loop%d", i);
|
loop_name = grub_xasprintf ("loop%d", i);
|
||||||
if (!loop_name)
|
if (!loop_name)
|
||||||
grub_util_error (grub_errmsg);
|
grub_util_error ("%s", grub_errmsg);
|
||||||
|
|
||||||
host_file = grub_xasprintf ("(host)%s", images[i]);
|
host_file = grub_xasprintf ("(host)%s", images[i]);
|
||||||
if (!host_file)
|
if (!host_file)
|
||||||
grub_util_error (grub_errmsg);
|
grub_util_error ("%s", grub_errmsg);
|
||||||
|
|
||||||
argv[0] = loop_name;
|
argv[0] = loop_name;
|
||||||
argv[1] = host_file;
|
argv[1] = host_file;
|
||||||
|
@ -343,7 +346,8 @@ fstest (int n, char **args)
|
||||||
if (mount_crypt)
|
if (mount_crypt)
|
||||||
{
|
{
|
||||||
if (execute_command ("cryptomount", 1, argv))
|
if (execute_command ("cryptomount", 1, argv))
|
||||||
grub_util_error (_("`cryptomount' command fails: %s"), grub_errmsg);
|
grub_util_error (_("`cryptomount' command fails: %s"),
|
||||||
|
grub_errmsg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -395,16 +399,16 @@ fstest (int n, char **args)
|
||||||
char *argv[3] = { "-l", NULL, NULL};
|
char *argv[3] = { "-l", NULL, NULL};
|
||||||
dev = grub_device_open (n ? args[0] : 0);
|
dev = grub_device_open (n ? args[0] : 0);
|
||||||
if (!dev)
|
if (!dev)
|
||||||
grub_util_error (grub_errmsg);
|
grub_util_error ("%s", grub_errmsg);
|
||||||
fs = grub_fs_probe (dev);
|
fs = grub_fs_probe (dev);
|
||||||
if (!fs)
|
if (!fs)
|
||||||
grub_util_error (grub_errmsg);
|
grub_util_error ("%s", grub_errmsg);
|
||||||
if (!fs->uuid)
|
if (!fs->uuid)
|
||||||
grub_util_error (_("couldn't retrieve UUID"));
|
grub_util_error ("%s", _("couldn't retrieve UUID"));
|
||||||
if (fs->uuid (dev, &uuid))
|
if (fs->uuid (dev, &uuid))
|
||||||
grub_util_error (grub_errmsg);
|
grub_util_error ("%s", grub_errmsg);
|
||||||
if (!uuid)
|
if (!uuid)
|
||||||
grub_util_error (_("couldn't retrieve UUID"));
|
grub_util_error ("%s", _("couldn't retrieve UUID"));
|
||||||
argv[1] = uuid;
|
argv[1] = uuid;
|
||||||
execute_command ("xnu_uuid", 2, argv);
|
execute_command ("xnu_uuid", 2, argv);
|
||||||
grub_free (uuid);
|
grub_free (uuid);
|
||||||
|
@ -418,7 +422,7 @@ fstest (int n, char **args)
|
||||||
|
|
||||||
loop_name = grub_xasprintf ("loop%d", i);
|
loop_name = grub_xasprintf ("loop%d", i);
|
||||||
if (!loop_name)
|
if (!loop_name)
|
||||||
grub_util_error (grub_errmsg);
|
grub_util_error ("%s", grub_errmsg);
|
||||||
|
|
||||||
argv[0] = "-d";
|
argv[0] = "-d";
|
||||||
argv[1] = loop_name;
|
argv[1] = loop_name;
|
||||||
|
@ -462,7 +466,7 @@ print_version (FILE *stream, struct argp_state *state)
|
||||||
}
|
}
|
||||||
void (*argp_program_version_hook) (FILE *, struct argp_state *) = print_version;
|
void (*argp_program_version_hook) (FILE *, struct argp_state *) = print_version;
|
||||||
|
|
||||||
error_t
|
static error_t
|
||||||
argp_parser (int key, char *arg, struct argp_state *state)
|
argp_parser (int key, char *arg, struct argp_state *state)
|
||||||
{
|
{
|
||||||
char *p;
|
char *p;
|
||||||
|
@ -656,7 +660,8 @@ struct argp argp = {
|
||||||
int
|
int
|
||||||
main (int argc, char *argv[])
|
main (int argc, char *argv[])
|
||||||
{
|
{
|
||||||
char *default_root, *alloc_root;
|
const char *default_root;
|
||||||
|
char *alloc_root;
|
||||||
|
|
||||||
set_program_name (argv[0]);
|
set_program_name (argv[0]);
|
||||||
|
|
||||||
|
@ -694,7 +699,7 @@ main (int argc, char *argv[])
|
||||||
free (alloc_root);
|
free (alloc_root);
|
||||||
|
|
||||||
/* Do it. */
|
/* Do it. */
|
||||||
fstest (args_count - 1 - num_disks, args);
|
fstest (args_count - 1 - num_disks);
|
||||||
|
|
||||||
/* Free resources. */
|
/* Free resources. */
|
||||||
grub_gcry_fini_all ();
|
grub_gcry_fini_all ();
|
||||||
|
|
Loading…
Reference in a new issue