diff options
author | Phillip Lougher <phillip@lougher.demon.co.uk> | 2011-01-25 18:07:34 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2011-01-25 19:50:05 -0500 |
commit | 3689456b4bd36027022b3215eb2acba51cd0e6b5 (patch) | |
tree | 8233856d31d744feacf6d91b0fb7dbe7fbcf2803 /fs/squashfs/block.c | |
parent | ac15ee691fe84cb46cbd2497ddcb10e246f7ee47 (diff) |
squashfs: fix use of uninitialised variable in zlib & xz decompressors
Fix potential use of uninitialised variable caused by recent
decompressor code optimisations.
In zlib_uncompress (zlib_wrapper.c) we have
int zlib_err, zlib_init = 0;
...
do {
...
if (avail == 0) {
offset = 0;
put_bh(bh[k++]);
continue;
}
...
zlib_err = zlib_inflate(stream, Z_SYNC_FLUSH);
...
} while (zlib_err == Z_OK);
If continue is executed (avail == 0) then the while condition will be
evaluated testing zlib_err, which is uninitialised first time around the
loop.
Fix this by getting rid of the 'if (avail == 0)' condition test, this
edge condition should not be being handled in the decompressor code, and
instead handle it generically in the caller code.
Similarly for xz_wrapper.c.
Incidentally, on most architectures (bar Mips and Parisc), no
uninitialised variable warning is generated by gcc, this is because the
while condition test on continue is optimised out and not performed
(when executing continue zlib_err has not been changed since entering
the loop, and logically if the while condition was true previously, then
it's still true).
Signed-off-by: Phillip Lougher <phillip@lougher.demon.co.uk>
Reported-by: Jesper Juhl <jj@chaosbits.net>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'fs/squashfs/block.c')
-rw-r--r-- | fs/squashfs/block.c | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/fs/squashfs/block.c b/fs/squashfs/block.c index 2fb2882f0fa7..8ab48bc2fa7d 100644 --- a/fs/squashfs/block.c +++ b/fs/squashfs/block.c | |||
@@ -63,6 +63,14 @@ static struct buffer_head *get_block_length(struct super_block *sb, | |||
63 | *length = (unsigned char) bh->b_data[*offset] | | 63 | *length = (unsigned char) bh->b_data[*offset] | |
64 | (unsigned char) bh->b_data[*offset + 1] << 8; | 64 | (unsigned char) bh->b_data[*offset + 1] << 8; |
65 | *offset += 2; | 65 | *offset += 2; |
66 | |||
67 | if (*offset == msblk->devblksize) { | ||
68 | put_bh(bh); | ||
69 | bh = sb_bread(sb, ++(*cur_index)); | ||
70 | if (bh == NULL) | ||
71 | return NULL; | ||
72 | *offset = 0; | ||
73 | } | ||
66 | } | 74 | } |
67 | 75 | ||
68 | return bh; | 76 | return bh; |