From 4ba8b2e68407a141f5cccd3f3dac6e8137691659 Mon Sep 17 00:00:00 2001 From: Yasuyuki Tanaka Date: Wed, 12 Jul 2017 12:08:30 +0900 Subject: [PATCH] TSCH: add argument validation in tsch_schedule_add_link() The purpose is to avoid allocating a meaningless link, which could cause communication issue with a peer. --- os/net/mac/tsch/tsch-schedule.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/os/net/mac/tsch/tsch-schedule.c b/os/net/mac/tsch/tsch-schedule.c index e22b0b498..a0a56147b 100644 --- a/os/net/mac/tsch/tsch-schedule.c +++ b/os/net/mac/tsch/tsch-schedule.c @@ -180,6 +180,16 @@ tsch_schedule_add_link(struct tsch_slotframe *slotframe, struct tsch_link *l = NULL; if(slotframe != NULL) { /* We currently support only one link per timeslot in a given slotframe. */ + + /* Validation of specified timeslot and channel_offset */ + if(timeslot > (slotframe->size.val - 1)) { + LOG_ERR("! add_link invalid timeslot: %u\n", timeslot); + return NULL; + } else if(channel_offset > 15) { + LOG_ERR("! add_link invalid channel_offset: %u\n", channel_offset); + return NULL; + } + /* Start with removing the link currently installed at this timeslot (needed * to keep neighbor state in sync with link options etc.) */ tsch_schedule_remove_link_by_timeslot(slotframe, timeslot);