From e73bb8017042f2abffa8feafe02bdf21d88e9fe9 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 22 Jul 2012 16:27:03 +0200 Subject: [PATCH] * grub-core/lib/xzembed/xz_dec_stream.c (hash_validate): Fix behaviour if hash function is unavailable. (dec_stream_header): Likewise. --- ChangeLog | 6 ++++++ grub-core/lib/xzembed/xz_dec_stream.c | 15 ++++++++++----- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index 38374a33f..892d31bd1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2012-07-22 Vladimir Serbinenko + + * grub-core/lib/xzembed/xz_dec_stream.c (hash_validate): Fix behaviour + if hash function is unavailable. + (dec_stream_header): Likewise. + 2012-07-22 Vladimir Serbinenko * grub-core/normal/autofs.c (autoload_fs_module): Save and restore diff --git a/grub-core/lib/xzembed/xz_dec_stream.c b/grub-core/lib/xzembed/xz_dec_stream.c index 0d79b1f0b..6170b0c5c 100644 --- a/grub-core/lib/xzembed/xz_dec_stream.c +++ b/grub-core/lib/xzembed/xz_dec_stream.c @@ -403,18 +403,25 @@ static enum xz_ret hash_validate(struct xz_dec *s, struct xz_buf *b, } #endif - do { + if (b->in_pos == b->in_size) + return XZ_OK; + + if (!crc32 && s->hash_size == 0) + s->pos += 8; + + while (s->pos < (crc32 ? 32 : s->hash_size * 8)) { if (b->in_pos == b->in_size) return XZ_OK; #ifndef GRUB_EMBED_DECOMPRESSOR - if (hash && s->hash_value[s->pos / 8] != b->in[b->in_pos++]) + if (hash && s->hash_value[s->pos / 8] != b->in[b->in_pos]) return XZ_DATA_ERROR; #endif + b->in_pos++; s->pos += 8; - } while (s->pos < (crc32 ? 32 : s->hash_size * 8)); + } #ifndef GRUB_EMBED_DECOMPRESSOR if (s->hash) @@ -529,8 +536,6 @@ static enum xz_ret dec_stream_header(struct xz_dec *s) s->hash->init(s->index.hash.hash_context); s->hash->init(s->block.hash.hash_context); } - if (!s->hash) - return XZ_OPTIONS_ERROR; #endif } else