From 506f4e4f8c97b11241d471d7ec46a93e898c76ec Mon Sep 17 00:00:00 2001 From: Laurent Mazet Date: Fri, 11 Apr 2025 23:57:40 +0200 Subject: [PATCH] fix two potential null pointer exception --- makefile | 2 +- morep_simulator.c | 12 +++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/makefile b/makefile index 0233737..f9e2c47 100644 --- a/makefile +++ b/makefile @@ -1,6 +1,6 @@ # Default flags -CC = gcc +CC ?= gcc #INCLUDES = -I../debug -D__MEMORY_ALLOCATION__ INCLUDES += -DVERBOSE_COLOR=1 diff --git a/morep_simulator.c b/morep_simulator.c index cc5237d..f7b1989 100644 --- a/morep_simulator.c +++ b/morep_simulator.c @@ -385,7 +385,7 @@ int main (int argc, char **argv) VERBOSE (simul, TRACE, PRINTF ("no morep found '%s'\n", line)); continue; } - VERBOSE (simul, DEBUG, PRINTF ("work with %c[%s]\n", comm->mode ? 'T' : 'R', serv->name)); + VERBOSE (simul, DEBUG, PRINTF ("service %c:%s\n", comm->mode ? 'T' : 'R', serv->name)); /* skip space */ tmp = line + offset; @@ -423,6 +423,12 @@ int main (int argc, char **argv) msg = m; } } + /* avoid null pointer */ + if (msg == NULL) { + VERBOSE (simul, WARNING, PRINTF ("can't find msgtype %d for service %s\n", msgtype, serv->name)); + continue; + } + } /* check message and service */ @@ -430,7 +436,7 @@ int main (int argc, char **argv) VERBOSE (simul, WARNING, PRINTF ("message %s is not allowed for service %s (line '%s')\n", msg->name, serv->name, line)); continue; } - VERBOSE (simul, DEBUG, PRINTF ("work with message %s\n", msg->name)); + VERBOSE (simul, DEBUG, PRINTF ("message %s\n", msg->name)); CHANNEL_t pdu_channel = {0}; CLEAR_DATA_t pdu_clear_data = {0}; @@ -525,7 +531,7 @@ int main (int argc, char **argv) } /* check msg type */ if (msg == NULL) { - VERBOSE (simul, WARNING, PRINTF ("R:%s[%s] [SEQ=%d MSG=%d LEN=%d PDU=%d] message type is not allowed for this service\n", serv->name, comm->etype, seqnum, msg->msgtype, len, pdu)); + VERBOSE (simul, WARNING, PRINTF ("R:%s[%s] [SEQ=%d MSG=%d LEN=%d PDU=%d] message type is not allowed for this service\n", serv->name, comm->etype, seqnum, msgtype, len, pdu)); continue; } if (exp_msg->msgtype != msg->msgtype) { -- 2.30.2