sstaub / sACN

Send and receive sACN DMX packets following ANSI E1.31
MIT License
16 stars 1 forks source link

Receiver::parse() accesses elements outside of array #3

Closed ndebruin closed 1 year ago

ndebruin commented 1 year ago

Ran into this issue on a Pi Pico while trying to use this library with the Pico-DMX library.

Lines 61 & 62 in sACN.cpp attempt to verify the postamble of the sacnPacket against predefined values stored in sACNDefs.h. (seen below)

    if (sacnPacket[POSTAMBLE_ADDR] != POSTAMBLE[POSTAMBLE_ADDR]) return false;
    if (sacnPacket[POSTAMBLE_ADDR + 1] != POSTAMBLE[POSTAMBLE_ADDR + 1]) return false;

In sACNDefs.h, POSTAMBLE_ADDR is defined as 2. When using this index to access data in POSTAMBLE (defined as {0x00, 0x00}), it accesses data outside of that array.

In sACN_Receive there appears to be nothing stored in the memory directly after the POSTAMBLE array, and so the test reads the correct value.

However, in more complex sketches, there is the possibility of other data being stored at that memory address.

Simple fix might be to replace POSTAMBLE_ADDR in the POSTAMBLE index with 0. EX:

    if (sacnPacket[POSTAMBLE_ADDR] != POSTAMBLE[0]) return false;
    if (sacnPacket[POSTAMBLE_ADDR + 1] != POSTAMBLE[1]) return false;

Tested in my specific sketch, and works. Not sure if this change would make something else silently fail.

sstaub commented 1 year ago

I see the same problem on preamble. I will fix it.

sstaub commented 1 year ago

make a new release 1.0.1

sstaub commented 1 year ago

1.0.2 should work