From ad8a6ab070803f2b0e0fa177fd6638c10db2dde3 Mon Sep 17 00:00:00 2001 From: Bui Nguyen Quoc Thanh Date: Mon, 10 May 2021 14:02:41 +0700 Subject: daemon: check the conf inputs The configuration of memory buffer size must be carefully parsed and validated to avoid segmentation fault Any misleading information in configuration file must be considered as major error and dlt-daemon should stop and raise error message to stderr This commit also corrects error handling of dlt_buffer_init_dynamic(). Signed-off-by: Bui Nguyen Quoc Thanh --- src/shared/dlt_common.c | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src/shared/dlt_common.c') diff --git a/src/shared/dlt_common.c b/src/shared/dlt_common.c index 9fe6c88..507c8ad 100644 --- a/src/shared/dlt_common.c +++ b/src/shared/dlt_common.c @@ -2350,6 +2350,14 @@ DltReturnValue dlt_buffer_init_dynamic(DltBuffer *buf, uint32_t min_size, uint32 head->write = 0; head->count = 0; buf->mem = (unsigned char *)(buf->shm + sizeof(DltBufferHead)); + + if (buf->min_size < (uint32_t)sizeof(DltBufferHead)) { + dlt_vlog(LOG_ERR, + "%s: min_size is too small [%u]\n", + __func__, buf->min_size); + return DLT_RETURN_WRONG_PARAMETER; + } + buf->size = (uint32_t) (buf->min_size - sizeof(DltBufferHead)); dlt_vlog(LOG_DEBUG, -- cgit v1.2.1