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
This commit is contained in:
Michael Sauer
2026-09-19 23:49:47 +02:00
parent cdbbe31831
commit f09a51088a
2 changed files with 26 additions and 2 deletions
+10 -2
View File
@@ -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 */ if (buf[112] & 0x80u) /* Preview-Daten duerfen laut E1.31 nicht ausgegeben werden */
return false; return false;
out->universe = be16(buf + 113); /* Universe must be in range 1..63999; 0 and values >63999 are reserved. */
out->priority = buf[108]; 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->sequence = buf[111];
out->terminated = (buf[112] & 0x40u) != 0u; out->terminated = (buf[112] & 0x40u) != 0u;
out->slot_count = (uint16_t)(pvc - 1u); out->slot_count = (uint16_t)(pvc - 1u);
+16
View File
@@ -178,6 +178,20 @@ static void test_universe_is_read(void)
TEST_ASSERT_EQUAL_UINT8(7, p.sequence); 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) int main(void)
{ {
UNITY_BEGIN(); UNITY_BEGIN();
@@ -197,5 +211,7 @@ int main(void)
RUN_TEST(test_property_value_count_mismatch); RUN_TEST(test_property_value_count_mismatch);
RUN_TEST(test_too_short_and_too_long); RUN_TEST(test_too_short_and_too_long);
RUN_TEST(test_universe_is_read); RUN_TEST(test_universe_is_read);
RUN_TEST(test_universe_zero_rejected);
RUN_TEST(test_universe_too_high_rejected);
return UNITY_END(); return UNITY_END();
} }