* 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.
This commit is contained in:
Vladimir 'phcoder' Serbinenko 2012-02-24 12:30:32 +01:00
parent 697f18b067
commit 4e27343fb0
16 changed files with 74 additions and 27 deletions

View file

@ -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> 2012-02-24 Grégoire Sutre <gregoire.sutre@gmail.com>
* grub-core/commands/lsacpi.c (disp_acpi_xsdt_table): Fix loop condition * grub-core/commands/lsacpi.c (disp_acpi_xsdt_table): Fix loop condition

View file

@ -105,7 +105,7 @@ starfielddir = $(pkgdatadir)/themes/starfield
CFLAGS_GCRY = -Wno-error -Wno-missing-field-initializers CFLAGS_GCRY = -Wno-error -Wno-missing-field-initializers
CPPFLAGS_GCRY = -I$(top_srcdir)/grub-core/lib/libgcrypt_wrap 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 CPPFLAGS_GNULIB = -I$(top_builddir)/grub-core/gnulib -I$(top_srcdir)/grub-core/gnulib
CFLAGS_POSIX = -fno-builtin CFLAGS_POSIX = -fno-builtin

View file

@ -377,9 +377,9 @@ LDFLAGS="$TARGET_LDFLAGS"
LIBS="" LIBS=""
# debug flags. # 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" 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" TARGET_CCASFLAGS="$TARGET_CCASFLAGS -g"
# Force no alignment to save space on i386. # Force no alignment to save space on i386.

View file

@ -543,15 +543,17 @@ struct legacy_md5_password
grub_uint8_t hash[MD5_HASHLEN]; grub_uint8_t hash[MD5_HASHLEN];
}; };
#pragma GCC diagnostic ignored "-Wunsafe-loop-optimizations"
static int static int
check_password_md5_real (const char *entered, check_password_md5_real (const char *entered,
struct legacy_md5_password *pw) 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 alt_result[MD5_HASHLEN];
unsigned char *digest; unsigned char *digest;
grub_uint8_t ctx[GRUB_MD_MD5->contextsize]; grub_uint8_t ctx[GRUB_MD_MD5->contextsize];
int i; grub_size_t i;
GRUB_MD_MD5->init (ctx); GRUB_MD_MD5->init (ctx);
GRUB_MD_MD5->write (ctx, entered, enteredlen); GRUB_MD_MD5->write (ctx, entered, enteredlen);

View file

@ -77,19 +77,24 @@ grub_cmd_testload (struct grub_command *cmd __attribute__ ((unused)),
grub_printf ("Reading %s sequentially again", argv[0]); grub_printf ("Reading %s sequentially again", argv[0]);
grub_file_seek (file, 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]; char sector[GRUB_DISK_SECTOR_SIZE];
grub_size_t curlen = GRUB_DISK_SECTOR_SIZE;
if (grub_file_read (file, sector, GRUB_DISK_SECTOR_SIZE) if (curlen > size - pos)
!= GRUB_DISK_SECTOR_SIZE) curlen = size - pos;
if (grub_file_read (file, sector, curlen)
!= (grub_ssize_t) curlen)
goto fail; 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); grub_printf ("\nDiffers in %lld\n", (unsigned long long) pos);
goto fail; goto fail;
} }
pos += curlen;
} }
grub_printf (" Done.\n"); grub_printf (" Done.\n");

View 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_pv *pv = NULL;
struct grub_diskfilter_vg *vg = 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); 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->pv == pv
&& lv->segments->nodes->start + pv->start_sector == start) && lv->segments->nodes->start + pv->start_sector == start)
{ {
res = lv; res_lv = lv;
break; break;
} }
if (!res_lv)
return NULL;
for (lv = vg->lvs; lv; lv = lv->next) for (lv = vg->lvs; lv; lv = lv->next)
if (lv->segment_count == 1 && lv->segments->node_count == 1 if (lv->segment_count == 1 && lv->segments->node_count == 1
&& lv->segments->type == GRUB_DISKFILTER_MIRROR && lv->segments->type == GRUB_DISKFILTER_MIRROR
&& lv->segments->nodes->lv == lv) && lv->segments->nodes->lv == res_lv)
{ {
res = lv; res = lv;
break; break;
} }
if (res->fullname) if (res && res->fullname)
return grub_strdup (lv->fullname); return grub_strdup (res->fullname);
return NULL; return NULL;
} }

View file

@ -129,7 +129,7 @@ zio_checksum_SHA256(const void *buf, grub_uint64_t size,
for (i = 0; i < 8; i++) for (i = 0; i < 8; i++)
pad[padsize++] = (size << 3) >> (56 - 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); SHA256Transform(H, pad + i);
zcp->zc_word[0] = grub_cpu_to_zfs64 ((grub_uint64_t)H[0] << 32 | H[1], zcp->zc_word[0] = grub_cpu_to_zfs64 ((grub_uint64_t)H[0] << 32 | H[1],

View file

@ -363,6 +363,8 @@ static ush mask_bits[] =
0x01ff, 0x03ff, 0x07ff, 0x0fff, 0x1fff, 0x3fff, 0x7fff, 0xffff 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 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) #define DUMPBITS(n) do {b>>=(n);k-=(n);} while (0)

View file

@ -1211,7 +1211,7 @@ static UInt32 GetOptimum(CLzmaEnc *p, UInt32 position, UInt32 *backRes)
{ {
UInt32 i; UInt32 i;
reps[0] = prevOpt->backs[pos]; reps[0] = prevOpt->backs[pos];
for (i = 1; i <= pos; i++) for (i = 1; i < pos + 1; i++)
reps[i] = prevOpt->backs[i - 1]; reps[i] = prevOpt->backs[i - 1];
for (; i < LZMA_NUM_REPS; i++) for (; i < LZMA_NUM_REPS; i++)
reps[i] = prevOpt->backs[i]; reps[i] = prevOpt->backs[i];

View 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_network_level_interface **interf)
{ {
struct grub_net_route *route; struct grub_net_route *route;
int depth = 0; unsigned int depth = 0;
int routecnt = 0; unsigned int routecnt = 0;
struct grub_net_network_level_protocol *prot = NULL; struct grub_net_network_level_protocol *prot = NULL;
grub_net_network_level_address_t curtarget = addr; 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) FOR_NET_ROUTES(route)
routecnt++; 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; struct grub_net_route *bestroute = NULL;
FOR_NET_ROUTES(route) FOR_NET_ROUTES(route)

View file

@ -734,7 +734,8 @@ bidi_line_wrap (struct grub_unicode_glyph *visual_out,
{ {
int right_join = 0; int right_join = 0;
signed i; 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); enum grub_join_type join_type = get_join_type (visual[i].base);
if (!(visual[i].attributes if (!(visual[i].attributes

View file

@ -49,13 +49,13 @@ grub_set_history (int newsize)
/* Remove the lines that don't fit in the new buffer. */ /* Remove the lines that don't fit in the new buffer. */
if (newsize < hist_used) if (newsize < hist_used)
{ {
int i; grub_size_t i;
int delsize = hist_used - newsize; grub_size_t delsize = hist_used - newsize;
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) if (pos < 0)
pos += hist_size; pos += hist_size;
grub_free (old_hist_lines[pos]); grub_free (old_hist_lines[pos]);

View file

@ -31,6 +31,9 @@
#include "grub_script.tab.h" #include "grub_script.tab.h"
#pragma GCC diagnostic ignored "-Wunreachable-code" #pragma GCC diagnostic ignored "-Wunreachable-code"
#pragma GCC diagnostic ignored "-Wmissing-declarations"
#pragma GCC diagnostic ignored "-Wunsafe-loop-optimizations"
%} %}
%union { %union {

View file

@ -27,6 +27,8 @@
#pragma GCC diagnostic ignored "-Wunused-parameter" #pragma GCC diagnostic ignored "-Wunused-parameter"
#pragma GCC diagnostic ignored "-Wmissing-prototypes" #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 yyfree grub_lexer_yyfree
#define yyalloc grub_lexer_yyalloc #define yyalloc grub_lexer_yyalloc

View file

@ -681,6 +681,8 @@ write_be16_section (const char *name, grub_uint16_t data, int* offset,
*offset += 10; *offset += 10;
} }
#pragma GCC diagnostic ignored "-Wunsafe-loop-optimizations"
static void static void
print_glyphs (struct grub_font_info *font_info) print_glyphs (struct grub_font_info *font_info)
{ {
@ -717,7 +719,7 @@ print_glyphs (struct grub_font_info *font_info)
bitmap = glyph->bitmap; bitmap = glyph->bitmap;
mask = 0x80; mask = 0x80;
for (y = ymax - 1; y >= ymin; y--) for (y = ymax - 1; y > ymin - 1; y--)
{ {
int line_pos; int line_pos;

View file

@ -625,7 +625,7 @@ compress_kernel_xz (char *kernel_img, size_t kernel_size,
xzret = lzma_stream_encoder (&strm, fltrs, LZMA_CHECK_NONE); xzret = lzma_stream_encoder (&strm, fltrs, LZMA_CHECK_NONE);
if (xzret != LZMA_OK) 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); *core_img = xmalloc (kernel_size);
@ -642,7 +642,7 @@ compress_kernel_xz (char *kernel_img, size_t kernel_size,
continue; continue;
if (xzret == LZMA_STREAM_END) if (xzret == LZMA_STREAM_END)
break; break;
grub_util_error (_("cannot compress the kernel image")); grub_util_error ("%s", _("cannot compress the kernel image"));
} }
*core_size -= strm.avail_out; *core_size -= strm.avail_out;