2727 */
2828#include <stddef.h>
2929#include <stdlib.h>
30-
31- #include <BPSecLib_Private.h>
30+ #include <string.h>
3231#include <sys/types.h>
32+ #include <m-array.h>
3333
34+ #include <BPSecLib_Private.h>
3435#include "SamplePolicyProvider.h"
3536
37+ /** @struct BSLP_SecOperPtrList_t
38+ * Defines a basic list of ::BSL_SecOper_t pointers.
39+ */
40+ /// @cond Doxygen_Suppress
41+ // NOLINTBEGIN
42+ // GCOV_EXCL_START
43+ M_ARRAY_DEF (BSLP_SecOperPtrList , BSL_SecOper_t * , M_PTR_OPLIST )
44+ // GCOV_EXCL_STOP
45+ // NOLINTEND
46+ /// @endcond
47+
3648static bool BSLP_PolicyProvider_IsConsistent (const BSLP_PolicyProvider_t * self )
3749{
3850 ASSERT_ARG_NONNULL (self );
@@ -164,15 +176,15 @@ int BSLP_QueryPolicy(const void *user_data, BSL_SecurityActionSet_t *output_acti
164176 const BSLP_PolicyRule_t * rule = & self -> rules [index ];
165177 if (!BSLP_PolicyRule_IsConsistent (rule ))
166178 {
167- BSL_LOG_ERR ("Rule `%s` is not consistent" , m_string_get_cstr ( rule -> description ) );
179+ BSL_LOG_ERR ("Rule `%s` is not consistent" , rule -> description );
168180 continue ;
169181 }
170- BSL_LOG_DEBUG ("Evaluating against rule `%s`" , m_string_get_cstr ( rule -> description ) );
182+ BSL_LOG_DEBUG ("Evaluating against rule `%s`" , rule -> description );
171183
172184 if (!BSLP_PolicyPredicate_IsMatch (rule -> predicate , location , primary_block .field_src_node_id ,
173185 primary_block .field_dest_eid ))
174186 {
175- BSL_LOG_DEBUG ("Rule `%s` not a match" , m_string_get_cstr ( rule -> description ) );
187+ BSL_LOG_DEBUG ("Rule `%s` not a match" , rule -> description );
176188 continue ;
177189 }
178190
@@ -258,7 +270,7 @@ int BSLP_QueryPolicy(const void *user_data, BSL_SecurityActionSet_t *output_acti
258270 BSL_LOG_INFO ("append to end" );
259271 BSLP_SecOperPtrList_push_back (secops , sec_oper );
260272 }
261- BSL_LOG_INFO ("Created sec operation for rule `%s`" , m_string_get_cstr ( rule -> description ) );
273+ BSL_LOG_INFO ("Created sec operation for rule `%s`" , rule -> description );
262274 }
263275 BSL_PrimaryBlock_deinit (& primary_block );
264276
@@ -408,7 +420,12 @@ int BSLP_PolicyRule_Init(BSLP_PolicyRule_t *self, const char *desc, BSLP_PolicyP
408420{
409421 ASSERT_ARG_NONNULL (self );
410422 memset (self , 0 , sizeof (* self ));
411- string_init_set_str (self -> description , desc );
423+
424+ size_t desc_sz = strnlen (desc , BSLP_POLICYPREDICATE_ARRAY_CAPACITY );
425+ self -> description = BSL_MALLOC (desc_sz + 1 );
426+ strncpy (self -> description , desc , desc_sz );
427+ self -> description [desc_sz ] = '\0' ;
428+
412429 self -> sec_block_type = sec_block_type ;
413430 self -> target_block_type = target_block_type ;
414431 self -> predicate = predicate ;
@@ -424,9 +441,8 @@ int BSLP_PolicyRule_Init(BSLP_PolicyRule_t *self, const char *desc, BSLP_PolicyP
424441void BSLP_PolicyRule_Deinit (BSLP_PolicyRule_t * self )
425442{
426443 ASSERT_ARG_EXPR (BSLP_PolicyRule_IsConsistent (self ));
427- BSL_LOG_INFO ("BSLP_PolicyRule_Deinit: %s, nparams=%zu" , m_string_get_cstr (self -> description ),
428- BSLB_SecParamList_size (self -> params ));
429- string_clear (self -> description );
444+ BSL_LOG_INFO ("BSLP_PolicyRule_Deinit: %s, nparams=%zu" , self -> description , BSLB_SecParamList_size (self -> params ));
445+ BSL_FREE (self -> description );
430446 BSLB_SecParamList_clear (self -> params );
431447 memset (self , 0 , sizeof (* self ));
432448}
@@ -486,7 +502,7 @@ int BSLP_PolicyRule_EvaluateAsSecOper(const BSLP_PolicyRule_t *self, BSL_SecOper
486502 const BSL_SecParam_t * param = BSLB_SecParamList_cref (pit );
487503 BSL_SecOper_AppendParam (sec_oper , param );
488504 }
489- BSL_LOG_INFO ("Created sec operation for rule `%s`" , m_string_get_cstr ( self -> description ) );
505+ BSL_LOG_INFO ("Created sec operation for rule `%s`" , self -> description );
490506
491507 return BSL_SUCCESS ;
492508}
0 commit comments