Address complaints by code scanner 25/5025/1 4.4.1
authorE. Scott Daniels <daniels@research.att.com>
Tue, 10 Nov 2020 13:38:52 +0000 (08:38 -0500)
committerE. Scott Daniels <daniels@research.att.com>
Tue, 10 Nov 2020 13:38:52 +0000 (08:38 -0500)
This change addresses complaints generated by a recent code scan

Issue-ID: RIC-673

Signed-off-by: E. Scott Daniels <daniels@research.att.com>
Change-Id: I230449eced30477e13ec3eb867a5e16f67d4fae8

13 files changed:
CHANGES_CORE.txt
CMakeLists.txt
docs/rel-notes.rst
src/rmr/common/src/logging.c
src/rmr/common/src/ring_static.c
src/rmr/common/src/rt_generic_static.c
src/rmr/common/src/rtc_static.c
src/rmr/common/src/tools_static.c
src/rmr/si/src/rmr_si.c
src/rmr/si/src/rtable_si_static.c
src/rmr/si/src/si95/siestablish.c
src/rmr/si/src/si95/sipoll.c
src/rmr/si/src/si95/siwait.c

index a3e1373..fa92133 100644 (file)
@@ -5,6 +5,9 @@
 # API and build change  and fix summaries. Doc correctsions
 # and/or changes are not mentioned here; see the commit messages.
 
+2020 November 4; Version 4.4.1
+       Changes to correct complaints generated by a code scan. (RIC-673)
+
 2020 November 4; Version 4.4.0
        Changes to address a potential race condition when route tables
        arrive in quick succession.  (RIC-674)
index 2ac15d7..dd189f4 100644 (file)
@@ -41,7 +41,7 @@ cmake_minimum_required( VERSION 3.5 )
 
 set( major_version "4" )               # should be automatically populated from git tag later, but until CI process sets a tag we use this
 set( minor_version "4" )
-set( patch_level "0" )
+set( patch_level "1" )
 
 set( install_root "${CMAKE_INSTALL_PREFIX}" )
 set( install_inc "include/rmr" )
index a37304b..7b3d7a7 100644 (file)
@@ -22,6 +22,14 @@ the need to leap frog versions ceased, and beginning with
 version 4.0.0, the RMR versions should no longer skip.
 
 
+2020 November 4; Version 4.4.1
+------------------------------
+
+Changes to correct complaints generated by a code scan.
+(Ric-673)
+
+
+
 2020 November 4; Version 4.4.0
 ------------------------------
 
index 65fb745..0407eed 100644 (file)
@@ -156,6 +156,8 @@ extern void rmr_vlog( int write_level, char* fmt, ... ) {
 
        vsnprintf( body, sizeof( msg ) - (hlen+2), fmt, argp );                 // add in user message formatting it along the way
        fprintf( stderr, "%s", msg );                                                                   // we grew from printfs so all existing msg have \n; assume there
+
+       va_end( argp );
 }
 
 /*
@@ -190,6 +192,8 @@ extern void rmr_vlog_force( int write_level, char* fmt, ... ) {
 
        vsnprintf( body, sizeof( msg ) - (hlen+2), fmt, argp );                 // add in user message formatting it along the way
        fprintf( stderr, "%s", msg );                                                                   // we grew from printfs so all existing msg have \n; assume there
+
+       va_end( argp );
 }
 
 // -------------------- public functions that are needed -----------------
index b54d815..da2a9bd 100644 (file)
@@ -85,12 +85,12 @@ static void* uta_mk_ring( int size ) {
        }
 
        r->nelements = size;            // because we always have an empty element when full
-       if( (r->data = (void **) malloc( sizeof( void** ) * (r->nelements + 1) )) == NULL ) {
+       if( (r->data = (void **) malloc( sizeof( void* ) * (r->nelements + 1) )) == NULL ) {
                free( r );
                return NULL;
        }
 
-       memset( r->data, 0, sizeof( void** ) * r->nelements );
+       memset( r->data, 0, sizeof( void* ) * r->nelements );
        r->pfd = eventfd( 0, EFD_SEMAPHORE | EFD_NONBLOCK );            // in semaphore mode counter is maintained with each insert/extract
        return (void *) r;
 }
index 4f8fa12..532a6bf 100644 (file)
@@ -712,15 +712,13 @@ static void meid_parser( uta_ctx_t* ctx, uta_ctx_t* pctx, rmr_mbuf_t* mbuf, char
                }
                parse_meid_ar( ctx->new_rtable,  tokens[1], tokens[2], vlevel );
                ctx->new_rtable->mupdates++;
+               return;
        }
 
-       if( strcmp( tokens[0], "mme_del" ) == 0 ) {
-               if( ntoks < 2 ) {
-                       rmr_vlog( RMR_VL_ERR, "meid_parse: mme_del record didn't have enough tokens\n" );
-                       return;
-               }
+       if( strcmp( tokens[0], "mme_del" ) == 0 ) {                                             // ntoks < 2 already validated
                parse_meid_del( ctx->new_rtable,  tokens[1], vlevel );
                ctx->new_rtable->mupdates++;
+               return;
        }
 }
 
index 2deef8e..9aca092 100644 (file)
@@ -78,8 +78,9 @@ static void* rtc_file( void* vctx ) {
                if( vfd >= 0 ) {
                        wbuf[0] = 0;
                        lseek( vfd, 0, 0 );
-                       read( vfd, wbuf, 10 );
-                       vlevel = atoi( wbuf );
+                       if( read( vfd, wbuf, 10 ) > 0 ) {
+                               vlevel = atoi( wbuf );
+                       }
                }
 
                read_static_rt( ctx, vlevel );                                          // seed the route table if one provided
@@ -98,8 +99,9 @@ static int refresh_vlevel( int vfd ) {
        if( vfd >= 0 ) {                                        // if file is open, read current value
                rbuf[0] = 0;
                lseek( vfd, 0, 0 );
-               read( vfd, rbuf, 10 );
-               vlevel = atoi( rbuf );
+               if( read( vfd, rbuf, 10 ) > 0 ) {
+                       vlevel = atoi( rbuf );
+               }
        }
 
        return vlevel;
index a69db35..cc95fc1 100644 (file)
@@ -80,7 +80,7 @@ static inline int zt_buf_fill( char* dest, char const* src, int len ) {
        char const*     sp;
        int                     n;              // num moved
 
-       if( dest == NULL && src == NULL ) {
+       if( dest == NULL || src == NULL ) {
                return -1;
        }
 
@@ -334,7 +334,7 @@ static if_addrs_t*  mk_ip_list( char* port ) {
        struct  ifaddrs *ele;           // pointer into the list
        char    octs[NI_MAXHOST+1];
        char    wbuf[NI_MAXHOST+128];
-       char*   fmt;
+       char*   fmt = NULL;                     // address format (v4 or v6)
        char*   envp;                           // at the environment var if there
        char*   target_if = NULL;       // target interface supplied by ENV_BIND_IF
        char*   tok;
@@ -379,7 +379,7 @@ static if_addrs_t*  mk_ip_list( char* port ) {
                                        }
                                }
 
-                               if( *octs ) {
+                               if( *octs  && fmt != NULL ) {                           // possible that we didn't recognise the format (v4 or v6), don't try if we didn't
                                        if( (tok = strchr( octs, '%' )) != NULL ) {                     // for unknown reasons some ip6 addrs have %if-name appended; truncate
                                                *tok = 0;
                                        }
index 9b2444a..85e058b 100644 (file)
@@ -544,7 +544,7 @@ static void* init(  char* uproto_port, int def_msg_size, int flags ) {
        uta_ctx_t*      ctx = NULL;
        char    bind_info[256];                         // bind info
        char*   proto = "tcp";                          // pointer into the proto/port string user supplied
-       char*   port;
+       char*   port;                                           // pointer into the proto_port buffer at the port value
        char*   interface = NULL;                       // interface to bind to (from RMR_BIND_IF, 0.0.0.0 if not defined)
        char*   proto_port;
        char    wbuf[1024];                                     // work buffer
@@ -660,6 +660,7 @@ static void* init(  char* uproto_port, int def_msg_size, int flags ) {
        ctx->my_name = (char *) malloc( sizeof( char ) * RMR_MAX_SRC );
        if( snprintf( ctx->my_name, RMR_MAX_SRC, "%s:%s", wbuf, port ) >= RMR_MAX_SRC ) {                       // our registered name is host:port
                rmr_vlog( RMR_VL_CRIT, "rmr_init: hostname + port must be less than %d characters; %s:%s is not\n", RMR_MAX_SRC, wbuf, port );
+               free( proto_port );                                     // some scanners complain that port is not freed; it CANNOT be
                return NULL;
        }
 
index e0e3dc6..c348b7f 100644 (file)
@@ -177,12 +177,12 @@ extern endpoint_t*  uta_add_ep( route_table_t* rt, rtable_ent_t* rte, char* ep_n
                }
                memset( rrg, 0, sizeof( *rrg ) );
 
-               if( (rrg->epts = (endpoint_t **) malloc( sizeof( endpoint_t ) * MAX_EP_GROUP )) == NULL ) {
+               if( (rrg->epts = (endpoint_t **) malloc( sizeof( endpoint_t* ) * MAX_EP_GROUP )) == NULL ) {
                        rmr_vlog( RMR_VL_WARN, "rmr_add_ep: malloc failed for group endpoint array: group=%d\n", group );
                        free( rrg );
                        return NULL;
                }
-               memset( rrg->epts, 0, sizeof( endpoint_t ) * MAX_EP_GROUP );
+               memset( rrg->epts, 0, sizeof( endpoint_t* ) * MAX_EP_GROUP );
 
                rte->rrgroups[group] = rrg;
 
@@ -224,7 +224,7 @@ static int uta_epsock_byname( uta_ctx_t* ctx, char* ep_name, int* nn_sock, endpo
 
        if( PARANOID_CHECKS ) {
                if( ctx == NULL ) {
-                       if( DEBUG ) rmr_vlog( RMR_VL_DEBUG, "epsock_byname: parinoia check pop ctx=%p\n", ctx, rt );
+                       if( DEBUG ) rmr_vlog( RMR_VL_DEBUG, "epsock_byname: parinoia check pop ctx=%p rt=%p\n", ctx, rt );
                        return FALSE;
                }
                rt = get_rt( ctx );                             // get active rt and bump ref count
index 53c8db5..d3068e0 100644 (file)
@@ -94,6 +94,9 @@ extern struct tp_blk *SIlisten_prep( struct ginfo_blk *gptr, int type, char* abu
 
                alen = SIgenaddr( abuf, protocol, family, tptr->type, &addr );  //  family == 0 for type that suits the address passed in
                if( alen <= 0 ) {
+                       if( addr != NULL ) {
+                               free( addr );           // not needed, but scanners complain if we don't overtly do this
+                       }
                        return NULL;
                }
 
@@ -190,6 +193,9 @@ extern struct tp_blk *SIconn_prep( struct ginfo_blk *gptr, int type, char *abuf,
 
                alen = SIgenaddr( abuf, protocol, family, tptr->type, &addr );  //  family == 0 for type that suits the address passed in
                if( alen <= 0 ) {
+                       if( addr != NULL ) {            // not needed, but scanners complain if we don't overtly do this
+                               free( addr );
+                       }
                        return NULL;
                }
 
index d736d14..aa85e8b 100644 (file)
@@ -42,9 +42,6 @@
 
 extern int SIpoll( struct ginfo_blk *gptr, int msdelay )
 {
- //extern int deaths;       //  number of children that died and are zombies
- //extern int sigflags;     //  flags set by the signal handler routine
-
  int fd;                       //  file descriptor for use in this routine
  int ((*cbptr)());             //  pointer to callback routine to call
  int status = SI_OK;              //  return status
@@ -113,7 +110,7 @@ extern int SIpoll( struct ginfo_blk *gptr, int msdelay )
 
          if( tpptr->flags & TPF_LISTENFD )     //  listen port setup by init?
           {                                    //  yes-assume new session req
-           status = SInewsession( gptr, tpptr );    //  make new session
+           SInewsession( gptr, tpptr );                   //  cannot do anything about failure, so ignore status
           }
          else                              //  data received on a regular port
           if( tpptr->type == SOCK_DGRAM )          //  udp socket?
@@ -128,6 +125,7 @@ extern int SIpoll( struct ginfo_blk *gptr, int msdelay )
                 status = (*cbptr)( gptr->cbtab[SI_CB_RDATA].cbdata, gptr->rbuf, status, buf );
                 SIcbstat( gptr, status, SI_CB_RDATA );    //  handle status
                                free( buf );
+                               buf = NULL;                                             // just to be safe
                }                              //  end if call back was defined
              }                                //  end if status was ok
             free( uaddr );
index 128c1a7..c14c5a9 100644 (file)
@@ -78,6 +78,7 @@ extern int SIwait( struct ginfo_blk *gptr ) {
 
        if( gptr->magicnum != MAGICNUM ) {                              //  if not a valid ginfo block 
                rmr_vlog( RMR_VL_CRIT, "SI95: wait: bad global info struct magic number is wrong\n" );
+               free( ibuf );
                return SI_ERROR;
        }