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 — Port 5.0: HAProxyMessage: decode TLVs with an empty value at the end … · netty/netty@d9c5725

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-5Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -299,8 +299,8 @@ private static HAProxyTLV readNextTLV(final ByteBuf header, int nestingLevel) {
299299
throw new HAProxyProtocolException(
300300
"Maximum TLV nesting level reached: " + nestingLevel + " (expected: < " + MAX_NESTING_LEVEL + ')');
301301
}
302-
// We need at least 4 bytes for a TLV
303-
if (header.readableBytes() < 4) {
302+
// We need at least 3 bytes for a TLV: the type and the length, the value may be empty
303+
if (header.readableBytes() < 3) {
304304
return null;
305305
}
306306

@@ -324,7 +324,7 @@ private static HAProxyTLV readNextTLV(final ByteBuf header, int nestingLevel) {
324324
final byte client = byteBuf.readByte();
325325
final int verify = byteBuf.readInt();
326326

327-
if (byteBuf.readableBytes() >= 4) {
327+
if (byteBuf.readableBytes() >= 3) {
328328

329329
final List<HAProxyTLV> encapsulatedTlvs = new ArrayList<HAProxyTLV>(4);
330330
try {
@@ -334,8 +334,7 @@ private static HAProxyTLV readNextTLV(final ByteBuf header, int nestingLevel) {
334334
break;
335335
}
336336
encapsulatedTlvs.add(haProxyTLV);
337-
} while (byteBuf.readableBytes() >= 4);
338-
337+
} while (byteBuf.readableBytes() >= 3);
339338
} catch (Throwable t) {
340339
// Release all previously read TLVs before rethrowing as otherwise we would leak.
341340
releaseDeep(encapsulatedTlvs);
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
+49Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1476,4 +1476,53 @@ public void wellFormedNestedHeaderDecodesAndReleasesCleanly() {
14761476
assertTrue(header.release(), "buffer fully released");
14771477
assertEquals(0, header.refCnt());
14781478
}
1479+
1480+
@Test
1481+
public void testEmptyTLVsAtEndOfHeader() throws Exception {
1482+
final ByteBuf data = Unpooled.buffer();
1483+
data.writeBytes(new byte[] {
1484+
0x0D, 0x0A, 0x0D, 0x0A, 0x00, 0x0D, 0x0A, 0x51, 0x55, 0x49, 0x54, 0x0A,
1485+
0x21, 0x11, // v2, cmd=PROXY, TCP over IPv4
1486+
0x00, 0x1A, // 12 bytes of addresses and ports + 14 bytes of TLVs
1487+
0x7F, 0x00, 0x00, 0x01,
1488+
0x7F, 0x00, 0x00, 0x01,
1489+
0x04, (byte) 0xD2,
1490+
0x00, 0x50,
1491+
0x20, 0x00, 0x08, 0x01, 0x00, 0x00, 0x00, 0x00, // PP2_TYPE_SSL, client=1, verify=0
1492+
0x21, 0x00, 0x00, // with an empty PP2_SUBTYPE_SSL_VERSION
1493+
0x04, 0x00, 0x00 // empty PP2_TYPE_NOOP
1494+
});
1495+
1496+
assertTrue(ch.writeInbound(data));
1497+
HAProxyMessage msg = ch.readInbound();
1498+
List<HAProxyTLV> tlvs = msg.tlvs();
1499+
assertEquals(3, tlvs.size());
1500+
HAProxySSLTLV ssl = (HAProxySSLTLV) tlvs.get(0);
1501+
assertEquals(1, ssl.encapsulatedTLVs().size());
1502+
assertEquals(HAProxyTLV.Type.PP2_TYPE_SSL_VERSION, ssl.encapsulatedTLVs().get(0).type());
1503+
assertEquals(0, ssl.encapsulatedTLVs().get(0).content().readableBytes());
1504+
assertEquals(HAProxyTLV.Type.OTHER, tlvs.get(2).type());
1505+
assertEquals(0x04, tlvs.get(2).typeByteValue());
1506+
assertEquals(0, tlvs.get(2).content().readableBytes());
1507+
assertTrue(msg.release());
1508+
assertFalse(ch.finish());
1509+
}
1510+
1511+
@Test
1512+
public void testIncompleteTLVAtEndOfHeader() {
1513+
final ByteBuf data = Unpooled.buffer();
1514+
data.writeBytes(new byte[] {
1515+
0x0D, 0x0A, 0x0D, 0x0A, 0x00, 0x0D, 0x0A, 0x51, 0x55, 0x49, 0x54, 0x0A,
1516+
0x21, 0x11, // v2, cmd=PROXY, TCP over IPv4
1517+
0x00, 0x0F, // 12 bytes of addresses and ports + 3 bytes of TLV
1518+
0x7F, 0x00, 0x00, 0x01,
1519+
0x7F, 0x00, 0x00, 0x01,
1520+
0x04, (byte) 0xD2,
1521+
0x00, 0x50,
1522+
0x01, 0x00, 0x01 // PP2_TYPE_ALPN with a length of 1, but no value
1523+
});
1524+
1525+
assertThrows(HAProxyProtocolException.class, () -> ch.writeInbound(data));
1526+
assertFalse(ch.isActive());
1527+
}
14791528
}

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.