Merge upstream changes as of April 29th

This commit is contained in:
Michael Marineau 2015-07-31 15:41:48 -07:00
commit c7c750ecc2
267 changed files with 6019 additions and 1963 deletions

View file

@ -131,6 +131,8 @@ grub_acpi_get_rsdpv1 (void)
return grub_machine_acpi_get_rsdpv1 ();
}
#if defined (__i386__) || defined (__x86_64__)
static inline int
iszero (grub_uint8_t *reg, int size)
{
@ -141,7 +143,6 @@ iszero (grub_uint8_t *reg, int size)
return 1;
}
#if defined (__i386__) || defined (__x86_64__)
/* Context for grub_acpi_create_ebda. */
struct grub_acpi_create_ebda_ctx {
int ebda_len;
@ -227,7 +228,7 @@ grub_acpi_create_ebda (void)
grub_dprintf ("acpi", "Copying rsdpv2 to %p\n", target);
v2inebda = target;
target += v2->length;
target = (grub_uint8_t *) ((((grub_addr_t) target - 1) | 0xf) + 1);
target = (grub_uint8_t *) ALIGN_UP((grub_addr_t) target, 16);
v2 = 0;
break;
}
@ -246,7 +247,7 @@ grub_acpi_create_ebda (void)
grub_dprintf ("acpi", "Copying rsdpv1 to %p\n", target);
v1inebda = target;
target += sizeof (struct grub_acpi_rsdp_v10);
target = (grub_uint8_t *) ((((grub_addr_t) target - 1) | 0xf) + 1);
target = (grub_uint8_t *) ALIGN_UP((grub_addr_t) target, 16);
v1 = 0;
break;
}
@ -265,7 +266,7 @@ grub_acpi_create_ebda (void)
grub_memcpy (target, v2, v2->length);
v2inebda = target;
target += v2->length;
target = (grub_uint8_t *) ((((grub_addr_t) target - 1) | 0xf) + 1);
target = (grub_uint8_t *) ALIGN_UP((grub_addr_t) target, 16);
v2 = 0;
break;
}
@ -282,7 +283,7 @@ grub_acpi_create_ebda (void)
grub_memcpy (target, v1, sizeof (struct grub_acpi_rsdp_v10));
v1inebda = target;
target += sizeof (struct grub_acpi_rsdp_v10);
target = (grub_uint8_t *) ((((grub_addr_t) target - 1) | 0xf) + 1);
target = (grub_uint8_t *) ALIGN_UP((grub_addr_t) target, 16);
v1 = 0;
break;
}

View file

@ -23,6 +23,8 @@
#include <grub/i18n.h>
#include <grub/disk.h>
GRUB_MOD_LICENSE ("GPLv3+");
static grub_err_t
grub_rescue_cmd_info (struct grub_command *cmd __attribute__ ((unused)),
int argc __attribute__ ((unused)),

View file

@ -476,8 +476,8 @@ grub_cmd_file (grub_extcmd_context_t ctxt, int argc, char **args)
be at least 12 bytes and aligned on a 4-byte boundary. */
for (header = buffer;
((char *) header <=
(char *) buffer + len - (type == IS_MULTIBOOT2 ? 16 : 12))
|| (header = 0); header += step)
(char *) buffer + len - (type == IS_MULTIBOOT2 ? 16 : 12));
header += step)
{
if (header[0] == magic
&& !(grub_le_to_cpu32 (header[0])
@ -485,11 +485,12 @@ grub_cmd_file (grub_extcmd_context_t ctxt, int argc, char **args)
+ grub_le_to_cpu32 (header[2])
+ (type == IS_MULTIBOOT2
? grub_le_to_cpu32 (header[3]) : 0)))
break;
{
ret = 1;
break;
}
}
if (header != 0)
ret = 1;
grub_free (buffer);
break;
}

View file

@ -40,10 +40,10 @@ grub_file_check_netbsdXX (grub_elf_t elf)
return 0;
if (grub_file_seek (elf->file, elf->ehdr.ehdrXX.e_shoff) == (grub_off_t) -1)
return 0;
goto fail;
if (grub_file_read (elf->file, s0, shsize) != (grub_ssize_t) shsize)
return 0;
goto fail;
s = (Elf_Shdr *) ((char *) s0 + elf->ehdr.ehdrXX.e_shstrndx * shentsize);
stroff = s->sh_offset;
@ -54,18 +54,21 @@ grub_file_check_netbsdXX (grub_elf_t elf)
char name[sizeof(".note.netbsd.ident")];
grub_memset (name, 0, sizeof (name));
if (grub_file_seek (elf->file, stroff + s->sh_name) == (grub_off_t) -1)
return grub_errno;
goto fail;
if (grub_file_read (elf->file, name, sizeof (name)) != (grub_ssize_t) sizeof (name))
{
if (grub_errno)
return grub_errno;
goto fail;
continue;
}
if (grub_memcmp (name, ".note.netbsd.ident",
sizeof(".note.netbsd.ident")) != 0)
continue;
grub_free (s0);
return 1;
}
fail:
grub_free (s0);
return 0;
}

View file

@ -235,6 +235,8 @@ grub_cmd_gptsync (grub_command_t cmd __attribute__ ((unused)),
return grub_errno;
}
grub_device_close (dev);
grub_printf_ (N_("New MBR is written to `%s'\n"), args[0]);
return GRUB_ERR_NONE;

View file

@ -329,6 +329,7 @@ grub_cmd_hdparm (grub_extcmd_context_t ctxt, int argc, char **args)
break;
}
default:
grub_disk_close (disk);
return grub_error (GRUB_ERR_IO, "not an ATA device");
}

View file

@ -107,6 +107,14 @@ grub_cmd_play (grub_command_t cmd __attribute__ ((unused)),
return grub_errno;
}
if (!tempo)
{
grub_file_close (file);
grub_error (GRUB_ERR_BAD_ARGUMENT, N_("Invalid tempo in %s"),
args[0]);
return grub_errno;
}
tempo = grub_le_to_cpu32 (tempo);
grub_dprintf ("play","tempo = %d\n", tempo);
@ -131,6 +139,13 @@ grub_cmd_play (grub_command_t cmd __attribute__ ((unused)),
tempo = grub_strtoul (args[0], &end, 0);
if (!tempo)
{
grub_error (GRUB_ERR_BAD_ARGUMENT, N_("Invalid tempo in %s"),
args[0]);
return grub_errno;
}
if (*end)
/* Was not a number either, assume it was supposed to be a file name. */
return grub_error (GRUB_ERR_FILE_NOT_FOUND, N_("file `%s' not found"), args[0]);

View file

@ -292,7 +292,7 @@ find_key_code (char *key)
{
unsigned i;
for (i = 0; i < sizeof (keysym_table) / sizeof (keysym_table[0]); i++)
for (i = 0; i < ARRAY_SIZE(keysym_table); i++)
{
if (keysym_table[i].unshifted_name
&& grub_strcmp (key, keysym_table[i].unshifted_name) == 0)
@ -311,7 +311,7 @@ find_ascii_code (char *key)
{
unsigned i;
for (i = 0; i < sizeof (keysym_table) / sizeof (keysym_table[0]); i++)
for (i = 0; i < ARRAY_SIZE(keysym_table); i++)
{
if (keysym_table[i].unshifted_name
&& grub_strcmp (key, keysym_table[i].unshifted_name) == 0)
@ -352,15 +352,13 @@ grub_cmd_sendkey (grub_extcmd_context_t ctxt, int argc, char **args)
{
unsigned i;
for (i = 0; i < sizeof (simple_flag_offsets)
/ sizeof (simple_flag_offsets[0]); i++)
for (i = 0; i < ARRAY_SIZE(simple_flag_offsets); i++)
grub_sendkey_set_simple_flag (simple_flag_offsets[i],
grub_sendkey_parse_op(state[i]));
}
/* Set noled. */
noled = (state[sizeof (simple_flag_offsets)
/ sizeof (simple_flag_offsets[0])].set);
noled = (state[ARRAY_SIZE(simple_flag_offsets)].set);
return GRUB_ERR_NONE;
}

View file

@ -57,14 +57,20 @@ legacy_file (const char *filename)
file = grub_file_open (filename);
if (! file)
return grub_errno;
{
grub_free (suffix);
return grub_errno;
}
menu = grub_env_get_menu ();
if (! menu)
{
menu = grub_zalloc (sizeof (*menu));
if (! menu)
return grub_errno;
{
grub_free (suffix);
return grub_errno;
}
grub_env_set_menu (menu);
}
@ -77,6 +83,7 @@ legacy_file (const char *filename)
if (!buf && grub_errno)
{
grub_file_close (file);
grub_free (suffix);
return grub_errno;
}
@ -173,6 +180,8 @@ legacy_file (const char *filename)
if (!args)
{
grub_file_close (file);
grub_free (suffix);
grub_free (entrysrc);
return grub_errno;
}
args[0] = entryname;
@ -376,6 +385,8 @@ grub_cmd_legacy_kernel (struct grub_command *mycmd __attribute__ ((unused)),
if (part && grub_strcmp (part->partmap->name, "msdos") == 0)
bsd_slice = part->number;
}
if (dev)
grub_device_close (dev);
}
/* k*BSD didn't really work well with grub-legacy. */

View file

@ -106,7 +106,7 @@ grub_mac_bless_inode (grub_device_t dev, grub_uint32_t inode, int is_dir,
ablk_size = grub_be_to_cpu32 (volheader.hfs.blksz);
ablk_start = grub_be_to_cpu16 (volheader.hfs.first_block);
embedded_offset = (ablk_start
+ extent_start
+ ((grub_uint64_t) extent_start)
* (ablk_size >> GRUB_DISK_SECTOR_BITS));
err =
@ -183,7 +183,7 @@ grub_cmd_macbless (grub_command_t cmd, int argc, char **args)
{
char *device_name;
char *path = 0;
grub_device_t dev;
grub_device_t dev = 0;
grub_err_t err;
if (argc != 1)
@ -197,13 +197,12 @@ grub_cmd_macbless (grub_command_t cmd, int argc, char **args)
else
path = path + 1;
if (!path || *path == 0 || !device_name)
if (!path || *path == 0 || !dev)
{
if (dev)
grub_device_close (dev);
grub_free (device_name);
grub_free (path);
return grub_error (GRUB_ERR_BAD_ARGUMENT, "invalid argument");
}

View file

@ -57,6 +57,7 @@ get_uuid (const char *name, char **uuid, int getnative)
if (!dev->disk)
{
grub_dprintf ("nativedisk", "Skipping non-disk\n");
grub_device_close (dev);
return 0;
}
@ -90,6 +91,7 @@ get_uuid (const char *name, char **uuid, int getnative)
case GRUB_DISK_DEVICE_MEMDISK_ID:
grub_dprintf ("nativedisk", "Skipping native disk %s\n",
dev->disk->name);
grub_device_close (dev);
return 0;
/* FIXME: those probably need special handling. */

View file

@ -243,11 +243,19 @@ grub_cmd_parttool (grub_command_t cmd __attribute__ ((unused)),
}
if (argc == 1)
return show_help (dev);
{
err = show_help (dev);
grub_device_close (dev);
return err;
}
for (i = 1; i < argc; i++)
if (grub_strcmp (args[i], "help") == 0)
return show_help (dev);
{
err = show_help (dev);
grub_device_close (dev);
return err;
}
parsed = (int *) grub_zalloc (argc * sizeof (int));
@ -274,8 +282,11 @@ grub_cmd_parttool (grub_command_t cmd __attribute__ ((unused)),
break;
}
if (! cur)
return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("unknown argument `%s'"),
{
grub_device_close (dev);
return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("unknown argument `%s'"),
args[i]);
}
ptool = cur;
pargs = (struct grub_parttool_args *)
grub_zalloc (ptool->nargs * sizeof (struct grub_parttool_args));

View file

@ -119,7 +119,10 @@ syslinux_file (grub_extcmd_context_t ctxt, const char *filename)
{
menu = grub_zalloc (sizeof (*menu));
if (! menu)
return grub_errno;
{
grub_free (result);
return grub_errno;
}
grub_env_set_menu (menu);
}

View file

@ -332,7 +332,7 @@ test_parse (char **args, int *argn, int argc)
get_fileinfo (args[*argn + 1], &ctx);
update_val (ctx.file_exists && ctx.file_info.dir, &ctx);
(*argn) += 2;
return ctx.or || ctx.and;
continue;
}
if (grub_strcmp (args[*argn], "-e") == 0)
@ -340,7 +340,7 @@ test_parse (char **args, int *argn, int argc)
get_fileinfo (args[*argn + 1], &ctx);
update_val (ctx.file_exists, &ctx);
(*argn) += 2;
return ctx.or || ctx.and;
continue;
}
if (grub_strcmp (args[*argn], "-f") == 0)
@ -349,7 +349,7 @@ test_parse (char **args, int *argn, int argc)
/* FIXME: check for other types. */
update_val (ctx.file_exists && ! ctx.file_info.dir, &ctx);
(*argn) += 2;
return ctx.or || ctx.and;
continue;
}
if (grub_strcmp (args[*argn], "-s") == 0)
@ -362,7 +362,7 @@ test_parse (char **args, int *argn, int argc)
grub_file_close (file);
grub_errno = GRUB_ERR_NONE;
(*argn) += 2;
return ctx.or || ctx.and;
continue;
}
/* String tests. */

View file

@ -80,7 +80,7 @@ grub_cmd_tr (grub_extcmd_context_t ctxt, int argc, char **args)
} else if (argc > 3)
return grub_error (GRUB_ERR_BAD_ARGUMENT, "too many parameters");
if (argc <= 0 && (!s1 || !s2 || !input))
if (!s1 || !s2 || !input)
return grub_error (GRUB_ERR_BAD_ARGUMENT, "missing parameters");
if (grub_strlen (s1) != grub_strlen (s2))

View file

@ -33,6 +33,13 @@
GRUB_MOD_LICENSE ("GPLv3+");
struct grub_verified
{
grub_file_t file;
void *buf;
};
typedef struct grub_verified *grub_verified_t;
enum
{
OPTION_SKIP_SIG = 0
@ -301,7 +308,7 @@ grub_load_public_key (grub_file_t f)
if (!sk)
goto fail;
grub_memset (fingerprint_context, 0, sizeof (fingerprint_context));
grub_memset (fingerprint_context, 0, GRUB_MD_SHA1->contextsize);
GRUB_MD_SHA1->init (fingerprint_context);
GRUB_MD_SHA1->write (fingerprint_context, "\x99", 1);
len_be = grub_cpu_to_be16 (len);
@ -447,7 +454,7 @@ grub_verify_signature_real (char *buf, grub_size_t size,
grub_err_t err;
grub_size_t i;
gcry_mpi_t mpis[10];
grub_uint8_t type;
grub_uint8_t type = 0;
err = read_packet_header (sig, &type, &len);
if (err)
@ -802,19 +809,39 @@ grub_cmd_verify_signature (grub_extcmd_context_t ctxt,
static int sec = 0;
static void
verified_free (grub_verified_t verified)
{
if (verified)
{
grub_free (verified->buf);
grub_free (verified);
}
}
static grub_ssize_t
verified_read (struct grub_file *file, char *buf, grub_size_t len)
{
grub_memcpy (buf, (char *) file->data + file->offset, len);
grub_verified_t verified = file->data;
grub_memcpy (buf, (char *) verified->buf + file->offset, len);
return len;
}
static grub_err_t
verified_close (struct grub_file *file)
{
grub_free (file->data);
grub_verified_t verified = file->data;
grub_file_close (verified->file);
verified_free (verified);
file->data = 0;
return GRUB_ERR_NONE;
/* device and name are freed by parent */
file->device = 0;
file->name = 0;
return grub_errno;
}
struct grub_fs verified_fs =
@ -832,6 +859,7 @@ grub_pubkey_open (grub_file_t io, const char *filename)
grub_err_t err;
grub_file_filter_t curfilt[GRUB_FILE_FILTER_MAX];
grub_file_t ret;
grub_verified_t verified;
if (!sec)
return io;
@ -857,7 +885,10 @@ grub_pubkey_open (grub_file_t io, const char *filename)
ret = grub_malloc (sizeof (*ret));
if (!ret)
return NULL;
{
grub_file_close (sig);
return NULL;
}
*ret = *io;
ret->fs = &verified_fs;
@ -866,29 +897,46 @@ grub_pubkey_open (grub_file_t io, const char *filename)
{
grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
"big file signature isn't implemented yet");
return NULL;
}
ret->data = grub_malloc (ret->size);
if (!ret->data)
{
grub_file_close (sig);
grub_free (ret);
return NULL;
}
if (grub_file_read (io, ret->data, ret->size) != (grub_ssize_t) ret->size)
verified = grub_malloc (sizeof (*verified));
if (!verified)
{
grub_file_close (sig);
grub_free (ret);
return NULL;
}
verified->buf = grub_malloc (ret->size);
if (!verified->buf)
{
grub_file_close (sig);
grub_free (verified);
grub_free (ret);
return NULL;
}
if (grub_file_read (io, verified->buf, ret->size) != (grub_ssize_t) ret->size)
{
if (!grub_errno)
grub_error (GRUB_ERR_FILE_READ_ERROR, N_("premature end of file %s"),
filename);
grub_file_close (sig);
verified_free (verified);
grub_free (ret);
return NULL;
}
err = grub_verify_signature_real (ret->data, ret->size, 0, sig, NULL);
err = grub_verify_signature_real (verified->buf, ret->size, 0, sig, NULL);
grub_file_close (sig);
if (err)
return NULL;
io->device = 0;
io->name = 0;
grub_file_close (io);
{
verified_free (verified);
grub_free (ret);
return NULL;
}
verified->file = io;
ret->data = verified;
return ret;
}

View file

@ -245,7 +245,10 @@ match_devices_iter (const char *name, void *data)
t = grub_realloc (ctx->devs, sizeof (char*) * (ctx->ndev + 2));
if (! t)
return 1;
{
grub_free (buffer);
return 1;
}
ctx->devs = t;
ctx->devs[ctx->ndev++] = buffer;
@ -290,7 +293,8 @@ struct match_files_ctx
/* Helper for match_files. */
static int
match_files_iter (const char *name, const struct grub_dirhook_info *info,
match_files_iter (const char *name,
const struct grub_dirhook_info *info __attribute__((unused)),
void *data)
{
struct match_files_ctx *ctx = data;