From 955ce64d08bd90a8fe30e3033ece95a0cf08d78b Mon Sep 17 00:00:00 2001 From: Abdulwahid W Date: Thu, 10 Nov 2022 16:04:51 +0300 Subject: [PATCH] RIC-939 : Fixes for static error checks Signed-off-by: Abdulwahid W Change-Id: If9f0a0e899d6bd4ea4566cd2b26d194fcf32b3ad --- CMakeLists.txt | 2 +- src/rmr/common/src/rt_generic_static.c | 17 +++++++++++++---- src/rmr/si/src/rmr_si.c | 1 + src/rmr/si/src/si95/sisendt.c | 2 +- 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 11bc04f..0448c63 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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" ) diff --git a/src/rmr/common/src/rt_generic_static.c b/src/rmr/common/src/rt_generic_static.c index 9a8d1fd..56b124e 100644 --- a/src/rmr/common/src/rt_generic_static.c +++ b/src/rmr/common/src/rt_generic_static.c @@ -46,6 +46,8 @@ #include #include #include +#include +#include #include // 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 diff --git a/src/rmr/si/src/rmr_si.c b/src/rmr/si/src/rmr_si.c index bd858de..52007fc 100644 --- a/src/rmr/si/src/rmr_si.c +++ b/src/rmr/si/src/rmr_si.c @@ -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 diff --git a/src/rmr/si/src/si95/sisendt.c b/src/rmr/si/src/si95/sisendt.c index 26c5f93..752a955 100644 --- a/src/rmr/si/src/si95/sisendt.c +++ b/src/rmr/si/src/si95/sisendt.c @@ -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; } -- 2.16.6