diff options
author | Gary E. Miller <gem@rellim.com> | 2018-07-14 12:17:35 -0700 |
---|---|---|
committer | Gary E. Miller <gem@rellim.com> | 2018-07-14 12:17:35 -0700 |
commit | 6bba8b329fc7687b15863d30471d5af402467802 (patch) | |
tree | 10975c312ee76bf58c4f66b6997e07c4f5e5e4c3 /libgps_core.c | |
parent | 692427a17aeb54d69826def759cc1f1da605ba33 (diff) | |
download | gpsd-6bba8b329fc7687b15863d30471d5af402467802.tar.gz |
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.
Diffstat (limited to 'libgps_core.c')
-rw-r--r-- | libgps_core.c | 10 |
1 files changed, 8 insertions, 2 deletions
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 */ |