Properly initialize the message lists.

The message lists are implemented using a TAILQ from queue(3).  The heads
of the list must be initialized using the provided macros, since the field
called 'tqh_last' is non-zero in the initial state.  This patch fixes a
potential null pointer dereference by properly initializing the queues.

Note that there is no actual bug in the current code, because it uses the
lists in such a way as to initialize 'tqh_last' before any dereference.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
master
Richard Cochran 2015-11-01 12:30:51 +01:00
parent 3f2ef92052
commit 01dcf7e9ac
2 changed files with 2 additions and 1 deletions

2
msg.c
View File

@ -42,7 +42,7 @@ struct message_storage {
struct ptp_message msg; struct ptp_message msg;
} PACKED; } PACKED;
static TAILQ_HEAD(msg_pool, ptp_message) msg_pool; static TAILQ_HEAD(msg_pool, ptp_message) msg_pool = TAILQ_HEAD_INITIALIZER(msg_pool);
static struct { static struct {
int total; int total;

1
port.c
View File

@ -376,6 +376,7 @@ static int add_foreign_master(struct port *p, struct ptp_message *m)
return 0; return 0;
} }
memset(fc, 0, sizeof(*fc)); memset(fc, 0, sizeof(*fc));
TAILQ_INIT(&fc->messages);
LIST_INSERT_HEAD(&p->foreign_masters, fc, list); LIST_INSERT_HEAD(&p->foreign_masters, fc, list);
fc->port = p; fc->port = p;
fc->dataset.sender = m->header.sourcePortIdentity; fc->dataset.sender = m->header.sourcePortIdentity;