From 154d225b934de70387533f3dfaf5d449a580c28b Mon Sep 17 00:00:00 2001 From: michael-methner Date: Tue, 11 Oct 2022 04:53:12 +0200 Subject: 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 --- include/dlt/dlt_common.h | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/dlt/dlt_common.h b/include/dlt/dlt_common.h index 100a481..ead124f 100644 --- a/include/dlt/dlt_common.h +++ b/include/dlt/dlt_common.h @@ -1631,15 +1631,28 @@ int16_t dlt_getloginfo_conv_ascii_to_uint16_t(char *rp, int *rp_count); */ int16_t dlt_getloginfo_conv_ascii_to_int16_t(char *rp, int *rp_count); + +/** + * Convert get log info from ASCII to string (with '\0' termination) + * + * @param rp char + * @param rp_count int + * @param wp char Array needs to be 1 byte larger than len to store '\0' + * @param len int + */ +void dlt_getloginfo_conv_ascii_to_string(char *rp, int *rp_count, char *wp, int len); + + /** - * Convert get log info from ASCII to ID + * Convert get log info from ASCII to ID (without '\0' termination) * * @param rp char * @param rp_count int * @param wp char * @param len int + * @return position of last read character in wp */ -void dlt_getloginfo_conv_ascii_to_id(char *rp, int *rp_count, char *wp, int len); +int dlt_getloginfo_conv_ascii_to_id(char *rp, int *rp_count, char *wp, int len); /** * Convert from hex ASCII to binary -- cgit v1.2.1