Skip to content

Commit 4831375

Browse files
akoulakkoul-amz
andauthored
fix: use lzo1x_decompress_safe to prevent stack buffer overflow (#1245)
Replace lzo1x_decompress() with lzo1x_decompress_safe() in transop_decode_lzo(). The unsafe variant does not enforce the output buffer size limit, allowing a crafted compressed payload to overflow the N2N_PKT_BUF_SIZE (2048 byte) stack buffer in handle_PACKET(). The safe variant (already bundled in src/minilzo.c) validates output bounds during decompression, preventing the overflow. The post-decompression size check was ineffective because the overflow had already occurred before the check executed. CAN-2026-2035137 Co-authored-by: Akhil Koul <akkoul@amazon.com>
1 parent 98738bc commit 4831375

1 file changed

Lines changed: 3 additions & 5 deletions

File tree

src/transform_lzo.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
#include <stdlib.h> // for size_t, calloc, free, NULL
2222
#include <string.h> // for memset
2323
#include <sys/types.h> // for time_t
24-
#include "minilzo.h" // for lzo1x_1_compress, lzo1x_decompress, LZO1X_1_M...
24+
#include "minilzo.h" // for lzo1x_1_compress, lzo1x_decompress_safe, LZO1X_1_M...
2525
#include "n2n.h" // for n2n_trans_op_t, TRACE_ERROR, traceEvent, N2N_...
2626

2727

@@ -92,10 +92,8 @@ static int transop_decode_lzo (n2n_trans_op_t *arg,
9292
return 0;
9393
}
9494

95-
lzo1x_decompress(inbuf, in_len, outbuf, &deflated_len, NULL);
96-
97-
if(deflated_len > N2N_PKT_BUF_SIZE) {
98-
traceEvent(TRACE_ERROR, "decode_lzo outbuf wrong size (%ul) decompressed", deflated_len);
95+
if(lzo1x_decompress_safe(inbuf, in_len, outbuf, &deflated_len, NULL) != LZO_E_OK) {
96+
traceEvent(TRACE_ERROR, "decode_lzo decompression failed or output exceeds buffer");
9997
return 0;
10098
}
10199

0 commit comments

Comments
 (0)