Skip to content

Commit 06e6b23

Browse files
DedeHaisofthack007
andauthored
bugfix in parsePacket(): accept short artnet packets (#5588) for 16_x
* bugfix in parsePacket(): accept short artnet packets * add min artnet packet size check and fix indentation --------- Co-authored-by: Frank Möhle <91616163+softhack007@users.noreply.github.com>
1 parent 0828173 commit 06e6b23

1 file changed

Lines changed: 22 additions & 18 deletions

File tree

wled00/src/dependencies/e131/ESPAsyncE131.cpp

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -99,33 +99,37 @@ bool ESPAsyncE131::initMulticast(uint16_t port, uint16_t universe, uint8_t n) {
9999

100100
void ESPAsyncE131::parsePacket(AsyncUDPPacket _packet) {
101101
bool error = false;
102-
uint8_t protocol = P_E131;
102+
uint8_t protocol = P_ARTNET;
103103
const size_t pktLen = _packet.length();
104104

105105
e131_packet_t *sbuff = reinterpret_cast<e131_packet_t *>(_packet.data());
106106

107107
// E1.31 packet identifier (ACN_ID = "ASC-E1.17"), need at least 16 bytes to safely read acn_id (offset 4, length 12).
108108
if (pktLen >= 16) {
109-
if (memcmp(sbuff->acn_id, ESPAsyncE131::ACN_ID, sizeof(sbuff->acn_id)))
110-
protocol = P_ARTNET;
109+
if (!memcmp(sbuff->acn_id, ESPAsyncE131::ACN_ID, sizeof(sbuff->acn_id)))
110+
protocol = P_E131;
111111
}
112112

113113
if (protocol == P_ARTNET) {
114-
if (memcmp(sbuff->art_id, ESPAsyncE131::ART_ID, sizeof(sbuff->art_id)))
115-
error = true; //not "Art-Net"
116-
if (sbuff->art_opcode != ARTNET_OPCODE_OPDMX && sbuff->art_opcode != ARTNET_OPCODE_OPPOLL)
117-
error = true; //not a DMX or poll packet
118-
} else { //E1.31 error handling
119-
if (htonl(sbuff->root_vector) != ESPAsyncE131::VECTOR_ROOT)
120-
error = true;
121-
if (htonl(sbuff->frame_vector) != ESPAsyncE131::VECTOR_FRAME)
122-
error = true;
123-
if (sbuff->dmp_vector != ESPAsyncE131::VECTOR_DMP)
124-
error = true;
125-
if (sbuff->property_values[0] != 0)
126-
error = true;
127-
}
128-
114+
if (pktLen < 10) {
115+
error = true; // Need at least Art-Net ID (8) + opcode (2)
116+
} else {
117+
if (memcmp(sbuff->art_id, ESPAsyncE131::ART_ID, sizeof(sbuff->art_id)))
118+
error = true; //not "Art-Net"
119+
if (sbuff->art_opcode != ARTNET_OPCODE_OPDMX && sbuff->art_opcode != ARTNET_OPCODE_OPPOLL)
120+
error = true; //not a DMX or poll packet
121+
}
122+
} else { //E1.31 error handling
123+
if (htonl(sbuff->root_vector) != ESPAsyncE131::VECTOR_ROOT)
124+
error = true;
125+
if (htonl(sbuff->frame_vector) != ESPAsyncE131::VECTOR_FRAME)
126+
error = true;
127+
if (sbuff->dmp_vector != ESPAsyncE131::VECTOR_DMP)
128+
error = true;
129+
if (sbuff->property_values[0] != 0)
130+
error = true;
131+
}
132+
129133
if (error && _packet.localPort() == DDP_DEFAULT_PORT) { //DDP packet
130134
error = false;
131135
protocol = P_DDP;

0 commit comments

Comments
 (0)