From 9c859ffdca5d9203a8f2025eec84a3276bf2e042 Mon Sep 17 00:00:00 2001 From: Andrew Johnson Date: Thu, 1 Jun 2017 15:37:34 -0500 Subject: [PATCH] Protect casStatsFetch() if called before rsrv_init() Also ensures clientQ is initialized before creating clientQlock. Fixes LP: #1694966 --- src/rsrv/caservertask.c | 15 ++++++++++----- src/rsrv/server.h | 4 ++-- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/rsrv/caservertask.c b/src/rsrv/caservertask.c index 7867babe6..71c35ec1b 100644 --- a/src/rsrv/caservertask.c +++ b/src/rsrv/caservertask.c @@ -241,7 +241,6 @@ int rsrv_init (void) clientQlock = epicsMutexMustCreate(); - ellInit ( &clientQ ); freeListInitPvt ( &rsrvClientFreeList, sizeof(struct client), 8 ); freeListInitPvt ( &rsrvChanFreeList, sizeof(struct channel_in_use), 512 ); freeListInitPvt ( &rsrvEventFreeList, sizeof(struct event_ext), 512 ); @@ -951,16 +950,22 @@ struct client *create_tcp_client ( SOCKET sock ) void casStatsFetch ( unsigned *pChanCount, unsigned *pCircuitCount ) { - LOCK_CLIENTQ; + if ( ! clientQlock ) { + *pCircuitCount = 0; + *pChanCount = 0; + return; + } + + LOCK_CLIENTQ; { int circuitCount = ellCount ( &clientQ ); if ( circuitCount < 0 ) { - *pCircuitCount = 0; + *pCircuitCount = 0; } else { - *pCircuitCount = (unsigned) circuitCount; + *pCircuitCount = (unsigned) circuitCount; } *pChanCount = rsrvChannelCount; } - UNLOCK_CLIENTQ; + UNLOCK_CLIENTQ; } diff --git a/src/rsrv/server.h b/src/rsrv/server.h index fc7627f80..e4b947ea9 100644 --- a/src/rsrv/server.h +++ b/src/rsrv/server.h @@ -156,7 +156,7 @@ enum ctl {ctlInit, ctlRun, ctlPause, ctlExit}; /* NOTE: external used so they remember the state across loads */ #ifdef GLBLSOURCE # define GLBLTYPE -# define GLBLTYPE_INIT(A) +# define GLBLTYPE_INIT(A) = A #else # define GLBLTYPE extern # define GLBLTYPE_INIT(A) @@ -176,7 +176,7 @@ GLBLTYPE int CASDEBUG; GLBLTYPE SOCKET IOC_sock; GLBLTYPE SOCKET IOC_cast_sock; GLBLTYPE unsigned short ca_server_port; -GLBLTYPE ELLLIST clientQ; /* locked by clientQlock */ +GLBLTYPE ELLLIST clientQ GLBLTYPE_INIT(ELLLIST_INIT); GLBLTYPE ELLLIST beaconAddrList; GLBLTYPE epicsMutexId clientQlock; GLBLTYPE struct client *prsrv_cast_client;