[OpenWrt-Devel] [PATCH 1/2] nmea.c: Add null byte to nmea fields
Alexander Couzens
lynxis at fe80.eu
Fri Jun 29 17:19:11 EDT 2018
Either the main.c treat them as non-null terminated strings or
nmea adds a null byte to the fields.
Found-by: Coverity
Fixes CID 1431321 1431098
---
nmea.c | 12 ++++++------
nmea.h | 2 +-
2 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/nmea.c b/nmea.c
index 73ee722dfb7e..242bc21eda59 100644
--- a/nmea.c
+++ b/nmea.c
@@ -51,7 +51,7 @@ struct nmea_param {
} nmea_params[MAX_NMEA_PARAM];
static int nmea_bad_time;
-char longitude[32] = { 0 }, latitude[32] = { 0 }, course[16] = { 0 }, speed[16] = { 0 }, elevation[16] = { 0 };
+char longitude[33] = { 0 }, latitude[33] = { 0 }, course[17] = { 0 }, speed[17] = { 0 }, elevation[17] = { 0 };
int gps_valid = 0;
static void
@@ -136,8 +136,8 @@ nmea_rmc_cb(void)
if (*nmea_params[6].str == 'W')
lon *= -1.0;
- snprintf(latitude, sizeof(latitude), "%f", lat);
- snprintf(longitude, sizeof(longitude), "%f", lon);
+ snprintf(latitude, sizeof(latitude) - 1, "%f", lat);
+ snprintf(longitude, sizeof(longitude) - 1, "%f", lon);
DEBUG(3, "position: %s %s\n", latitude, longitude);
gps_timestamp();
@@ -149,7 +149,7 @@ nmea_gga_cb(void)
{
if (!gps_valid)
return;
- strncpy(elevation, nmea_params[9].str, sizeof(elevation));
+ strncpy(elevation, nmea_params[9].str, sizeof(elevation) - 1);
DEBUG(4, "height: %s\n", elevation);
}
@@ -158,8 +158,8 @@ nmea_vtg_cb(void)
{
if (!gps_valid)
return;
- strncpy(course, nmea_params[1].str, sizeof(course));
- strncpy(speed, nmea_params[7].str, sizeof(speed));
+ strncpy(course, nmea_params[1].str, sizeof(course) - 1);
+ strncpy(speed, nmea_params[7].str, sizeof(speed) - 1);
DEBUG(4, "course: %s\n", course);
DEBUG(4, "speed: %s\n", speed);
}
diff --git a/nmea.h b/nmea.h
index c6f1896df986..9f46d299983e 100644
--- a/nmea.h
+++ b/nmea.h
@@ -23,7 +23,7 @@
#include <libubox/ustream.h>
-extern char longitude[32], latitude[32], course[16], speed[16], elevation[16];
+extern char longitude[33], latitude[33], course[17], speed[17], elevation[17];
extern int nmea_open(char *dev, struct ustream_fd *s, speed_t speed);
extern void gps_timestamp(void);
extern unsigned int adjust_clock;
--
2.18.0
_______________________________________________
openwrt-devel mailing list
openwrt-devel at lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel
More information about the openwrt-devel
mailing list