From f09a51088ab885988d7db5bcd815e03078df5e9e Mon Sep 17 00:00:00 2001 From: Michael Sauer Date: Sat, 19 Sep 2026 23:49:47 +0200 Subject: [PATCH] fix(sacn): validate universe range (1..63999), add boundary tests Universe 0 and values >63999 are reserved per E1.31 spec and must be rejected. Priority is deliberately not validated (compared relatively in later tasks only). Test coverage: - test_universe_zero_rejected: rejects universe 0 - test_universe_too_high_rejected: rejects universe 64000 - test_universe_is_read: continues to accept universe 63999 --- src/net/nl_e131.c | 12 ++++++++++-- test/test_e131.c | 16 ++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/net/nl_e131.c b/src/net/nl_e131.c index 5671318..46b0183 100644 --- a/src/net/nl_e131.c +++ b/src/net/nl_e131.c @@ -47,8 +47,16 @@ bool nl_e131_parse(const uint8_t *buf, size_t len, nl_e131_packet_t *out) if (buf[112] & 0x80u) /* Preview-Daten duerfen laut E1.31 nicht ausgegeben werden */ return false; - out->universe = be16(buf + 113); - out->priority = buf[108]; + /* Universe must be in range 1..63999; 0 and values >63999 are reserved. */ + uint16_t universe = be16(buf + 113); + if (universe == 0u || universe > 63999u) + return false; + + out->universe = universe; + out->priority = buf[108]; /* taken as-is without range check; priority is only compared + * relatively in later tasks, never against absolute bounds. + * strict validation would silently drop light data from slightly + * non-conformant senders, worse than accepting 0..255 */ out->sequence = buf[111]; out->terminated = (buf[112] & 0x40u) != 0u; out->slot_count = (uint16_t)(pvc - 1u); diff --git a/test/test_e131.c b/test/test_e131.c index f583f2b..b03158f 100644 --- a/test/test_e131.c +++ b/test/test_e131.c @@ -178,6 +178,20 @@ static void test_universe_is_read(void) TEST_ASSERT_EQUAL_UINT8(7, p.sequence); } +static void test_universe_zero_rejected(void) +{ + nl_e131_packet_t p; + build(0, 100, 0, 0, 6); + TEST_ASSERT_FALSE(nl_e131_parse(pkt, pkt_len, &p)); +} + +static void test_universe_too_high_rejected(void) +{ + nl_e131_packet_t p; + build(64000, 100, 0, 0, 6); + TEST_ASSERT_FALSE(nl_e131_parse(pkt, pkt_len, &p)); +} + int main(void) { UNITY_BEGIN(); @@ -197,5 +211,7 @@ int main(void) RUN_TEST(test_property_value_count_mismatch); RUN_TEST(test_too_short_and_too_long); RUN_TEST(test_universe_is_read); + RUN_TEST(test_universe_zero_rejected); + RUN_TEST(test_universe_too_high_rejected); return UNITY_END(); }