From 393324be7c27ee65c3f07de5b5e56f001b8a9ed3 Mon Sep 17 00:00:00 2001 From: BVK Chaitanya Date: Wed, 8 Dec 2010 16:43:11 +0530 Subject: [PATCH 01/15] execute menu editor commands with argument scope --- grub-core/normal/menu_entry.c | 59 +++++++++++++++++------------------ 1 file changed, 28 insertions(+), 31 deletions(-) diff --git a/grub-core/normal/menu_entry.c b/grub-core/normal/menu_entry.c index 0bb51ca28..4db4a45c1 100644 --- a/grub-core/normal/menu_entry.c +++ b/grub-core/normal/menu_entry.c @@ -1163,37 +1163,35 @@ clear_completions_all (struct screen *screen) static int run (struct screen *screen) { - int currline = 0; - char *nextline; + char *script; int errs_before; grub_menu_t menu; + char *dummy[1] = { NULL }; - auto grub_err_t editor_getline (char **line, int cont); - grub_err_t editor_getline (char **line, int cont __attribute__ ((unused))) - { - struct line *linep = screen->lines + currline; - char *p; + auto char * editor_getsource (void); + char * editor_getsource (void) + { + int i; + int size = 0; + char *source; - if (currline > screen->num_lines) - { - *line = 0; - return 0; - } + for (i = 0; i < screen->num_lines; i++) + size += screen->lines[i].len + 1; - /* Trim down space characters. */ - for (p = linep->buf + linep->len - 1; - p >= linep->buf && grub_isspace (*p); - p--) - ; - *++p = '\0'; + source = grub_malloc (size + 1); + if (! source) + return NULL; - linep->len = p - linep->buf; - for (p = linep->buf; grub_isspace (*p); p++) - ; - *line = grub_strdup (p); - currline++; - return 0; - } + size = 0; + for (i = 0; i < screen->num_lines; i++) + { + grub_strcpy (source + size, screen->lines[i].buf); + size += screen->lines[i].len; + source[size++] = '\n'; + } + source[size] = '\0'; + return source; + } grub_cls (); grub_printf (" "); @@ -1212,12 +1210,11 @@ run (struct screen *screen) } /* Execute the script, line for line. */ - while (currline < screen->num_lines) - { - editor_getline (&nextline, 0); - if (grub_normal_parse_line (nextline, editor_getline)) - break; - } + script = editor_getsource (); + if (! script) + return 0; + grub_script_execute_sourcecode (script, 0, dummy); + grub_free (script); if (errs_before != grub_err_printed_errors) grub_wait_after_message (); From b04298cfa29418564bd86fd1053fb681000966bc Mon Sep 17 00:00:00 2001 From: kashyap garimella Date: Sat, 18 Dec 2010 15:22:11 +0100 Subject: [PATCH 02/15] * grub-core/loader/i386/multiboot_mbi.c (grub_multiboot_load): Use correct cat to grub_uint8_t * rather than grub_uint32_t *. --- ChangeLog | 5 +++++ grub-core/loader/i386/multiboot_mbi.c | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index abd1d0400..254c8303a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2010-12-18 kashyap garimella + + * grub-core/loader/i386/multiboot_mbi.c (grub_multiboot_load): Use + correct cat to grub_uint8_t * rather than grub_uint32_t *. + 2010-12-10 Colin Watson * .bzrignore: Ignore grub-core/rs_decoder.S. diff --git a/grub-core/loader/i386/multiboot_mbi.c b/grub-core/loader/i386/multiboot_mbi.c index 79f72ee0f..e3f328494 100644 --- a/grub-core/loader/i386/multiboot_mbi.c +++ b/grub-core/loader/i386/multiboot_mbi.c @@ -141,7 +141,7 @@ grub_multiboot_load (grub_file_t file) } if (header->bss_end_addr) - grub_memset ((grub_uint32_t *) source + load_size, 0, + grub_memset ((grub_uint8_t *) source + load_size, 0, header->bss_end_addr - header->load_addr - load_size); grub_multiboot_payload_eip = header->entry_addr; From e1dffcf2705db474dd3a59d8a514598af878da19 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 18 Dec 2010 14:31:05 +0100 Subject: [PATCH 03/15] * grub-core/loader/i386/multiboot_mbi.c (grub_multiboot_make_mbi): Set ptrdest to correct get_physical_target_address rather than incorrect get_virtual_current_address. --- ChangeLog | 6 ++++++ grub-core/loader/i386/multiboot_mbi.c | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 254c8303a..d7091f27c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2010-12-18 Vladimir Serbinenko + + * grub-core/loader/i386/multiboot_mbi.c (grub_multiboot_make_mbi): + Set ptrdest to correct get_physical_target_address rather than + incorrect get_virtual_current_address. + 2010-12-18 kashyap garimella * grub-core/loader/i386/multiboot_mbi.c (grub_multiboot_load): Use diff --git a/grub-core/loader/i386/multiboot_mbi.c b/grub-core/loader/i386/multiboot_mbi.c index e3f328494..7015666fc 100644 --- a/grub-core/loader/i386/multiboot_mbi.c +++ b/grub-core/loader/i386/multiboot_mbi.c @@ -441,7 +441,7 @@ grub_multiboot_make_mbi (grub_uint32_t *target) if (err) return err; ptrorig = get_virtual_current_address (ch); - ptrdest = (grub_addr_t) get_virtual_current_address (ch); + ptrdest = get_physical_target_address (ch); *target = ptrdest; From 32570200a8bb64856c3125fecfc79b9467dddb50 Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Sat, 18 Dec 2010 17:37:48 +0000 Subject: [PATCH 04/15] * grub-core/normal/term.c (print_more): Make \r or \n scroll one line, and other keys scroll an entire page (previous handling was for \r and \n to scroll a page and other keys to scroll two lines). --- ChangeLog | 6 ++++++ grub-core/normal/term.c | 8 ++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index d7091f27c..3f15bcc7b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2010-12-18 Colin Watson + + * grub-core/normal/term.c (print_more): Make \r or \n scroll one + line, and other keys scroll an entire page (previous handling was + for \r and \n to scroll a page and other keys to scroll two lines). + 2010-12-18 Vladimir Serbinenko * grub-core/loader/i386/multiboot_mbi.c (grub_multiboot_make_mbi): diff --git a/grub-core/normal/term.c b/grub-core/normal/term.c index 00721c447..a1aa3d783 100644 --- a/grub-core/normal/term.c +++ b/grub-core/normal/term.c @@ -91,16 +91,16 @@ print_more (void) grub_term_restore_pos (pos); grub_free (pos); - /* Scroll one lines or an entire page, depending on the key. */ + /* Scroll one line or an entire page, depending on the key. */ if (key == '\r' || key =='\n') - grub_normal_reset_more (); - else { static struct term_state *state; for (state = term_states; state; state = state->next) - state->num_lines -= 2; + state->num_lines--; } + else + grub_normal_reset_more (); } void From 5cf86f4b0fadf4fbe8780cf5d4592b81e86158b4 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 18 Dec 2010 22:47:50 +0100 Subject: [PATCH 05/15] * util/grub-mkfont.c (main): Handle errors from FT_Set_Pixel_Sizes. --- ChangeLog | 4 ++++ util/grub-mkfont.c | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index bc5e26582..1012833a0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -4,6 +4,10 @@ editor under argument scope. Reported by: Jordan Uggla +2010-12-18 Vladimir Serbinenko + + * util/grub-mkfont.c (main): Handle errors from FT_Set_Pixel_Sizes. + 2010-12-18 Colin Watson * grub-core/normal/term.c (print_more): Make \r or \n scroll one diff --git a/util/grub-mkfont.c b/util/grub-mkfont.c index 3e24380d1..fff6a619e 100644 --- a/util/grub-mkfont.c +++ b/util/grub-mkfont.c @@ -1170,7 +1170,8 @@ main (int argc, char *argv[]) font_info.style = ft_face->style_flags; font_info.size = size; - FT_Set_Pixel_Sizes (ft_face, size, size); + if (FT_Set_Pixel_Sizes (ft_face, size, size)) + grub_util_error ("can't set %dx%d font size", size, size); add_font (&font_info, ft_face, file_format != PF2); FT_Done_Face (ft_face); } From 7059d1ec14f7c5c44623688a7960050be9c585e0 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 19 Dec 2010 00:43:41 +0100 Subject: [PATCH 06/15] Fix handling of UTF-16 UDF labels. * grub-core/fs/udf.c (grub_udf_iterate_dir): Move string-parsing part (read_string): .. here. (grub_udf_label): Use read_string. --- ChangeLog | 8 ++++++ grub-core/fs/udf.c | 70 +++++++++++++++++++++++++++++++--------------- 2 files changed, 55 insertions(+), 23 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1012833a0..333b24ab2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2010-12-19 Vladimir Serbinenko + + Fix handling of UTF-16 UDF labels. + + * grub-core/fs/udf.c (grub_udf_iterate_dir): Move string-parsing part + (read_string): .. here. + (grub_udf_label): Use read_string. + 2010-12-19 BVK Chaitanya * grub-core/normal/menu_entry.c (run): Execute commands from menu diff --git a/grub-core/fs/udf.c b/grub-core/fs/udf.c index 7041e619e..51726edf3 100644 --- a/grub-core/fs/udf.c +++ b/grub-core/fs/udf.c @@ -788,6 +788,43 @@ fail: return 0; } +static char * +read_string (grub_uint8_t *raw, grub_size_t sz) +{ + grub_uint16_t *utf16; + char *ret; + grub_size_t utf16len = 0; + + if (raw[0] != 8 && raw[0] != 16) + return NULL; + + if (raw[0] == 8) + { + unsigned i; + utf16len = sz - 1; + utf16 = grub_malloc (utf16len * sizeof (utf16[0])); + if (!utf16) + return NULL; + for (i = 0; i < utf16len; i++) + utf16[i] = raw[i + 1]; + } + if (raw[0] == 16) + { + unsigned i; + utf16len = (sz - 1) / 2; + utf16 = grub_malloc (utf16len * sizeof (utf16[0])); + if (!utf16) + return NULL; + for (i = 0; i < utf16len; i++) + utf16[i] = (raw[2 * i + 1] << 8) | raw[2*i + 2]; + } + ret = grub_malloc (utf16len * 3 + 1); + if (ret) + *grub_utf16_to_utf8 ((grub_uint8_t *) ret, utf16, utf16len) = '\0'; + grub_free (utf16); + return ret; +} + static int grub_udf_iterate_dir (grub_fshelp_node_t dir, int NESTED_FUNC_ATTR @@ -841,10 +878,8 @@ grub_udf_iterate_dir (grub_fshelp_node_t dir, else { enum grub_fshelp_filetype type; + char *filename; grub_uint8_t raw[dirent.file_ident_length]; - grub_uint16_t utf16[dirent.file_ident_length - 1]; - grub_uint8_t filename[dirent.file_ident_length * 2]; - grub_size_t utf16len = 0; type = ((dirent.characteristics & GRUB_UDF_FID_CHAR_DIRECTORY) ? (GRUB_FSHELP_DIR) : (GRUB_FSHELP_REG)); @@ -855,27 +890,16 @@ grub_udf_iterate_dir (grub_fshelp_node_t dir, != dirent.file_ident_length) return 0; - if (raw[0] == 8) - { - unsigned i; - utf16len = dirent.file_ident_length - 1; - for (i = 0; i < utf16len; i++) - utf16[i] = raw[i + 1]; - } - if (raw[0] == 16) - { - unsigned i; - utf16len = (dirent.file_ident_length - 1) / 2; - for (i = 0; i < utf16len; i++) - utf16[i] = (raw[2 * i + 1] << 8) | raw[2*i + 2]; - } - if (raw[0] == 8 || raw[0] == 16) - { - *grub_utf16_to_utf8 (filename, utf16, utf16len) = '\0'; + filename = read_string (raw, dirent.file_ident_length); + if (!filename) + grub_print_error (); - if (hook ((char *) filename, type, child)) - return 1; + if (filename && hook (filename, type, child)) + { + grub_free (filename); + return 1; } + grub_free (filename); } } @@ -1004,7 +1028,7 @@ grub_udf_label (grub_device_t device, char **label) if (data) { - *label = grub_strdup ((char *) &data->lvd.ident[1]); + *label = read_string (data->lvd.ident, sizeof (data->lvd.ident)); grub_free (data); } else From a2a08a35bf2a6603b9c0ee5dc3e224f41373258c Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 19 Dec 2010 00:49:52 +0100 Subject: [PATCH 07/15] * grub-core/fs/affs.c (grub_affs_fs) [GRUB_UTIL]: Explicitly set reserved_first_sector to 0. * grub-core/fs/cpio.c (grub_cpio_fs) [GRUB_UTIL]: Likewise. * grub-core/fs/sfs.c (grub_sfs_fs) [GRUB_UTIL]: Likewise. * grub-core/fs/xfs.c (grub_xfs_fs) [GRUB_UTIL]: Likewise. --- ChangeLog | 8 ++++++++ grub-core/fs/affs.c | 3 +++ grub-core/fs/cpio.c | 3 +++ grub-core/fs/sfs.c | 3 +++ grub-core/fs/xfs.c | 3 +++ 5 files changed, 20 insertions(+) diff --git a/ChangeLog b/ChangeLog index 333b24ab2..99cf2cd7f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2010-12-19 Vladimir Serbinenko + + * grub-core/fs/affs.c (grub_affs_fs) [GRUB_UTIL]: Explicitly set + reserved_first_sector to 0. + * grub-core/fs/cpio.c (grub_cpio_fs) [GRUB_UTIL]: Likewise. + * grub-core/fs/sfs.c (grub_sfs_fs) [GRUB_UTIL]: Likewise. + * grub-core/fs/xfs.c (grub_xfs_fs) [GRUB_UTIL]: Likewise. + 2010-12-19 Vladimir Serbinenko Fix handling of UTF-16 UDF labels. diff --git a/grub-core/fs/affs.c b/grub-core/fs/affs.c index 3dc80752d..27e03c0c4 100644 --- a/grub-core/fs/affs.c +++ b/grub-core/fs/affs.c @@ -535,6 +535,9 @@ static struct grub_fs grub_affs_fs = .read = grub_affs_read, .close = grub_affs_close, .label = grub_affs_label, +#ifdef GRUB_UTIL + .reserved_first_sector = 0, +#endif .next = 0 }; diff --git a/grub-core/fs/cpio.c b/grub-core/fs/cpio.c index c087b4f90..2c92404c3 100644 --- a/grub-core/fs/cpio.c +++ b/grub-core/fs/cpio.c @@ -354,6 +354,9 @@ static struct grub_fs grub_cpio_fs = { .open = grub_cpio_open, .read = grub_cpio_read, .close = grub_cpio_close, +#ifdef GRUB_UTIL + .reserved_first_sector = 0, +#endif }; #ifdef MODE_USTAR diff --git a/grub-core/fs/sfs.c b/grub-core/fs/sfs.c index 4a5005908..b49420de1 100644 --- a/grub-core/fs/sfs.c +++ b/grub-core/fs/sfs.c @@ -579,6 +579,9 @@ static struct grub_fs grub_sfs_fs = .read = grub_sfs_read, .close = grub_sfs_close, .label = grub_sfs_label, +#ifdef GRUB_UTIL + .reserved_first_sector = 0, +#endif .next = 0 }; diff --git a/grub-core/fs/xfs.c b/grub-core/fs/xfs.c index 9dffe31d1..3d773856e 100644 --- a/grub-core/fs/xfs.c +++ b/grub-core/fs/xfs.c @@ -808,6 +808,9 @@ static struct grub_fs grub_xfs_fs = .close = grub_xfs_close, .label = grub_xfs_label, .uuid = grub_xfs_uuid, +#ifdef GRUB_UTIL + .reserved_first_sector = 0, +#endif .next = 0 }; From 6c85b743f5c3a07c400ffd798e87cbcf2d3ab64d Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 19 Dec 2010 00:52:18 +0100 Subject: [PATCH 08/15] * grub-core/fs/affs.c (grub_affs_mount): Read data->bblock.rootblock rather than assuming than rootblock is exactly in the middle. (grub_affs_label): Likewise. --- ChangeLog | 6 ++++++ grub-core/fs/affs.c | 6 +++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 99cf2cd7f..12836d9af 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2010-12-19 Vladimir Serbinenko + + * grub-core/fs/affs.c (grub_affs_mount): Read data->bblock.rootblock + rather than assuming than rootblock is exactly in the middle. + (grub_affs_label): Likewise. + 2010-12-19 Vladimir Serbinenko * grub-core/fs/affs.c (grub_affs_fs) [GRUB_UTIL]: Explicitly set diff --git a/grub-core/fs/affs.c b/grub-core/fs/affs.c index 27e03c0c4..40be4b2f6 100644 --- a/grub-core/fs/affs.c +++ b/grub-core/fs/affs.c @@ -208,7 +208,7 @@ grub_affs_mount (grub_disk_t disk) rblock = (struct grub_affs_rblock *) rootblock; /* Read the rootblock. */ - grub_disk_read (disk, (disk->total_sectors >> 1) + blocksize, 0, + grub_disk_read (disk, grub_be_to_cpu32 (data->bblock.rootblock), 0, GRUB_DISK_SECTOR_SIZE * 16, rootblock); if (grub_errno) goto fail; @@ -240,7 +240,7 @@ grub_affs_mount (grub_disk_t disk) data->disk = disk; data->htsize = grub_be_to_cpu32 (rblock->htsize); data->diropen.data = data; - data->diropen.block = (disk->total_sectors >> 1); + data->diropen.block = grub_be_to_cpu32 (data->bblock.rootblock); grub_free (rootblock); @@ -507,7 +507,7 @@ grub_affs_label (grub_device_t device, char **label) { /* The rootblock maps quite well on a file header block, it's something we can use here. */ - grub_disk_read (data->disk, disk->total_sectors >> 1, + grub_disk_read (data->disk, grub_be_to_cpu32 (data->bblock.rootblock), data->blocksize * (GRUB_DISK_SECTOR_SIZE - GRUB_AFFS_FILE_LOCATION), sizeof (file), &file); From 5318fe9804f1e95e2d04186f4bf28562c8cfaf5e Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Mon, 20 Dec 2010 16:13:01 +0100 Subject: [PATCH 09/15] * grub-core/loader/i386/multiboot_mbi.c (grub_multiboot_add_module): Avoid next pointing to nowhere. --- ChangeLog | 5 +++++ grub-core/loader/i386/multiboot_mbi.c | 1 + 2 files changed, 6 insertions(+) diff --git a/ChangeLog b/ChangeLog index 12836d9af..6e564324b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2010-12-20 Vladimir Serbinenko + + * grub-core/loader/i386/multiboot_mbi.c (grub_multiboot_add_module): + Avoid next pointing to nowhere. + 2010-12-19 Vladimir Serbinenko * grub-core/fs/affs.c (grub_affs_mount): Read data->bblock.rootblock diff --git a/grub-core/loader/i386/multiboot_mbi.c b/grub-core/loader/i386/multiboot_mbi.c index 7015666fc..eade78e93 100644 --- a/grub-core/loader/i386/multiboot_mbi.c +++ b/grub-core/loader/i386/multiboot_mbi.c @@ -641,6 +641,7 @@ grub_multiboot_add_module (grub_addr_t start, grub_size_t size, return grub_errno; newmod->start = start; newmod->size = size; + newmod->next = 0; for (i = 0; i < argc; i++) len += grub_strlen (argv[i]) + 1; From 4e01b6c821b46c83b19a22b7ecd0207780c90ab0 Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Tue, 21 Dec 2010 12:49:29 +0000 Subject: [PATCH 10/15] * util/grub-mkconfig_lib.in (gettext_quoted): Add clarifying comment. Add an extra layer of quotation, requiring the output of this function to be used in a printf format string. (gettext_printf): New function. * util/grub.d/10_hurd.in: Use gettext_printf where appropriate. Extract translatable strings from here-documents and use a temporary variable instead, so that xgettext can find them. * util/grub.d/10_kfreebsd.in: Likewise. * util/grub.d/10_linux.in: Likewise. * util/grub.d/20_linux_xen.in: Likewise. * po/grub.d.sed: New file. * po/Makefile.in.in ($(DOMAIN).pot-update): Extract gettext_printf arguments. Set c-format flags on all strings extracted from util/grub.d/ (xgettext refuses to include these itself for strings it extracted from a shell file, but these really are c-format). --- ChangeLog | 19 +++++++++++++++++++ po/Makefile.in.in | 8 ++++++-- po/grub.d.sed | 2 ++ util/grub-mkconfig_lib.in | 14 +++++++++++++- util/grub.d/10_hurd.in | 12 ++++++++---- util/grub.d/10_kfreebsd.in | 3 ++- util/grub.d/10_linux.in | 6 ++++-- util/grub.d/20_linux_xen.in | 6 ++++-- 8 files changed, 58 insertions(+), 12 deletions(-) create mode 100644 po/grub.d.sed diff --git a/ChangeLog b/ChangeLog index 6e564324b..ca555a662 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,22 @@ +2010-12-21 Colin Watson + + * util/grub-mkconfig_lib.in (gettext_quoted): Add clarifying + comment. Add an extra layer of quotation, requiring the output of + this function to be used in a printf format string. + (gettext_printf): New function. + * util/grub.d/10_hurd.in: Use gettext_printf where appropriate. + Extract translatable strings from here-documents and use a temporary + variable instead, so that xgettext can find them. + * util/grub.d/10_kfreebsd.in: Likewise. + * util/grub.d/10_linux.in: Likewise. + * util/grub.d/20_linux_xen.in: Likewise. + + * po/grub.d.sed: New file. + * po/Makefile.in.in ($(DOMAIN).pot-update): Extract gettext_printf + arguments. Set c-format flags on all strings extracted from + util/grub.d/ (xgettext refuses to include these itself for strings + it extracted from a shell file, but these really are c-format). + 2010-12-20 Vladimir Serbinenko * grub-core/loader/i386/multiboot_mbi.c (grub_multiboot_add_module): diff --git a/po/Makefile.in.in b/po/Makefile.in.in index d0af6c962..b0e7b8fa2 100644 --- a/po/Makefile.in.in +++ b/po/Makefile.in.in @@ -173,7 +173,8 @@ $(DOMAIN).pot-update: $(POTFILES) $(srcdir)/POTFILES.in $(srcdir)/POTFILES-shell --files-from=$(srcdir)/POTFILES-shell.in \ --copyright-holder='$(COPYRIGHT_HOLDER)' \ --msgid-bugs-address="$$msgid_bugs_address" \ - --join-existing --language=Shell --keyword=gettext_quoted \ + --join-existing --language=Shell \ + --keyword=gettext_quoted --keyword=gettext_printf \ ;; \ *) \ $(XGETTEXT) --default-domain=$(DOMAIN) --directory=$(top_srcdir) \ @@ -183,10 +184,13 @@ $(DOMAIN).pot-update: $(POTFILES) $(srcdir)/POTFILES.in $(srcdir)/POTFILES-shell --package-name="$${package_gnu}@PACKAGE@" \ --package-version='@VERSION@' \ --msgid-bugs-address="$$msgid_bugs_address" \ - --join-existing --language=Shell --keyword=gettext_quoted \ + --join-existing --language=Shell \ + --keyword=gettext_quoted --keyword=gettext_printf \ ;; \ esac test ! -f $(DOMAIN).po || { \ + sed -f grub.d.sed < $(DOMAIN).po > $(DOMAIN).1po && \ + mv $(DOMAIN).1po $(DOMAIN).po; \ if test -f $(srcdir)/$(DOMAIN).pot; then \ sed -f remove-potcdate.sed < $(srcdir)/$(DOMAIN).pot > $(DOMAIN).1po && \ sed -f remove-potcdate.sed < $(DOMAIN).po > $(DOMAIN).2po && \ diff --git a/po/grub.d.sed b/po/grub.d.sed new file mode 100644 index 000000000..9fd729474 --- /dev/null +++ b/po/grub.d.sed @@ -0,0 +1,2 @@ +/^#: util\/grub\.d\//a\ +#, c-format diff --git a/util/grub-mkconfig_lib.in b/util/grub-mkconfig_lib.in index 41359975e..ec4084698 100644 --- a/util/grub-mkconfig_lib.in +++ b/util/grub-mkconfig_lib.in @@ -187,8 +187,20 @@ version_find_latest () echo "$a" } +# One layer of quotation is eaten by "", the second by sed, and the third by +# printf; so this turns ' into \'. Note that you must use the output of +# this function in a printf format string. gettext_quoted () { - $gettext "$@" | sed "s/'/'\\\\''/g" + $gettext "$@" | sed "s/'/'\\\\\\\\''/g" +} + +# Run the first argument through gettext_quoted, and then pass that and all +# remaining arguments to printf. This is a useful abbreviation and tends to +# be easier to type. +gettext_printf () { + local format="$1" + shift + printf "$(gettext_quoted "$format")" "$@" } uses_abstraction () { diff --git a/util/grub.d/10_hurd.in b/util/grub.d/10_hurd.in index 6490913ae..eeb441aa4 100644 --- a/util/grub.d/10_hurd.in +++ b/util/grub.d/10_hurd.in @@ -81,14 +81,16 @@ do menuentry "${OS} ${KERNEL}" ${CLASS} { EOF prepare_grub_to_access_device ${GRUB_DEVICE_BOOT} | sed -e "s/^/\t/" + message="$(gettext_printf "Loading GNU Mach ...")" cat << EOF - echo '$(gettext_quoted "Loading GNU Mach ...")' + echo '$message' multiboot ${kernel} root=device:${GRUB_DEVICE#/dev/} EOF save_default_entry | sed -e "s/^/\t/" prepare_grub_to_access_device ${GRUB_DEVICE} | sed -e "s/^/\t/" + message="$(gettext_printf "Loading the Hurd ...")" cat << EOF - echo '$(gettext_quoted "Loading the Hurd ...")' + echo '$message' module /hurd/${hurd_fs}.static ${hurd_fs} --readonly \\ --multiboot-command-line='\${kernel-command-line}' \\ --host-priv-port='\${host-port}' \\ @@ -103,13 +105,15 @@ EOF menuentry "${OS} ${KERNEL} (recovery mode)" ${CLASS} { EOF prepare_grub_to_access_device ${GRUB_DEVICE_BOOT} | sed -e "s/^/\t/" + message="$(gettext_printf "Loading GNU Mach ...")" cat << EOF - echo '$(gettext_quoted "Loading GNU Mach ...")' + echo '$message' multiboot ${kernel} root=device:${GRUB_DEVICE#/dev/} -s EOF prepare_grub_to_access_device ${GRUB_DEVICE} | sed -e "s/^/\t/" + message="$(gettext_printf "Loading the Hurd ...")" cat << EOF - echo '$(gettext_quoted "Loading the Hurd ...")' + echo '$message' module /hurd/${hurd_fs}.static ${hurd_fs} \\ --multiboot-command-line='\${kernel-command-line}' \\ --host-priv-port='\${host-port}' \\ diff --git a/util/grub.d/10_kfreebsd.in b/util/grub.d/10_kfreebsd.in index 9cb2788df..b026812a7 100644 --- a/util/grub.d/10_kfreebsd.in +++ b/util/grub.d/10_kfreebsd.in @@ -84,8 +84,9 @@ kfreebsd_entry () fi printf '%s\n' "${prepare_boot_cache}" + message="$(gettext_printf "Loading kernel of FreeBSD %s ..." ${version})" cat << EOF - echo '$(printf "$(gettext_quoted "Loading kernel of FreeBSD %s ...")" ${version})' + echo '$message' kfreebsd ${rel_dirname}/${basename} ${args} EOF diff --git a/util/grub.d/10_linux.in b/util/grub.d/10_linux.in index 7650ac9fa..a09c3e687 100644 --- a/util/grub.d/10_linux.in +++ b/util/grub.d/10_linux.in @@ -94,13 +94,15 @@ EOF prepare_boot_cache="$(prepare_grub_to_access_device ${GRUB_DEVICE_BOOT} | sed -e "s/^/\t/")" fi printf '%s\n' "${prepare_boot_cache}" + message="$(gettext_printf "Loading Linux %s ..." ${version})" cat << EOF - echo '$(printf "$(gettext_quoted "Loading Linux %s ...")" ${version})' + echo '$message' linux ${rel_dirname}/${basename} root=${linux_root_device_thisversion} ro ${args} EOF if test -n "${initrd}" ; then + message="$(gettext_printf "Loading initial ramdisk ...")" cat << EOF - echo '$(gettext_quoted "Loading initial ramdisk ...")' + echo '$message' initrd ${rel_dirname}/${initrd} EOF fi diff --git a/util/grub.d/20_linux_xen.in b/util/grub.d/20_linux_xen.in index 649ae85dd..a90211f44 100644 --- a/util/grub.d/20_linux_xen.in +++ b/util/grub.d/20_linux_xen.in @@ -73,14 +73,16 @@ linux_entry () prepare_boot_cache="$(prepare_grub_to_access_device ${GRUB_DEVICE_BOOT} | sed -e "s/^/\t/")" fi printf '%s\n' "${prepare_boot_cache}" + message="$(gettext_printf "Loading Linux %s ..." ${version})" cat << EOF - echo '$(printf "$(gettext_quoted "Loading Linux %s ...")" ${version})' + echo '$message' multiboot ${rel_xen_dirname}/${xen_basename} placeholder ${xen_args} module ${rel_dirname}/${basename} placeholder root=${linux_root_device_thisversion} ro ${args} EOF if test -n "${initrd}" ; then + message="$(gettext_printf "Loading initial ramdisk ...")" cat << EOF - echo '$(gettext_quoted "Loading initial ramdisk ...")' + echo '$message' module ${rel_dirname}/${initrd} EOF fi From b889cfadf9e3cf85f538d5eb206028b583bff7ef Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Tue, 21 Dec 2010 13:00:10 +0000 Subject: [PATCH 11/15] * grub-core/fs/udf.c (read_string): Pacify GCC warning by initialising utf16. --- ChangeLog | 5 +++++ grub-core/fs/udf.c | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index ca555a662..42e059d46 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2010-12-21 Colin Watson + + * grub-core/fs/udf.c (read_string): Pacify GCC warning by + initialising utf16. + 2010-12-21 Colin Watson * util/grub-mkconfig_lib.in (gettext_quoted): Add clarifying diff --git a/grub-core/fs/udf.c b/grub-core/fs/udf.c index 51726edf3..1672aab1b 100644 --- a/grub-core/fs/udf.c +++ b/grub-core/fs/udf.c @@ -791,7 +791,7 @@ fail: static char * read_string (grub_uint8_t *raw, grub_size_t sz) { - grub_uint16_t *utf16; + grub_uint16_t *utf16 = NULL; char *ret; grub_size_t utf16len = 0; From d060ad60eee798a5c7c970ca2e777c7f1d0f8caa Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Tue, 21 Dec 2010 13:52:07 +0000 Subject: [PATCH 12/15] * grub-core/commands/echo.c (grub_cmd_echo): Make UTF-8-clean by constructing a new unescaped string and passing it to grub_xputs in one go, rather than passing characters to grub_printf one at a time. --- ChangeLog | 6 ++++++ grub-core/commands/echo.c | 26 ++++++++++++++++++-------- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index 42e059d46..e65dc231c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2010-12-21 Colin Watson + + * grub-core/commands/echo.c (grub_cmd_echo): Make UTF-8-clean by + constructing a new unescaped string and passing it to grub_xputs in + one go, rather than passing characters to grub_printf one at a time. + 2010-12-21 Colin Watson * grub-core/fs/udf.c (read_string): Pacify GCC warning by diff --git a/grub-core/commands/echo.c b/grub-core/commands/echo.c index 7ab9f92c6..93a452fc8 100644 --- a/grub-core/commands/echo.c +++ b/grub-core/commands/echo.c @@ -44,8 +44,14 @@ grub_cmd_echo (grub_extcmd_context_t ctxt, int argc, char **args) for (i = 0; i < argc; i++) { char *arg = *args; + /* Unescaping results in a string no longer than the original. */ + char *unescaped = grub_malloc (grub_strlen (arg) + 1); + char *p = unescaped; args++; + if (!unescaped) + return grub_errno; + while (*arg) { /* In case `-e' is used, parse backslashes. */ @@ -58,11 +64,11 @@ grub_cmd_echo (grub_extcmd_context_t ctxt, int argc, char **args) switch (*arg) { case '\\': - grub_printf ("\\"); + *p++ = '\\'; break; case 'a': - grub_printf ("\a"); + *p++ = '\a'; break; case 'c': @@ -70,23 +76,23 @@ grub_cmd_echo (grub_extcmd_context_t ctxt, int argc, char **args) break; case 'f': - grub_printf ("\f"); + *p++ = '\f'; break; case 'n': - grub_printf ("\n"); + *p++ = '\n'; break; case 'r': - grub_printf ("\r"); + *p++ = '\r'; break; case 't': - grub_printf ("\t"); + *p++ = '\t'; break; case 'v': - grub_printf ("\v"); + *p++ = '\v'; break; } arg++; @@ -95,10 +101,14 @@ grub_cmd_echo (grub_extcmd_context_t ctxt, int argc, char **args) /* This was not an escaped character, or escaping is not enabled. */ - grub_printf ("%c", *arg); + *p++ = *arg; arg++; } + *p = '\0'; + grub_xputs (unescaped); + grub_free (unescaped); + /* If another argument follows, insert a space. */ if (i != argc - 1) grub_printf (" " ); From 20641b6baad5d5a18ec5d5cd5305e01ff3c7f025 Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Tue, 21 Dec 2010 16:51:08 +0000 Subject: [PATCH 13/15] * grub-core/lib/reed_solomon.c (gauss_solve): Fix size of standalone scratch area. Make sure to initialise chosen in standalone mode as well as non-standalone. Reported by: Robert Hooker and Andy Whitcroft. Tested by: Andy Whitcroft. --- ChangeLog | 8 ++++++++ grub-core/lib/reed_solomon.c | 12 +++++++----- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index e65dc231c..4c7225bc5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2010-12-21 Colin Watson + + * grub-core/lib/reed_solomon.c (gauss_solve): Fix size of standalone + scratch area. Make sure to initialise chosen in standalone mode as + well as non-standalone. + Reported by: Robert Hooker and Andy Whitcroft. + Tested by: Andy Whitcroft. + 2010-12-21 Colin Watson * grub-core/commands/echo.c (grub_cmd_echo): Make UTF-8-clean by diff --git a/grub-core/lib/reed_solomon.c b/grub-core/lib/reed_solomon.c index 4c6e160e4..6f571550a 100644 --- a/grub-core/lib/reed_solomon.c +++ b/grub-core/lib/reed_solomon.c @@ -18,6 +18,8 @@ #ifdef TEST #include +#include +#include #define xmalloc malloc #define grub_memset memset #define grub_memcpy memcpy @@ -25,8 +27,6 @@ #ifndef STANDALONE #ifdef TEST -#include -#include typedef unsigned int grub_size_t; typedef unsigned char grub_uint8_t; typedef unsigned short grub_uint16_t; @@ -45,6 +45,7 @@ typedef unsigned char grub_uint8_t; typedef unsigned short grub_uint16_t; #else #include +#include #endif void grub_reed_solomon_recover (void *ptr_, grub_size_t s, grub_size_t rs); @@ -207,11 +208,12 @@ gauss_solve (gf_single_t *eq, int n, int m, gf_single_t *sol) #ifndef STANDALONE chosen = xmalloc (n * sizeof (int)); - grub_memset (chosen, -1, n * sizeof (int)); #else chosen = (void *) scratch; - scratch += n; + scratch += n * sizeof (int); #endif + for (i = 0; i < n; i++) + chosen[i] = -1; for (i = 0; i < m; i++) sol[i] = 0; gauss_eliminate (eq, n, m, chosen); @@ -228,7 +230,7 @@ gauss_solve (gf_single_t *eq, int n, int m, gf_single_t *sol) #ifndef STANDALONE free (chosen); #else - scratch -= n; + scratch -= n * sizeof (int); #endif } From 1426ef3560721b04db1d3e162957825a00753cd8 Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Tue, 21 Dec 2010 17:41:47 +0000 Subject: [PATCH 14/15] * include/grub/offsets.h (GRUB_KERNEL_I386_PC_RAW_SIZE): The previous patch increased the size of the RS code by 20 bytes (at least with gcc-4.4), so increase this by 20 bytes to match. (GRUB_KERNEL_I386_PC_NO_REED_SOLOMON_PART): Likewise. --- ChangeLog | 7 +++++++ include/grub/offsets.h | 4 ++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 4c7225bc5..27e2aee97 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2010-12-21 Colin Watson + + * include/grub/offsets.h (GRUB_KERNEL_I386_PC_RAW_SIZE): The + previous patch increased the size of the RS code by 20 bytes (at + least with gcc-4.4), so increase this by 20 bytes to match. + (GRUB_KERNEL_I386_PC_NO_REED_SOLOMON_PART): Likewise. + 2010-12-21 Colin Watson * grub-core/lib/reed_solomon.c (gauss_solve): Fix size of standalone diff --git a/include/grub/offsets.h b/include/grub/offsets.h index b096abf37..817372b69 100644 --- a/include/grub/offsets.h +++ b/include/grub/offsets.h @@ -38,9 +38,9 @@ #define GRUB_KERNEL_I386_PC_REED_SOLOMON_REDUNDANCY 0x1c /* The size of the first region which won't be compressed. */ -#define GRUB_KERNEL_I386_PC_RAW_SIZE 0xc90 +#define GRUB_KERNEL_I386_PC_RAW_SIZE 0xca4 -#define GRUB_KERNEL_I386_PC_NO_REED_SOLOMON_PART 0x6f8 +#define GRUB_KERNEL_I386_PC_NO_REED_SOLOMON_PART 0x70c /* The offset of GRUB_PREFIX. */ #define GRUB_KERNEL_I386_PC_PREFIX GRUB_KERNEL_I386_PC_RAW_SIZE From ab66c69f1a91617b429d73c59987e2c0c7d898c3 Mon Sep 17 00:00:00 2001 From: Jordan Uggla Date: Thu, 23 Dec 2010 11:51:18 +0000 Subject: [PATCH 15/15] * tests/util/grub-shell.in: Suppress "ACPI shutdown failed" error to keep unit tests from failing when they shouldn't. --- ChangeLog | 5 +++++ tests/util/grub-shell.in | 2 ++ 2 files changed, 7 insertions(+) diff --git a/ChangeLog b/ChangeLog index 27e2aee97..79eeae387 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2010-12-23 Jordan Uggla + + * tests/util/grub-shell.in: Suppress "ACPI shutdown failed" error to + keep unit tests from failing when they shouldn't. + 2010-12-21 Colin Watson * include/grub/offsets.h (GRUB_KERNEL_I386_PC_RAW_SIZE): The diff --git a/tests/util/grub-shell.in b/tests/util/grub-shell.in index fc14ca7b0..e35d6bc65 100644 --- a/tests/util/grub-shell.in +++ b/tests/util/grub-shell.in @@ -132,6 +132,8 @@ done cat <>${cfgfile} source /boot/grub/testcase.cfg +# Stop serial output to suppress "ACPI shutdown failed" error. +terminal_output console halt EOF