RIC-939 : Fixes for static error checks 77/9577/1
authorAbdulwahid W <abdulwahid.w@nokia.com>
Thu, 10 Nov 2022 13:04:51 +0000 (16:04 +0300)
committerAbdulwahid W <abdulwahid.w@nokia.com>
Thu, 10 Nov 2022 13:04:51 +0000 (16:04 +0300)
Signed-off-by: Abdulwahid W <abdulwahid.w@nokia.com>
Change-Id: If9f0a0e899d6bd4ea4566cd2b26d194fcf32b3ad

CMakeLists.txt
src/rmr/common/src/rt_generic_static.c
src/rmr/si/src/rmr_si.c
src/rmr/si/src/si95/sisendt.c

index 11bc04f..0448c63 100644 (file)
@@ -42,7 +42,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 "8" )
-set( patch_level "3" )
+set( patch_level "4" )
 
 set( install_root "${CMAKE_INSTALL_PREFIX}" )
 set( install_inc "include/rmr" )
index 9a8d1fd..56b124e 100644 (file)
@@ -46,6 +46,8 @@
 #include <unistd.h>
 #include <netdb.h>
 #include <pthread.h>
+#include <immintrin.h>
+#include <stdbool.h>
 
 #include <RIC_message_types.h>         // needed for route manager messages
 
@@ -374,7 +376,7 @@ static void alarm_if_drops( uta_ctx_t* uctx, uta_ctx_t* pctx ) {
        must be at the start of a word (i.e. must be immediatly preceeded by whitespace).
 */
 static char* clip( char* buf ) {
-       char*   tok;
+       char*   tok=NULL;
 
        while( *buf && isspace( *buf ) ) {                                                      // skip leading whitespace
                buf++;
@@ -390,7 +392,7 @@ static char* clip( char* buf ) {
                }
        }
 
-       for( tok = buf + (strlen( buf ) - 1); tok > buf && isspace( *tok ); tok-- );    // trim trailing spaces too
+       for( tok = buf + (strlen( buf ) - 1); tok > buf && isspace_with_fence( *tok ); tok-- ); // trim trailing spaces too
        *(tok+1) = 0;
 
        return buf;
@@ -952,7 +954,7 @@ static void parse_rt_rec( uta_ctx_t* ctx,  uta_ctx_t* pctx, char* buf, int vleve
        int     grp;                                                    // group number
        rtable_ent_t const*     rte;                    // route table entry added
        char*   tokens[128];
-       char*   tok;                                            // pointer into a token or string
+       char*   tok=NULL;                                               // pointer into a token or string
        char    wbuf[1024];
 
        if( ! buf ) {
@@ -967,7 +969,7 @@ static void parse_rt_rec( uta_ctx_t* ctx,  uta_ctx_t* pctx, char* buf, int vleve
        while( *buf && isspace( *buf ) ) {                                                      // skip leading whitespace
                buf++;
        }
-       for( tok = buf + (strlen( buf ) - 1); tok > buf && isspace( *tok ); tok-- );    // trim trailing spaces too
+       for( tok = buf + (strlen( buf ) - 1); tok > buf && isspace_with_fence( *tok ); tok-- ); // trim trailing spaces too
        *(tok+1) = 0;
 
        memset( tokens, 0, sizeof( tokens ) );
@@ -1539,6 +1541,7 @@ static route_table_t* prep_new_rt( uta_ctx_t* ctx, int all ) {
                rt = NULL;
        }
 
+       pthread_mutex_destroy(ctx->rtgate);
        rt = uta_rt_clone( ctx, ctx->rtable, rt, all );         // also sets the ephash pointer
        if( rt != NULL ) {                                                                      // very small chance for nil, but not zero, so test
                rt->ref_count = 0;                                                              // take no chances; ensure it's 0!
@@ -1689,4 +1692,10 @@ static inline void release_rt( uta_ctx_t* ctx, route_table_t* rt ) {
        }
        pthread_mutex_unlock( ctx->rtgate );
 }
+
+int isspace_with_fence(int c) {
+       _mm_lfence();
+       return isspace( c );
+}
+
 #endif
index bd858de..52007fc 100644 (file)
@@ -796,6 +796,7 @@ static void* init( char* uproto_port, int def_msg_size, int flags ) {
                return init_err( "unable to allocate ep hash\n", ctx, proto_port, ENOMEM );
        }
 
+       pthread_mutex_destroy(ctx->rtgate);
        ctx->rtable = rt_clone_space( ctx, NULL, NULL, 0 );     // create an empty route table so that wormhole/rts calls can be used
        if( flags & RMRFL_NOTHREAD ) {                                          // no thread prevents the collector start for very special cases
                ctx->rtable_ready = 1;                                                  // route based sends will always fail, but rmr is ready for the non thread case
index 26c5f93..752a955 100644 (file)
@@ -69,7 +69,7 @@ extern int SIsendt( struct ginfo_blk *gptr, int fd, char *ubuf, int ulen ) {
                for( tpptr = gptr->tplist; tpptr != NULL && tpptr->fd != fd; tpptr = tpptr->next ) ; //  find the block if out of map's range
        }
        if( tpptr != NULL ) {
-               if( (fd = tpptr->fd) < 0 ) {                    // fd user given might not be real, and this might be closed already
+               if( (fd = tpptr->fd) < 0 || (fd = tpptr->fd) >= FD_SETSIZE ) {                  // fd user given might not be real, and this might be closed already
                        errno = EBADFD;
                        return SI_ERROR;
                }