Matthew Daley
2013-Nov-08 00:26 UTC
[PATCH 1/2] xen: always set an error return code on lz4 decompression failures
Signed-off-by: Matthew Daley <mattjd@gmail.com>
---
xen/common/unlz4.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/xen/common/unlz4.c b/xen/common/unlz4.c
index 195d829..ae87f4c 100644
--- a/xen/common/unlz4.c
+++ b/xen/common/unlz4.c
@@ -112,6 +112,7 @@ STATIC int INIT unlz4(unsigned char *input, unsigned int
in_len,
if (fill) {
if (chunksize > lz4_compressbound(uncomp_chunksize)) {
error("chunk length is longer than allocated");
+ ret = -1;
goto exit_2;
}
fill(inp, chunksize);
@@ -133,8 +134,10 @@ STATIC int INIT unlz4(unsigned char *input, unsigned int
in_len,
goto exit_2;
}
- if (flush && flush(outp, dest_len) != dest_len)
+ if (flush && flush(outp, dest_len) != dest_len) {
+ ret = -1;
goto exit_2;
+ }
if (output)
outp += dest_len;
if (posp)
@@ -146,6 +149,7 @@ STATIC int INIT unlz4(unsigned char *input, unsigned int
in_len,
break;
else if (size < 0) {
error("data corrupted");
+ ret = -1;
goto exit_2;
}
--
1.7.10.4
Matthew Daley
2013-Nov-08 00:26 UTC
[PATCH 2/2] libxc: always set a error return code on lz4 decompression failures
While at it, rename the exit_2 label to exit_1; there is no exit_1
currently.
Signed-off-by: Matthew Daley <mattjd@gmail.com>
---
tools/libxc/xc_dom_decompress_lz4.c | 15 +++++++++------
1 file changed, 9 insertions(+), 6 deletions(-)
diff --git a/tools/libxc/xc_dom_decompress_lz4.c
b/tools/libxc/xc_dom_decompress_lz4.c
index 4787535..b980186 100644
--- a/tools/libxc/xc_dom_decompress_lz4.c
+++ b/tools/libxc/xc_dom_decompress_lz4.c
@@ -69,13 +69,14 @@ int xc_try_lz4_decode(
size -= 4;
} else {
msg = "invalid header";
- goto exit_2;
+ goto exit_1;
}
for (;;) {
if (size < 4) {
msg = "missing data";
- goto exit_2;
+ ret = -1;
+ goto exit_1;
}
chunksize = get_unaligned_le32(inp);
if (chunksize == ARCHIVE_MAGICNUMBER) {
@@ -87,7 +88,8 @@ int xc_try_lz4_decode(
size -= 4;
if (chunksize > size) {
msg = "insufficient input data";
- goto exit_2;
+ ret = -1;
+ goto exit_1;
}
dest_len = out_len - (outp - output);
@@ -95,7 +97,7 @@ int xc_try_lz4_decode(
&dest_len);
if (ret < 0) {
msg = "decoding failed";
- goto exit_2;
+ goto exit_1;
}
outp += dest_len;
@@ -110,13 +112,14 @@ int xc_try_lz4_decode(
if (size < 0) {
msg = "data corrupted";
- goto exit_2;
+ ret = -1;
+ goto exit_1;
}
inp += chunksize;
}
-exit_2:
+exit_1:
free(output);
exit_0:
DOMPRINTF("LZ4 decompression error: %s\n", msg);
--
1.7.10.4
Jan Beulich
2013-Nov-08 09:29 UTC
Re: [PATCH 1/2] xen: always set an error return code on lz4 decompression failures
>>> On 08.11.13 at 01:26, Matthew Daley <mattjd@gmail.com> wrote:As just sent to LKML, I''d like to do this with a one line change (reproduced below), and by addressing it in the original first (and us just inheriting the fix). I''d recommend the same for patch 2, as that also touches a clone of the original code. Jan unlz4: always set an error return code on failures "ret", being set to -1 early on, gets cleared by the first invocation of lz4_decompress()/lz4_decompress_unknownoutputsize(), and hence subsequent failures wouldn''t be noticed by the caller without setting it back to -1 right after those calls. Reported-by: Matthew Daley <mattjd@gmail.com> Signed-off-by: Jan Beulich <jbeulich@suse.com> Cc: Kyungsik Lee <kyungsik.lee@lge.com> Cc: Andrew Morton <akpm@linux-foundation.org> --- a/lib/decompress_unlz4.c +++ b/lib/decompress_unlz4.c @@ -141,6 +141,7 @@ STATIC inline int INIT unlz4(u8 *input, goto exit_2; } + ret = -1; if (flush && flush(outp, dest_len) != dest_len) goto exit_2; if (output)