You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@plc4x.apache.org by cd...@apache.org on 2019/11/28 14:25:41 UTC

[plc4x] branch develop updated: - Fixed a problem that if an Iso on TCP packet didn't start with "0x03" then it wouldn't remove that byte and the driver would go into an infinite loop.

This is an automated email from the ASF dual-hosted git repository.

cdutz pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/plc4x.git


The following commit(s) were added to refs/heads/develop by this push:
     new 9d141e1  - Fixed a problem that if an Iso on TCP packet didn't start with "0x03" then it wouldn't remove that byte and the driver would go into an infinite loop.
9d141e1 is described below

commit 9d141e1cc5dc646332a3f4247f624746b676bf5a
Author: Christofer Dutz <ch...@c-ware.de>
AuthorDate: Thu Nov 28 15:25:28 2019 +0100

    - Fixed a problem that if an Iso on TCP packet didn't start with "0x03" then it wouldn't remove that byte and the driver would go into an infinite loop.
---
 .../apache/plc4x/java/isoontcp/protocol/IsoOnTcpProtocol.java  | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/plc4j/protocols/iso-on-tcp/src/main/java/org/apache/plc4x/java/isoontcp/protocol/IsoOnTcpProtocol.java b/plc4j/protocols/iso-on-tcp/src/main/java/org/apache/plc4x/java/isoontcp/protocol/IsoOnTcpProtocol.java
index afd6146..99ab801 100644
--- a/plc4j/protocols/iso-on-tcp/src/main/java/org/apache/plc4x/java/isoontcp/protocol/IsoOnTcpProtocol.java
+++ b/plc4j/protocols/iso-on-tcp/src/main/java/org/apache/plc4x/java/isoontcp/protocol/IsoOnTcpProtocol.java
@@ -87,6 +87,16 @@ public class IsoOnTcpProtocol extends PlcByteToMessageCodec<IsoOnTcpMessage> {
                 if (logger.isDebugEnabled()) {
                     logger.debug("Got Data: {}", ByteBufUtil.hexDump(in));
                 }
+                // Gobble up any garbage that might be still in the buffer until the buffer is
+                // empty or we reach the potential start of the next ISO on TCP packet.
+                while ((in.readableBytes() > 0) && (in.getByte(0) != ISO_ON_TCP_MAGIC_NUMBER)) {
+                    // Read and hereby remove the invalid byte.
+                    in.readByte();
+                }
+                // If there was nothing left, just give up.
+                if(in.readableBytes() == 0) {
+                    return;
+                }
                 exceptionCaught(ctx, new PlcProtocolException(
                     String.format("Expecting ISO on TCP magic number: %02X", ISO_ON_TCP_MAGIC_NUMBER)));
                 return;