From 386fc3ed893a2215784c76ffa745dd3fddaa451d Mon Sep 17 00:00:00 2001 From: Vedang Patel Date: Wed, 3 Oct 2018 09:41:48 -0700 Subject: [PATCH] clock: Add NULL check for best clock in clock_update_slave() This scenario will only be encountered when the clock transitions to the slave state without knowing who the master is. This will result in a segfault for BMCA with designated master and slave states (to be added in upcoming patches). Signed-off-by: Vedang Patel --- clock.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/clock.c b/clock.c index 0a000b9..56bc79b 100644 --- a/clock.c +++ b/clock.c @@ -636,7 +636,12 @@ static void clock_update_grandmaster(struct clock *c) static void clock_update_slave(struct clock *c) { struct parentDS *pds = &c->dad.pds; - struct ptp_message *msg = TAILQ_FIRST(&c->best->messages); + struct ptp_message *msg; + + if (!c->best) + return; + + msg = TAILQ_FIRST(&c->best->messages); c->cur.stepsRemoved = 1 + c->best->dataset.stepsRemoved; pds->parentPortIdentity = c->best->dataset.sender; pds->grandmasterIdentity = msg->announce.grandmasterIdentity;