GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — HAProxyMessage: validate the length of all TLV types (#17834) · netty/netty@f25d65c

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • codec-haproxy/src
    • main/java/io/netty/handler/codec/haproxy
      • HAProxyMessage.java
    • test/java/io/netty/handler/codec/haproxy
      • HAProxyMessageDecoderTest.java
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎codec-haproxy/src/main/java/io/netty/handler/codec/haproxy/HAProxyMessage.java‎

Copy file name to clipboardExpand all lines: codec-haproxy/src/main/java/io/netty/handler/codec/haproxy/HAProxyMessage.java
+4-4Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -308,15 +308,15 @@ private static HAProxyTLV readNextTLV(final ByteBuf header, int nestingLevel) {
308308
final HAProxyTLV.Type type = HAProxyTLV.Type.typeForByteValue(typeAsByte);
309309

310310
final int length = header.readUnsignedShort();
311+
if (length > header.readableBytes()) {
312+
throw new HAProxyProtocolException("TLV length must be smaller or equal the readable bytes (" +
313+
header.readableBytes() + ") but was: " + length);
314+
}
311315
switch (type) {
312316
case PP2_TYPE_SSL:
313317
if (length < 5) {
314318
throw new HAProxyProtocolException("TLV length must be at least 5 but was: " + length);
315319
}
316-
if (length > header.readableBytes()) {
317-
throw new HAProxyProtocolException("TLV length must be smaller or equal the readable bytes (" +
318-
header.readableBytes() + ") but was: " + length);
319-
}
320320
// Slice the rawContent but only retain it if we didn't see an error as otherwise we might
321321
// leak.
322322
final ByteBuf rawContent = header.slice(header.readerIndex(), length);
Collapse file

‎codec-haproxy/src/test/java/io/netty/handler/codec/haproxy/HAProxyMessageDecoderTest.java‎

Copy file name to clipboardExpand all lines: codec-haproxy/src/test/java/io/netty/handler/codec/haproxy/HAProxyMessageDecoderTest.java
+20Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1420,6 +1420,26 @@ public void execute() {
14201420
});
14211421
}
14221422

1423+
@ParameterizedTest
1424+
@ValueSource(bytes = { 0x01, 0x02, 0x21, 0x22, 0x30, (byte) 0xE0 })
1425+
public void testInvalidNonSslTLVLengthCorrectlyHandled(byte type) {
1426+
final ByteBuf data = Unpooled.buffer();
1427+
data.writeBytes(new byte[] {
1428+
0x0D, 0x0A, 0x0D, 0x0A, 0x00, 0x0D, 0x0A, 0x51, 0x55, 0x49, 0x54, 0x0A,
1429+
0x21, 0x11, // v2, cmd=PROXY, TCP over IPv4
1430+
0x00, 0x10, // 12 bytes of addresses and ports + 4 bytes of TLV
1431+
0x7F, 0x00, 0x00, 0x01,
1432+
0x7F, 0x00, 0x00, 0x01,
1433+
0x04, (byte) 0xD2,
1434+
0x00, 0x50,
1435+
type, 0x00, (byte) 0xFF, 'h' // TLV with a length of 255, but only one byte of value
1436+
});
1437+
1438+
assertThrows(HAProxyProtocolException.class, () -> ch.writeInbound(data));
1439+
assertFalse(ch.isActive());
1440+
assertFalse(ch.finish());
1441+
}
1442+
14231443
@Test
14241444
public void testReadTlvsLeaksRetainedBufferWhenSecondSSLTLVIsMalformed() {
14251445
ByteBuf data = Unpooled.buffer();

0 commit comments

Comments
0 (0)
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.