diff options
author | Vo Trung Chi <chi.votrung@vn.bosch.com> | 2019-11-14 11:56:41 +0700 |
---|---|---|
committer | Saya Sugiura <39760799+ssugiura@users.noreply.github.com> | 2019-11-14 13:56:41 +0900 |
commit | 6530fe75d8642f18d87d22456462a9530129cbda (patch) | |
tree | 9c7847a0f01b835a4b2c34903368f8dee7090197 /include/dlt | |
parent | f773961cda69ecc5334013dc82734f29f3459d2e (diff) | |
download | DLT-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 'include/dlt')
-rw-r--r-- | include/dlt/dlt_common.h | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/include/dlt/dlt_common.h b/include/dlt/dlt_common.h index a418e7d..f4248ea 100644 --- a/include/dlt/dlt_common.h +++ b/include/dlt/dlt_common.h @@ -313,14 +313,21 @@ enum { { memcpy(dst, src, DLT_ID_SIZE); src += DLT_ID_SIZE; length -= DLT_ID_SIZE; } \ } -# define DLT_MSG_READ_STRING(dst, src, maxlength, length) \ +#define DLT_MSG_READ_STRING(dst, src, maxlength, dstlength, length) \ +{ \ + if ((maxlength < 0) || (length <= 0) || (dstlength < length) || (maxlength < length)) \ { \ - if (((maxlength) < 0) || ((length) < 0) || ((maxlength) < (length))) \ - { maxlength = -1; } \ - else \ - { memcpy(dst, src, length); dlt_clean_string(dst, length); dst[length] = 0; \ - src += length; maxlength -= length; } \ - } + maxlength = -1; \ + } \ + else \ + { \ + memcpy(dst, src, length); \ + dlt_clean_string(dst, length); \ + dst[length] = 0; \ + src += length; \ + maxlength -= length; \ + } \ +} # define DLT_MSG_READ_NULL(src, maxlength, length) \ { \ |