diff --git a/ChangeLog b/ChangeLog index ff382d033..29f25d266 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,31 @@ +2012-02-24 Vladimir Serbinenko + + * conf/Makefile.common (CFLAGS_GNULIB): Add + -Wno-unsafe-loop-optimizations. + * configure.ac: Remove -Wmissing-declarations and -Wmissing-prototypes + on tools. + * grub-core/commands/legacycfg.c: Add pragma to skip + -Wunsafe-loop-optimizations. + (check_password_md5_real): Fix loop counter type. + * grub-core/commands/testload.c (grub_cmd_testload): Fix over the EOF + reading. + * grub-core/disk/ldm.c (grub_util_get_ldm): Fix logic error. + * grub-core/fs/zfs/zfs_sha256.c (zio_checksum_SHA256): Add safety + loop condition. + * grub-core/io/gzio.c: Add pragma to skip -Wunsafe-loop-optimizations. + * grub-core/lib/LzmaEnc.c (GetOptimum): Avoid possible infinite loop. + * grub-core/net/net.c (grub_net_route_address): Add safety loop + condition. + * grub-core/normal/charset.c (bidi_line_wrap): Likewise. + * grub-core/normal/cmdline.c (grub_set_history): Fix loop types and + avoid possible infinite loops. + * grub-core/script/parser.y: Add pragma to skip -Wmissing-declarations + and -Wunsafe-loop-optimizations. + * grub-core/script/yylex.l: Likewise. + * util/grub-mkfont.c: Add pragma to skip -Wunsafe-loop-optimizations. + (print_glyphs): Avoid infinite loops. + * util/grub-mkimage.c (compress_kernel_xz): Fix format security. + 2012-02-24 Grégoire Sutre * grub-core/commands/lsacpi.c (disp_acpi_xsdt_table): Fix loop condition diff --git a/conf/Makefile.common b/conf/Makefile.common index 4a04133d8..fbe6c2f38 100644 --- a/conf/Makefile.common +++ b/conf/Makefile.common @@ -105,7 +105,7 @@ starfielddir = $(pkgdatadir)/themes/starfield CFLAGS_GCRY = -Wno-error -Wno-missing-field-initializers CPPFLAGS_GCRY = -I$(top_srcdir)/grub-core/lib/libgcrypt_wrap -CFLAGS_GNULIB = -Wno-undef -Wno-sign-compare -Wno-unused -Wno-unused-parameter -Wno-redundant-decls -Wno-unreachable-code -Wno-conversion -Wno-old-style-definition +CFLAGS_GNULIB = -Wno-undef -Wno-sign-compare -Wno-unused -Wno-unused-parameter -Wno-redundant-decls -Wno-unreachable-code -Wno-conversion -Wno-old-style-definition -Wno-unsafe-loop-optimizations CPPFLAGS_GNULIB = -I$(top_builddir)/grub-core/gnulib -I$(top_srcdir)/grub-core/gnulib CFLAGS_POSIX = -fno-builtin diff --git a/configure.ac b/configure.ac index ac3721985..e2060cd9a 100644 --- a/configure.ac +++ b/configure.ac @@ -377,9 +377,9 @@ LDFLAGS="$TARGET_LDFLAGS" LIBS="" # debug flags. -WARN_FLAGS="-Wall -W -Wshadow -Wold-style-declaration -Wold-style-definition -Wpointer-arith -Wundef -Wextra -Waddress -Warray-bounds -Wattributes -Wbuiltin-macro-redefined -Wcast-align -Wchar-subscripts -Wclobbered -Wcomment -Wcoverage-mismatch -Wdeprecated -Wdeprecated-declarations -Wdisabled-optimization -Wdiv-by-zero -Wempty-body -Wendif-labels -Wfloat-equal -Wformat-contains-nul -Wformat-extra-args -Wformat-security -Wformat-y2k -Wignored-qualifiers -Wimplicit -Wimplicit-function-declaration -Wimplicit-int -Winit-self -Wint-to-pointer-cast -Winvalid-pch -Wunsafe-loop-optimizations -Wlogical-op -Wmain -Wmissing-braces -Wmissing-field-initializers -Wmissing-format-attribute -Wmissing-noreturn -Wmudflap -Wmultichar -Wnonnull -Woverflow -Wpacked-bitfield-compat -Wparentheses -Wpointer-arith -Wpointer-to-int-cast -Wreturn-type -Wsequence-point -Wshadow -Wsign-compare -Wstrict-aliasing -Wswitch -Wsync-nand -Wtrigraphs -Wtype-limits -Wundef -Wuninitialized -Wunknown-pragmas -Wunused -Wunused-function -Wunused-label -Wunused-parameter -Wunused-value -Wunused-variable -Wvariadic-macros -Wvolatile-register-var -Wwrite-strings -Wmissing-declarations -Wmissing-parameter-type -Wmissing-prototypes -Wnested-externs -Wstrict-prototypes -Wpointer-sign" +WARN_FLAGS="-Wall -W -Wshadow -Wold-style-declaration -Wold-style-definition -Wpointer-arith -Wundef -Wextra -Waddress -Warray-bounds -Wattributes -Wbuiltin-macro-redefined -Wcast-align -Wchar-subscripts -Wclobbered -Wcomment -Wcoverage-mismatch -Wdeprecated -Wdeprecated-declarations -Wdisabled-optimization -Wdiv-by-zero -Wempty-body -Wendif-labels -Wfloat-equal -Wformat-contains-nul -Wformat-extra-args -Wformat-security -Wformat-y2k -Wignored-qualifiers -Wimplicit -Wimplicit-function-declaration -Wimplicit-int -Winit-self -Wint-to-pointer-cast -Winvalid-pch -Wunsafe-loop-optimizations -Wlogical-op -Wmain -Wmissing-braces -Wmissing-field-initializers -Wmissing-format-attribute -Wmissing-noreturn -Wmudflap -Wmultichar -Wnonnull -Woverflow -Wpacked-bitfield-compat -Wparentheses -Wpointer-arith -Wpointer-to-int-cast -Wreturn-type -Wsequence-point -Wshadow -Wsign-compare -Wstrict-aliasing -Wswitch -Wsync-nand -Wtrigraphs -Wtype-limits -Wundef -Wuninitialized -Wunknown-pragmas -Wunused -Wunused-function -Wunused-label -Wunused-parameter -Wunused-value -Wunused-variable -Wvariadic-macros -Wvolatile-register-var -Wwrite-strings -Wmissing-parameter-type -Wnested-externs -Wstrict-prototypes -Wpointer-sign" HOST_CFLAGS="$HOST_CFLAGS $WARN_FLAGS" -TARGET_CFLAGS="$TARGET_CFLAGS $WARN_FLAGS -g -Wredundant-decls -Wmissing-prototypes" +TARGET_CFLAGS="$TARGET_CFLAGS $WARN_FLAGS -g -Wredundant-decls -Wmissing-prototypes -Wmissing-declarations" TARGET_CCASFLAGS="$TARGET_CCASFLAGS -g" # Force no alignment to save space on i386. diff --git a/grub-core/commands/legacycfg.c b/grub-core/commands/legacycfg.c index fb06401e9..ff6ee17fb 100644 --- a/grub-core/commands/legacycfg.c +++ b/grub-core/commands/legacycfg.c @@ -543,15 +543,17 @@ struct legacy_md5_password grub_uint8_t hash[MD5_HASHLEN]; }; +#pragma GCC diagnostic ignored "-Wunsafe-loop-optimizations" + static int check_password_md5_real (const char *entered, struct legacy_md5_password *pw) { - int enteredlen = grub_strlen (entered); + grub_size_t enteredlen = grub_strlen (entered); unsigned char alt_result[MD5_HASHLEN]; unsigned char *digest; grub_uint8_t ctx[GRUB_MD_MD5->contextsize]; - int i; + grub_size_t i; GRUB_MD_MD5->init (ctx); GRUB_MD_MD5->write (ctx, entered, enteredlen); diff --git a/grub-core/commands/testload.c b/grub-core/commands/testload.c index f67abadda..a1bf775b8 100644 --- a/grub-core/commands/testload.c +++ b/grub-core/commands/testload.c @@ -77,19 +77,24 @@ grub_cmd_testload (struct grub_command *cmd __attribute__ ((unused)), grub_printf ("Reading %s sequentially again", argv[0]); grub_file_seek (file, 0); - for (pos = 0; pos < size; pos += GRUB_DISK_SECTOR_SIZE) + for (pos = 0; pos < size;) { char sector[GRUB_DISK_SECTOR_SIZE]; + grub_size_t curlen = GRUB_DISK_SECTOR_SIZE; - if (grub_file_read (file, sector, GRUB_DISK_SECTOR_SIZE) - != GRUB_DISK_SECTOR_SIZE) + if (curlen > size - pos) + curlen = size - pos; + + if (grub_file_read (file, sector, curlen) + != (grub_ssize_t) curlen) goto fail; - if (grub_memcmp (sector, buf + pos, GRUB_DISK_SECTOR_SIZE) != 0) + if (grub_memcmp (sector, buf + pos, curlen) != 0) { grub_printf ("\nDiffers in %lld\n", (unsigned long long) pos); goto fail; } + pos += curlen; } grub_printf (" Done.\n"); diff --git a/grub-core/disk/ldm.c b/grub-core/disk/ldm.c index 154c8c98a..8e5d07402 100644 --- a/grub-core/disk/ldm.c +++ b/grub-core/disk/ldm.c @@ -831,7 +831,7 @@ grub_util_get_ldm (grub_disk_t disk, grub_disk_addr_t start) { struct grub_diskfilter_pv *pv = NULL; struct grub_diskfilter_vg *vg = NULL; - struct grub_diskfilter_lv *res, *lv; + struct grub_diskfilter_lv *res = 0, *lv, *res_lv = 0; pv = grub_diskfilter_get_pv_from_disk (disk, &vg); @@ -844,19 +844,21 @@ grub_util_get_ldm (grub_disk_t disk, grub_disk_addr_t start) && lv->segments->nodes->pv == pv && lv->segments->nodes->start + pv->start_sector == start) { - res = lv; + res_lv = lv; break; } + if (!res_lv) + return NULL; for (lv = vg->lvs; lv; lv = lv->next) if (lv->segment_count == 1 && lv->segments->node_count == 1 && lv->segments->type == GRUB_DISKFILTER_MIRROR - && lv->segments->nodes->lv == lv) + && lv->segments->nodes->lv == res_lv) { res = lv; break; } - if (res->fullname) - return grub_strdup (lv->fullname); + if (res && res->fullname) + return grub_strdup (res->fullname); return NULL; } diff --git a/grub-core/fs/zfs/zfs_sha256.c b/grub-core/fs/zfs/zfs_sha256.c index ba510cf69..a181f076c 100644 --- a/grub-core/fs/zfs/zfs_sha256.c +++ b/grub-core/fs/zfs/zfs_sha256.c @@ -129,7 +129,7 @@ zio_checksum_SHA256(const void *buf, grub_uint64_t size, for (i = 0; i < 8; i++) pad[padsize++] = (size << 3) >> (56 - 8 * i); - for (i = 0; i < padsize; i += 64) + for (i = 0; i < padsize && i <= 64; i += 64) SHA256Transform(H, pad + i); zcp->zc_word[0] = grub_cpu_to_zfs64 ((grub_uint64_t)H[0] << 32 | H[1], diff --git a/grub-core/io/gzio.c b/grub-core/io/gzio.c index cc81aaaa1..f88bda1cb 100644 --- a/grub-core/io/gzio.c +++ b/grub-core/io/gzio.c @@ -363,6 +363,8 @@ static ush mask_bits[] = 0x01ff, 0x03ff, 0x07ff, 0x0fff, 0x1fff, 0x3fff, 0x7fff, 0xffff }; +#pragma GCC diagnostic ignored "-Wunsafe-loop-optimizations" + #define NEEDBITS(n) do {while(k<(n)){b|=((ulg)get_byte(gzio))<>=(n);k-=(n);} while (0) diff --git a/grub-core/lib/LzmaEnc.c b/grub-core/lib/LzmaEnc.c index ae0c3b9f6..f2ec04a8c 100644 --- a/grub-core/lib/LzmaEnc.c +++ b/grub-core/lib/LzmaEnc.c @@ -1211,7 +1211,7 @@ static UInt32 GetOptimum(CLzmaEnc *p, UInt32 position, UInt32 *backRes) { UInt32 i; reps[0] = prevOpt->backs[pos]; - for (i = 1; i <= pos; i++) + for (i = 1; i < pos + 1; i++) reps[i] = prevOpt->backs[i - 1]; for (; i < LZMA_NUM_REPS; i++) reps[i] = prevOpt->backs[i]; diff --git a/grub-core/net/net.c b/grub-core/net/net.c index 5f3967bdf..c49d33472 100644 --- a/grub-core/net/net.c +++ b/grub-core/net/net.c @@ -608,8 +608,8 @@ grub_net_route_address (grub_net_network_level_address_t addr, struct grub_net_network_level_interface **interf) { struct grub_net_route *route; - int depth = 0; - int routecnt = 0; + unsigned int depth = 0; + unsigned int routecnt = 0; struct grub_net_network_level_protocol *prot = NULL; grub_net_network_level_address_t curtarget = addr; @@ -618,7 +618,7 @@ grub_net_route_address (grub_net_network_level_address_t addr, FOR_NET_ROUTES(route) routecnt++; - for (depth = 0; depth < routecnt + 2; depth++) + for (depth = 0; depth < routecnt + 2 && depth < GRUB_UINT_MAX; depth++) { struct grub_net_route *bestroute = NULL; FOR_NET_ROUTES(route) diff --git a/grub-core/normal/charset.c b/grub-core/normal/charset.c index 084e1e66c..dacd2126d 100644 --- a/grub-core/normal/charset.c +++ b/grub-core/normal/charset.c @@ -734,7 +734,8 @@ bidi_line_wrap (struct grub_unicode_glyph *visual_out, { int right_join = 0; signed i; - for (i = k - 1; i > (signed) line_start - 1; i--) + for (i = k - 1; i > (signed) line_start - 1 && i >= 0; + i--) { enum grub_join_type join_type = get_join_type (visual[i].base); if (!(visual[i].attributes diff --git a/grub-core/normal/cmdline.c b/grub-core/normal/cmdline.c index 18314cdc0..8b255e6d7 100644 --- a/grub-core/normal/cmdline.c +++ b/grub-core/normal/cmdline.c @@ -49,13 +49,13 @@ grub_set_history (int newsize) /* Remove the lines that don't fit in the new buffer. */ if (newsize < hist_used) { - int i; - int delsize = hist_used - newsize; + grub_size_t i; + grub_size_t delsize = hist_used - newsize; hist_used = newsize; - for (i = 1; i <= delsize; i++) + for (i = 1; i < delsize + 1; i++) { - int pos = hist_end - i; + grub_ssize_t pos = hist_end - i; if (pos < 0) pos += hist_size; grub_free (old_hist_lines[pos]); diff --git a/grub-core/script/parser.y b/grub-core/script/parser.y index 0c2d8867b..74c813bbe 100644 --- a/grub-core/script/parser.y +++ b/grub-core/script/parser.y @@ -31,6 +31,9 @@ #include "grub_script.tab.h" #pragma GCC diagnostic ignored "-Wunreachable-code" +#pragma GCC diagnostic ignored "-Wmissing-declarations" +#pragma GCC diagnostic ignored "-Wunsafe-loop-optimizations" + %} %union { diff --git a/grub-core/script/yylex.l b/grub-core/script/yylex.l index ab913988a..55188b79b 100644 --- a/grub-core/script/yylex.l +++ b/grub-core/script/yylex.l @@ -27,6 +27,8 @@ #pragma GCC diagnostic ignored "-Wunused-parameter" #pragma GCC diagnostic ignored "-Wmissing-prototypes" +#pragma GCC diagnostic ignored "-Wmissing-declarations" +#pragma GCC diagnostic ignored "-Wunsafe-loop-optimizations" #define yyfree grub_lexer_yyfree #define yyalloc grub_lexer_yyalloc diff --git a/util/grub-mkfont.c b/util/grub-mkfont.c index e86e37c92..b279384bb 100644 --- a/util/grub-mkfont.c +++ b/util/grub-mkfont.c @@ -681,6 +681,8 @@ write_be16_section (const char *name, grub_uint16_t data, int* offset, *offset += 10; } +#pragma GCC diagnostic ignored "-Wunsafe-loop-optimizations" + static void print_glyphs (struct grub_font_info *font_info) { @@ -717,7 +719,7 @@ print_glyphs (struct grub_font_info *font_info) bitmap = glyph->bitmap; mask = 0x80; - for (y = ymax - 1; y >= ymin; y--) + for (y = ymax - 1; y > ymin - 1; y--) { int line_pos; diff --git a/util/grub-mkimage.c b/util/grub-mkimage.c index 34f4730f5..78cf3f281 100644 --- a/util/grub-mkimage.c +++ b/util/grub-mkimage.c @@ -625,7 +625,7 @@ compress_kernel_xz (char *kernel_img, size_t kernel_size, xzret = lzma_stream_encoder (&strm, fltrs, LZMA_CHECK_NONE); if (xzret != LZMA_OK) - grub_util_error (_("cannot compress the kernel image")); + grub_util_error ("%s", _("cannot compress the kernel image")); *core_img = xmalloc (kernel_size); @@ -642,7 +642,7 @@ compress_kernel_xz (char *kernel_img, size_t kernel_size, continue; if (xzret == LZMA_STREAM_END) break; - grub_util_error (_("cannot compress the kernel image")); + grub_util_error ("%s", _("cannot compress the kernel image")); } *core_size -= strm.avail_out;