summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDinh Cong Toan <toan.dinhcong@vn.bosch.com>2020-12-01 15:02:27 +0700
committerSaya Sugiura <39760799+ssugiura@users.noreply.github.com>2021-01-06 09:27:28 +0900
commit929a02f18556b9f1109c84d784a56de1e36a6e41 (patch)
tree3df54d2f67cdaa9c7581fd0fd285f9abb63c1f64
parent6f4d05fe7c2a90b3e89837cbea9cac95c09ad746 (diff)
downloadDLT-daemon-929a02f18556b9f1109c84d784a56de1e36a6e41.tar.gz
gtest_dlt_common: fix seg fault when using memcpy().
- Checking size of buffer and size of message before using memcpy(). - Adding configuration file for testfilter in /tests/CMakeLists.txt. Signed-off-by: Dinh Cong Toan <toan.dinhcong@vn.bosch.com>
-rw-r--r--src/shared/dlt_common.c14
-rw-r--r--tests/CMakeLists.txt2
2 files changed, 11 insertions, 5 deletions
diff --git a/src/shared/dlt_common.c b/src/shared/dlt_common.c
index 1ae56c1..f8aa746 100644
--- a/src/shared/dlt_common.c
+++ b/src/shared/dlt_common.c
@@ -2392,9 +2392,11 @@ void dlt_buffer_write_block(DltBuffer *buf, int *write, const unsigned char *dat
*write += (int) size;
}
else {
- /* write two blocks */
- memcpy(buf->mem + *write, data, buf->size - (unsigned int) (*write));
- memcpy(buf->mem, data + buf->size - *write, size - buf->size + (unsigned int) (*write));
+ if(buf->size > (unsigned int) (*write)) {
+ /* write two blocks */
+ memcpy(buf->mem + *write, data, buf->size - (unsigned int) (*write));
+ memcpy(buf->mem, data + buf->size - *write, size - buf->size + (unsigned int) (*write));
+ }
*write += (int) (size - buf->size);
}
}
@@ -2417,9 +2419,11 @@ void dlt_buffer_read_block(DltBuffer *buf, int *read, unsigned char *data, unsig
*read +=(int) size;
}
else {
+ if(buf->size > (unsigned int) (*read)) {
/* read two blocks */
- memcpy(data, buf->mem + *read, buf->size - (unsigned int) (*read));
- memcpy(data + buf->size - *read, buf->mem, size - buf->size + (unsigned int) (*read));
+ memcpy(data, buf->mem + *read, buf->size - (unsigned int) (*read));
+ memcpy(data + buf->size - *read, buf->mem, size - buf->size + (unsigned int) (*read));
+ }
*read += (int) (size - buf->size);
}
}
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 53b3949..3b7bbe4 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -2,6 +2,8 @@
add_compile_options(-isystem ${gtest_SOURCE_DIR}/include)
configure_file(${PROJECT_SOURCE_DIR}/tests/testfile.dlt ${PROJECT_BINARY_DIR}/tests COPYONLY)
+configure_file(${PROJECT_SOURCE_DIR}/tests/testfilter.txt ${PROJECT_BINARY_DIR}/tests COPYONLY)
+configure_file(${PROJECT_SOURCE_DIR}/tests/testfile_filetransfer.txt ${PROJECT_BINARY_DIR}/tests COPYONLY)
if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
set(LIBRARIES gtest gtest_main)