* conf/Makefile.common (CFLAGS_GNULIB): Add
authorVladimir 'phcoder' Serbinenko <phcoder@gmail.com>
Fri, 24 Feb 2012 11:30:32 +0000 (12:30 +0100)
committerVladimir 'phcoder' Serbinenko <phcoder@gmail.com>
Fri, 24 Feb 2012 11:30:32 +0000 (12:30 +0100)
-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.

16 files changed:
ChangeLog
conf/Makefile.common
configure.ac
grub-core/commands/legacycfg.c
grub-core/commands/testload.c
grub-core/disk/ldm.c
grub-core/fs/zfs/zfs_sha256.c
grub-core/io/gzio.c
grub-core/lib/LzmaEnc.c
grub-core/net/net.c
grub-core/normal/charset.c
grub-core/normal/cmdline.c
grub-core/script/parser.y
grub-core/script/yylex.l
util/grub-mkfont.c
util/grub-mkimage.c

index ff382d0..29f25d2 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,31 @@
+2012-02-24  Vladimir Serbinenko  <phcoder@gmail.com>
+
+       * 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  <gregoire.sutre@gmail.com>
 
        * grub-core/commands/lsacpi.c (disp_acpi_xsdt_table): Fix loop condition
index 4a04133..fbe6c2f 100644 (file)
@@ -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
index ac37219..e2060cd 100644 (file)
@@ -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.
index fb06401..ff6ee17 100644 (file)
@@ -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);
index f67abad..a1bf775 100644 (file)
@@ -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");
 
index 154c8c9..8e5d074 100644 (file)
@@ -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;
 }
 
index ba510cf..a181f07 100644 (file)
@@ -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], 
index cc81aaa..f88bda1 100644 (file)
@@ -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))<<k;k+=8;}} while (0)
 #define DUMPBITS(n) do {b>>=(n);k-=(n);} while (0)
 
index ae0c3b9..f2ec04a 100644 (file)
@@ -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];
index 5f3967b..c49d334 100644 (file)
@@ -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)
index 084e1e6..dacd212 100644 (file)
@@ -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
index 18314cd..8b255e6 100644 (file)
@@ -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]);
index 0c2d886..74c813b 100644 (file)
@@ -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 {
index ab91398..55188b7 100644 (file)
@@ -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
index e86e37c..b279384 100644 (file)
@@ -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;
 
index 34f4730..78cf3f2 100644 (file)
@@ -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;