From 2b8b36c371f52b66a520f40c2370eb3cda14edf8 Mon Sep 17 00:00:00 2001 From: Andre Puschmann Date: Wed, 7 Jun 2017 15:03:14 +0200 Subject: [PATCH] fix debug_name handling in buffer_pool - possible bug discovered by coverity --- lib/include/srslte/common/buffer_pool.h | 5 +++-- lib/include/srslte/common/common.h | 6 +++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/include/srslte/common/buffer_pool.h b/lib/include/srslte/common/buffer_pool.h index 182c287e3..eec35b79a 100644 --- a/lib/include/srslte/common/buffer_pool.h +++ b/lib/include/srslte/common/buffer_pool.h @@ -76,7 +76,7 @@ public: { printf("%d buffers in queue\n", (int) used.size()); for (uint32_t i=0;idebug_name?used[i]->debug_name:"Undefined"); + printf("%s\n", strlen(used[i]->debug_name)?used[i]->debug_name:"Undefined"); } } @@ -97,7 +97,8 @@ public: } #ifdef SRSLTE_BUFFER_POOL_LOG_ENABLED if (debug_name) { - strncpy(b->debug_name, debug_name, 128); + strncpy(b->debug_name, debug_name, SRSLTE_BUFFER_POOL_LOG_NAME_LEN); + b->debug_name[SRSLTE_BUFFER_POOL_LOG_NAME_LEN-1] = 0; } #endif diff --git a/lib/include/srslte/common/common.h b/lib/include/srslte/common/common.h index d1f2f770f..5f13ab214 100644 --- a/lib/include/srslte/common/common.h +++ b/lib/include/srslte/common/common.h @@ -54,6 +54,7 @@ #ifdef SRSLTE_BUFFER_POOL_LOG_ENABLED #define pool_allocate (pool->allocate(__FUNCTION__)) +#define SRSLTE_BUFFER_POOL_LOG_NAME_LEN 128 #else #define pool_allocate (pool->allocate()) #endif @@ -121,7 +122,7 @@ public: uint8_t buffer[SRSLTE_MAX_BUFFER_SIZE_BYTES]; uint8_t *msg; #ifdef SRSLTE_BUFFER_POOL_LOG_ENABLED - char debug_name[128]; + char debug_name[SRSLTE_BUFFER_POOL_LOG_NAME_LEN]; #endif byte_buffer_t():N_bytes(0) @@ -129,6 +130,9 @@ public: timestamp_is_set = false; msg = &buffer[SRSLTE_BUFFER_HEADER_OFFSET]; next = NULL; +#ifdef SRSLTE_BUFFER_POOL_LOG_ENABLED + debug_name[0] = 0; +#endif } byte_buffer_t(const byte_buffer_t& buf) {