summaryrefslogtreecommitdiff
path: root/tests/gtest_dlt_common.cpp
diff options
context:
space:
mode:
authorVo Trung Chi <chi.votrung@vn.bosch.com>2019-11-14 11:56:41 +0700
committerSaya Sugiura <39760799+ssugiura@users.noreply.github.com>2019-11-14 13:56:41 +0900
commit6530fe75d8642f18d87d22456462a9530129cbda (patch)
tree9c7847a0f01b835a4b2c34903368f8dee7090197 /tests/gtest_dlt_common.cpp
parentf773961cda69ecc5334013dc82734f29f3459d2e (diff)
downloadDLT-daemon-6530fe75d8642f18d87d22456462a9530129cbda.tar.gz
Avoided Seg fault in dlt_message_payload (#179) (#181)
* Avoided Seg fault in dlt_message_payload (#179) Avoided Seg fault by adding boundary check before buffer access. Signed-off-by: Ravi Sankar P <ponnurangamravi.sankar@in.bosch.com> Signed-off-by: Vo Trung Chi <chi.votrung@vn.bosch.com>
Diffstat (limited to 'tests/gtest_dlt_common.cpp')
-rw-r--r--tests/gtest_dlt_common.cpp71
1 files changed, 29 insertions, 42 deletions
diff --git a/tests/gtest_dlt_common.cpp b/tests/gtest_dlt_common.cpp
index f5df4f5..364afbe 100644
--- a/tests/gtest_dlt_common.cpp
+++ b/tests/gtest_dlt_common.cpp
@@ -3124,56 +3124,43 @@ TEST(t_dlt_message_payload, normal)
}
TEST(t_dlt_message_payload, abnormal)
{
-/* DltFile file; */
-/* static char text[DLT_DAEMON_TEXTSIZE]; */
+ DltFile file;
+ static char text[DLT_DAEMON_TEXTSIZE];
/* Get PWD so file and filter can be used*/
-/* char pwd[100]; */
-/* getcwd(pwd, 100); */
-/* char openfile[114]; */
-/* sprintf(openfile, "%s/testfile.dlt", pwd); */
+ char pwd[100];
+ getcwd(pwd, 100);
+ char openfile[114];
+ sprintf(openfile, "%s/testfile.dlt", pwd);
/*---------------------------------------*/
/* Uninizialised, expected -1 */
-/* EXPECT_GE(DLT_RETURN_ERROR, dlt_message_payload(&file.msg, text, DLT_DAEMON_TEXTSIZE, DLT_OUTPUT_HEX, 0)); */
-/* EXPECT_GE(DLT_RETURN_ERROR, dlt_message_payload(&file.msg, text, DLT_DAEMON_TEXTSIZE, DLT_OUTPUT_ASCII, 0)); */
-/* EXPECT_GE(DLT_RETURN_ERROR, dlt_message_payload(&file.msg, text, DLT_DAEMON_TEXTSIZE, DLT_OUTPUT_MIXED_FOR_PLAIN, 0)); */
-/* EXPECT_GE(DLT_RETURN_ERROR, dlt_message_payload(&file.msg, text, DLT_DAEMON_TEXTSIZE, DLT_OUTPUT_MIXED_FOR_HTML, 0)); */
-/* EXPECT_GE(DLT_RETURN_ERROR, dlt_message_payload(&file.msg, text, DLT_DAEMON_TEXTSIZE, DLT_OUTPUT_ASCII_LIMITED, 0)); */
-/* EXPECT_GE(DLT_RETURN_ERROR, dlt_message_payload(&file.msg, text, DLT_DAEMON_TEXTSIZE, DLT_OUTPUT_HEX, 1)); */
-/* EXPECT_GE(DLT_RETURN_ERROR, dlt_message_payload(&file.msg, text, DLT_DAEMON_TEXTSIZE, DLT_OUTPUT_ASCII, 1)); */
-/* EXPECT_GE(DLT_RETURN_ERROR, dlt_message_payload(&file.msg, text, DLT_DAEMON_TEXTSIZE, DLT_OUTPUT_MIXED_FOR_PLAIN, 1)); */
-/* EXPECT_GE(DLT_RETURN_ERROR, dlt_message_payload(&file.msg, text, DLT_DAEMON_TEXTSIZE, DLT_OUTPUT_MIXED_FOR_HTML, 1)); */
-/* EXPECT_GE(DLT_RETURN_ERROR, dlt_message_payload(&file.msg, text, DLT_DAEMON_TEXTSIZE, DLT_OUTPUT_ASCII_LIMITED, 1)); */
+ memset(&file, 0x00, sizeof(DltFile));
+
+ EXPECT_GE(DLT_RETURN_ERROR, dlt_message_payload(&file.msg, text, DLT_DAEMON_TEXTSIZE, DLT_OUTPUT_HEX, 0));
+ EXPECT_GE(DLT_RETURN_ERROR, dlt_message_payload(&file.msg, text, DLT_DAEMON_TEXTSIZE, DLT_OUTPUT_ASCII, 0));
+ EXPECT_GE(DLT_RETURN_ERROR, dlt_message_payload(&file.msg, text, DLT_DAEMON_TEXTSIZE, DLT_OUTPUT_MIXED_FOR_PLAIN, 0));
+ EXPECT_GE(DLT_RETURN_ERROR, dlt_message_payload(&file.msg, text, DLT_DAEMON_TEXTSIZE, DLT_OUTPUT_MIXED_FOR_HTML, 0));
+ EXPECT_GE(DLT_RETURN_ERROR, dlt_message_payload(&file.msg, text, DLT_DAEMON_TEXTSIZE, DLT_OUTPUT_ASCII_LIMITED, 0));
+ EXPECT_GE(DLT_RETURN_ERROR, dlt_message_payload(&file.msg, text, DLT_DAEMON_TEXTSIZE, DLT_OUTPUT_HEX, 1));
+ EXPECT_GE(DLT_RETURN_ERROR, dlt_message_payload(&file.msg, text, DLT_DAEMON_TEXTSIZE, DLT_OUTPUT_ASCII, 1));
+ EXPECT_GE(DLT_RETURN_ERROR, dlt_message_payload(&file.msg, text, DLT_DAEMON_TEXTSIZE, DLT_OUTPUT_MIXED_FOR_PLAIN, 1));
+ EXPECT_GE(DLT_RETURN_ERROR, dlt_message_payload(&file.msg, text, DLT_DAEMON_TEXTSIZE, DLT_OUTPUT_MIXED_FOR_HTML, 1));
+ EXPECT_GE(DLT_RETURN_ERROR, dlt_message_payload(&file.msg, text, DLT_DAEMON_TEXTSIZE, DLT_OUTPUT_ASCII_LIMITED, 1));
/* USE own DLT_HEADER_SHOW , expected -1 */
-/* EXPECT_GE(DLT_RETURN_ERROR, dlt_message_payload(&file.msg, text, DLT_DAEMON_TEXTSIZE, 99, 0)); */
+ EXPECT_GE(DLT_RETURN_ERROR, dlt_message_payload(&file.msg, text, DLT_DAEMON_TEXTSIZE, 99, 0));
-/* EXPECT_LE(DLT_RETURN_OK, dlt_file_init(&file, 0)); */
-/* EXPECT_LE(DLT_RETURN_OK, dlt_file_open(&file, openfile, 0)); */
-/* while (dlt_file_read(&file,0)>=0){} */
-/* for(int i=0;i<file.counter;i++) */
-/* { */
-/* EXPECT_LE(DLT_RETURN_OK, dlt_file_message(&file, i, 0)); */
-/* EXPECT_GE(DLT_RETURN_ERROR, dlt_message_payload(&file.msg, text, DLT_DAEMON_TEXTSIZE, 99, 0)); */
-/* printf("%s \n",text); */
-/* } */
-/* EXPECT_LE(DLT_RETURN_OK, dlt_file_free(&file, 0)); */
-
- /* set verbose to 12345678 */
-/* EXPECT_LE(DLT_RETURN_OK, dlt_file_init(&file, 0)); */
-/* EXPECT_LE(DLT_RETURN_OK, dlt_file_open(&file, openfile, 0)); */
-/* while (dlt_file_read(&file,0)>=0){} */
-/* for(int i=0;i<file.counter;i++) */
-/* { */
-/* EXPECT_LE(DLT_RETURN_OK, dlt_file_message(&file, i, 0)); */
-/* EXPECT_GE(DLT_RETURN_ERROR, dlt_message_payload(&file.msg, text, DLT_DAEMON_TEXTSIZE, DLT_OUTPUT_HEX, 12345678)); */
-/* EXPECT_GE(DLT_RETURN_ERROR, dlt_message_payload(&file.msg, text, DLT_DAEMON_TEXTSIZE, DLT_OUTPUT_ASCII, 12345678)); */
-/* EXPECT_GE(DLT_RETURN_ERROR, dlt_message_payload(&file.msg, text, DLT_DAEMON_TEXTSIZE, DLT_OUTPUT_MIXED_FOR_PLAIN, 12345678)); */
-/* EXPECT_GE(DLT_RETURN_ERROR, dlt_message_payload(&file.msg, text, DLT_DAEMON_TEXTSIZE, DLT_OUTPUT_MIXED_FOR_HTML, 12345678)); */
-/* EXPECT_GE(DLT_RETURN_ERROR, dlt_message_payload(&file.msg, text, DLT_DAEMON_TEXTSIZE, DLT_OUTPUT_ASCII_LIMITED, 12345678)); */
-/* } */
-/* EXPECT_LE(DLT_RETURN_OK, dlt_file_free(&file, 0)); */
+ EXPECT_LE(DLT_RETURN_OK, dlt_file_init(&file, 0));
+ EXPECT_LE(DLT_RETURN_OK, dlt_file_open(&file, openfile, 0));
+ while (dlt_file_read(&file,0)>=0){}
+ for(int i=0;i<file.counter;i++)
+ {
+ EXPECT_LE(DLT_RETURN_OK, dlt_file_message(&file, i, 0));
+ EXPECT_GE(DLT_RETURN_ERROR, dlt_message_payload(&file.msg, text, DLT_DAEMON_TEXTSIZE, 99, 0));
+ printf("%s \n",text);
+ }
+ EXPECT_LE(DLT_RETURN_OK, dlt_file_free(&file, 0));
}
TEST(t_dlt_message_payload, nullpointer)
{