From 2e4659b810801d537f177ab43df6c07574dd0a2e Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 20 Oct 2013 23:45:43 +0200 Subject: [PATCH] * grub-core/loader/i386/bsd.c: Remove variable length arrays. --- ChangeLog | 4 ++++ grub-core/loader/i386/bsd.c | 31 +++++++++++++++++++++++-------- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index 4cc433a3c..9339da619 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2013-10-20 Vladimir Serbinenko + + * grub-core/loader/i386/bsd.c: Remove variable length arrays. + 2013-10-20 Vladimir Serbinenko * grub-core/fs/ufs.c: Remove variable length arrays. diff --git a/grub-core/loader/i386/bsd.c b/grub-core/loader/i386/bsd.c index 5143813fe..9e8592996 100644 --- a/grub-core/loader/i386/bsd.c +++ b/grub-core/loader/i386/bsd.c @@ -216,8 +216,8 @@ grub_bsd_get_device (grub_uint32_t * biosdev, grub_device_close (dev); } -grub_err_t -grub_bsd_add_meta (grub_uint32_t type, const void *data, grub_uint32_t len) +static grub_err_t +grub_bsd_add_meta_ptr (grub_uint32_t type, void **ptr, grub_uint32_t len) { struct bsd_tag *newtag; @@ -227,8 +227,7 @@ grub_bsd_add_meta (grub_uint32_t type, const void *data, grub_uint32_t len) newtag->len = len; newtag->type = type; newtag->next = NULL; - if (len) - grub_memcpy (newtag->data, data, len); + *ptr = newtag->data; if (kernel_type == KERNEL_TYPE_FREEBSD && type == (FREEBSD_MODINFO_METADATA | FREEBSD_MODINFOMD_SMAP)) @@ -257,6 +256,21 @@ grub_bsd_add_meta (grub_uint32_t type, const void *data, grub_uint32_t len) return GRUB_ERR_NONE; } +grub_err_t +grub_bsd_add_meta (grub_uint32_t type, const void *data, grub_uint32_t len) +{ + grub_err_t err; + void *ptr; + + err = grub_bsd_add_meta_ptr (type, &ptr, len); + if (err) + return err; + if (len) + grub_memcpy (ptr, data, len); + return GRUB_ERR_NONE; +} + + struct grub_e820_mmap { grub_uint64_t addr; @@ -440,7 +454,11 @@ grub_freebsd_add_meta_module (const char *filename, const char *type, if (n) { - char cmdline[n], *p; + void *cmdline; + char *p; + + if (grub_bsd_add_meta_ptr (FREEBSD_MODINFO_ARGS, &cmdline, n)) + return grub_errno; p = cmdline; for (i = 0; i < argc; i++) @@ -450,9 +468,6 @@ grub_freebsd_add_meta_module (const char *filename, const char *type, *(p++) = ' '; } *p = 0; - - if (grub_bsd_add_meta (FREEBSD_MODINFO_ARGS, cmdline, n)) - return grub_errno; } }