From 58d233cb429514c0190cafa8cb328a4707c2cc30 Mon Sep 17 00:00:00 2001 From: dongjiuzhu1 Date: Sun, 29 Sep 2024 21:00:10 +0800 Subject: [PATCH] drivers/sensors/gnss: check invalid nmea statement to avoid parsebuffer overflow Signed-off-by: dongjiuzhu1 --- drivers/sensors/gnss_uorb.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/drivers/sensors/gnss_uorb.c b/drivers/sensors/gnss_uorb.c index 0905371ddb59c..92212647b0949 100644 --- a/drivers/sensors/gnss_uorb.c +++ b/drivers/sensors/gnss_uorb.c @@ -591,8 +591,15 @@ static void gnss_parse(FAR struct gnss_upperhalf_s *upper, { if (*buffer != '\r' && *buffer != '\n') { - upper->parsebuffer[upper->parsenext++] = *buffer; - continue; + if (upper->parsenext + 1 < GNSS_PARSE_BUFFERSIZE) + { + upper->parsebuffer[upper->parsenext++] = *buffer; + continue; + } + + upper->parsebuffer[upper->parsenext] = '\0'; + snerr("NMEA buffer overflow, invalid statement:%s\n", + upper->parsebuffer); } upper->parsebuffer[upper->parsenext] = '\0';