diff options
author | michael-methner <mmethner@de.adit-jv.com> | 2022-10-11 04:53:12 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-11 09:53:12 +0700 |
commit | 154d225b934de70387533f3dfaf5d449a580c28b (patch) | |
tree | f2601b9fe713bb01f047edf67328b9fd1dd8dead /src/shared/dlt_common.c | |
parent | e961a8f7c0f655a4379c8c6bcf745f89604c453f (diff) | |
download | DLT-daemon-154d225b934de70387533f3dfaf5d449a580c28b.tar.gz |
Avoid memory corruption behind buffer wp in function dlt_getloginfo_conv_ascii_to_id (#411)
* 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
- Use dlt_getloginfo_conv_ascii_to_string to get '\0' terminated for app_description and context_description
Signed-off-by: Michael Methner <mmethner@de.adit-jv.com>
Diffstat (limited to 'src/shared/dlt_common.c')
-rw-r--r-- | src/shared/dlt_common.c | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/src/shared/dlt_common.c b/src/shared/dlt_common.c index 2ab6ed9..4dfbc20 100644 --- a/src/shared/dlt_common.c +++ b/src/shared/dlt_common.c @@ -4084,17 +4084,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); @@ -4103,8 +4117,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) |