From 6bba8b329fc7687b15863d30471d5af402467802 Mon Sep 17 00:00:00 2001 From: "Gary E. Miller" Date: Sat, 14 Jul 2018 12:17:35 -0700 Subject: gps_read(): fix some nasty buffer overruns and corruptions. Now pass an optional message buffer to gps_read(). Finally the JSON display in cgps works. Thanks to Virgin Orbit for their support fixing this bug. --- libgps_core.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'libgps_core.c') diff --git a/libgps_core.c b/libgps_core.c index 29ac6da1..e02ff1b9 100644 --- a/libgps_core.c +++ b/libgps_core.c @@ -146,12 +146,18 @@ int gps_close(struct gps_data_t *gpsdata CONDITIONALLY_UNUSED) return status; } -int gps_read(struct gps_data_t *gpsdata CONDITIONALLY_UNUSED) +int gps_read(struct gps_data_t *gpsdata CONDITIONALLY_UNUSED, + char *message, int message_len) /* read from a gpsd connection */ { int status = -1; libgps_debug_trace((DEBUG_CALLS, "gps_read() begins\n")); + if ((NULL != message) && (0 < message_len)) { + /* be sure message is zero length */ + /* we do not memset() as this is time critical input path */ + *message = '\0'; + } #ifdef SHM_EXPORT_ENABLE if (BAD_SOCKET((intptr_t)(gpsdata->gps_fd))) { @@ -161,7 +167,7 @@ int gps_read(struct gps_data_t *gpsdata CONDITIONALLY_UNUSED) #ifdef SOCKET_EXPORT_ENABLE if (status == -1 && !BAD_SOCKET((intptr_t)(gpsdata->gps_fd))) { - status = gps_sock_read(gpsdata); + status = gps_sock_read(gpsdata, message, message_len); } #endif /* SOCKET_EXPORT_ENABLE */ -- cgit v1.2.1