summaryrefslogtreecommitdiff
path: root/src/shared
diff options
context:
space:
mode:
authorMichael Methner <mmethner@de.adit-jv.com>2022-10-05 13:37:59 +0200
committerMichael Methner <mmethner@de.adit-jv.com>2022-10-05 13:38:27 +0200
commit6d706e15277b7cca52390ddca7d3083c52b4eaee (patch)
treea6e1144e25f112e4340a4a209fc7439d93b1a542 /src/shared
parent61704169cbf2756b2ea084a0ecfdc8cf34f5cc75 (diff)
downloadDLT-daemon-6d706e15277b7cca52390ddca7d3083c52b4eaee.tar.gz
Avoid memory corruption behind buffer wp in function dlt_getloginfo_conv_ascii_to_id
- Introduced new function dlt_getloginfo_conv_ascii_to_string for '\0' terminated strings - Avoid printing garbage characters in dlt-control after APID and CTID (which are not null terminated anymore) - Added unit test for dlt_client_parse_get_log_info_resp_text and dlt_getloginfo_conv_ascii_to_string Signed-off-by: Michael Methner <mmethner@de.adit-jv.com>
Diffstat (limited to 'src/shared')
-rw-r--r--src/shared/dlt_common.c23
1 files changed, 18 insertions, 5 deletions
diff --git a/src/shared/dlt_common.c b/src/shared/dlt_common.c
index adda5db..7168951 100644
--- a/src/shared/dlt_common.c
+++ b/src/shared/dlt_common.c
@@ -4082,17 +4082,31 @@ int16_t dlt_getloginfo_conv_ascii_to_int16_t(char *rp, int *rp_count)
return (signed char)strtol(num_work, &endptr, 16);
}
-void dlt_getloginfo_conv_ascii_to_id(char *rp, int *rp_count, char *wp, int len)
+void dlt_getloginfo_conv_ascii_to_string(char *rp, int *rp_count, char *wp, int len)
+{
+ if ((rp == NULL ) || (rp_count == NULL ) || (wp == NULL ))
+ return;
+ /* ------------------------------------------------------
+ * from: [72 65 6d 6f ] -> to: [0x72,0x65,0x6d,0x6f,0x00]
+ * ------------------------------------------------------ */
+
+ int count = dlt_getloginfo_conv_ascii_to_id(rp, rp_count, wp, len);
+ *(wp + count) = '\0';
+
+ return;
+}
+
+int dlt_getloginfo_conv_ascii_to_id(char *rp, int *rp_count, char *wp, int len)
{
char number16[3] = { 0 };
char *endptr;
int count;
if ((rp == NULL) || (rp_count == NULL) || (wp == NULL))
- return;
+ return 0;
/* ------------------------------------------------------
- * from: [72 65 6d 6f ] -> to: [0x72,0x65,0x6d,0x6f,0x00]
+ * from: [72 65 6d 6f ] -> to: [0x72,0x65,0x6d,0x6f]
* ------------------------------------------------------ */
for (count = 0; count < len; count++) {
number16[0] = *(rp + *rp_count + 0);
@@ -4101,8 +4115,7 @@ void dlt_getloginfo_conv_ascii_to_id(char *rp, int *rp_count, char *wp, int len)
*rp_count += 3;
}
- *(wp + count) = 0;
- return;
+ return count;
}
void dlt_hex_ascii_to_binary(const char *ptr, uint8_t *binary, int *size)