Skip to contentSkip to conversation

xen: always set an error return code on lz4 decompression failures

PATCH In review Matthew Daley 3 participants 9 messages Nov 8, 2013 – Jan 28, 2014 Library code

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 xen: always set an error return code on lz4 decompression failures

---
 xen/common/unlz4.c |    6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
xen/common/unlz4.c +5 -1
index 195d829..ae87f4c 100644
@@ -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;
 		}
 
Signature · 1 line
1.7.10.4
#1 lore raw

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.

---
 tools/libxc/xc_dom_decompress_lz4.c |   15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)
tools/libxc/xc_dom_decompress_lz4.c +9 -6
index 4787535..b980186 100644
@@ -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);
Signature · 1 line
1.7.10.4
#2 lore raw

PATCH 1/1 libxc/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.

Linux commit: 2a1d689c9ba42a6066540fb221b6ecbd6298b728

tools/libxc/xc_dom_decompress_lz4.c +1 -0
@@ -98,6 +98,7 @@ int xc_try_lz4_decode(
 			goto exit_2;
 		}
 
+		ret = -1;
 		outp += dest_len;
 		size -= chunksize;
 

libxc/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.

Linux commit: 2a1d689c9ba42a6066540fb221b6ecbd6298b728

tools/libxc/xc_dom_decompress_lz4.c +1 -0
@@ -98,6 +98,7 @@ int xc_try_lz4_decode(
 			goto exit_2;
 		}
 
+		ret = -1;
 		outp += dest_len;
 		size -= chunksize;
 

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

Acked-by on v1 1/1
#3 lore raw

Re: [PATCH] libxc/unlz4: always set an error return code on failures

Quoted 9 lines · Jan Beulich

"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.

Linux commit: 2a1d689c9ba42a6066540fb221b6ecbd6298b728

#4 lore raw

Re: [PATCH] libxc/unlz4: always set an error return code on failures

Quoted 6 lines · Ian Campbell
Quoted 5 lines · Jan Beulich

"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.

Quoted 6 lines
Quoted 4 lines

Linux commit: 2a1d689c9ba42a6066540fb221b6ecbd6298b728

This is a pretty obvious bug fix, which is already in Linux (where this code originates), so I've applied it.

I guess you will do the Xen side one yourself.

Ian.

#5 lore raw

Re: [PATCH] libxc/unlz4: always set an error return code on failures

Quoted 13 lines
Quoted 1 line
Quoted 1 line · Ian Campbell
Quoted 11 lines · Ian Campbell
Quoted 9 lines · Jan Beulich

"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.

Linux commit: 2a1d689c9ba42a6066540fb221b6ecbd6298b728

Quoted 6 lines
Quoted 1 line

This is a pretty obvious bug fix, which is already in Linux (where this code originates), so I've applied it.

I guess you will do the Xen side one yourself.

I was sort of hoping to get an ack from Keir, and wanted to apply both as a pair. Now that you did the tools side, I guess I'll call it trivial enough and apply the hypervisor side as is.

Jan

#6 lore raw

Re: [PATCH] libxc/unlz4: always set an error return code on failures

Quoted 15 lines · Jan Beulich
Quoted 15 lines
Quoted 1 line
Quoted 1 line · Ian Campbell
Quoted 12 lines · Ian Campbell
Quoted 9 lines · Jan Beulich

"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.

Linux commit: 2a1d689c9ba42a6066540fb221b6ecbd6298b728

Quoted 7 lines
Quoted 4 lines

This is a pretty obvious bug fix, which is already in Linux (where this code originates), so I've applied it.

I guess you will do the Xen side one yourself.

I was sort of hoping to get an ack from Keir, and wanted to apply both as a pair.

Oops, sorry!

Quoted 2 lines

Now that you did the tools side, I guess I'll call it
trivial enough and apply the hypervisor side as is.

FWIW: Acked-By: Ian Campbell <[email protected]> on that...

#7 lore raw
In reply to Matthew Daley
Quoted 1 line
Quoted 1 line
Quoted 1 line · Matthew Daley

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.

lib/decompress_unlz4.c +1 -0
@@ -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)
#8 lore raw

PATCH 1/1 xen/unlz4: always set an error return code on failures

In reply to Matthew Daley

"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.

Linux commit: 2a1d689c9ba42a6066540fb221b6ecbd6298b728

xen/common/unlz4.c +1 -0
@@ -133,6 +133,7 @@ STATIC int INIT unlz4(unsigned char *inp
 			goto exit_2;
 		}
 
+		ret = -1;
 		if (flush && flush(outp, dest_len) != dest_len)
 			goto exit_2;
 		if (output)

xen/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.

Linux commit: 2a1d689c9ba42a6066540fb221b6ecbd6298b728

xen/common/unlz4.c +1 -0
@@ -133,6 +133,7 @@ STATIC int INIT unlz4(unsigned char *inp
 			goto exit_2;
 		}
 
+		ret = -1;
 		if (flush && flush(outp, dest_len) != dest_len)
 			goto exit_2;
 		if (output)

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel