diff options
-rw-r--r-- | driver_nmea0183.c | 30 | ||||
-rw-r--r-- | test/daemon/april6_2019.log | 6 | ||||
-rw-r--r-- | test/daemon/april6_2019.log.chk | 2 |
3 files changed, 34 insertions, 4 deletions
diff --git a/driver_nmea0183.c b/driver_nmea0183.c index b0c71964..30e07f88 100644 --- a/driver_nmea0183.c +++ b/driver_nmea0183.c @@ -6,6 +6,7 @@ /* for vsnprintf() FreeBSD wants __ISO_C_VISIBLE >= 1999 */ #define __ISO_C_VISIBLE 1999 +#include <ctype.h> /* for isdigit() */ #include <stdio.h> #include <stdlib.h> #include <stdbool.h> @@ -133,6 +134,31 @@ static int merge_ddmmyy(char *ddmmyy, struct gps_device_t *session) int mon = DD(ddmmyy + 2); int mday = DD(ddmmyy); int year; + int i; + + if (NULL == ddmmyy) { + return 1; + } + for (i = 0; i < 6; i++) { + if (0 == isdigit(ddmmyy[i])) { + /* catches NUL and non-digits */ + /* Telit HE910 can set year to "-9" */ + gpsd_log(&session->context->errout, LOG_WARN, + "merge_ddmmyy(%s), malformed date\n", ddmmyy); + return 2; + } + } + /* check for termination */ + if ('\0' != ddmmyy[6]) { + /* missing NUL */ + gpsd_log(&session->context->errout, LOG_WARN, + "merge_ddmmyy(%s), malformed date\n", ddmmyy); + return 3; + } + + yy = DD(ddmmyy + 4); + mon = DD(ddmmyy + 2); + mday = DD(ddmmyy); /* check for century wrap */ if (session->nmea.date.tm_year % 100 == 99 && yy == 0) @@ -142,11 +168,11 @@ static int merge_ddmmyy(char *ddmmyy, struct gps_device_t *session) if ( (1 > mon ) || (12 < mon ) ) { gpsd_log(&session->context->errout, LOG_WARN, "merge_ddmmyy(%s), malformed month\n", ddmmyy); - return 1; + return 4; } else if ( (1 > mday ) || (31 < mday ) ) { gpsd_log(&session->context->errout, LOG_WARN, "merge_ddmmyy(%s), malformed day\n", ddmmyy); - return 1; + return 5; } else { gpsd_log(&session->context->errout, LOG_DATA, "merge_ddmmyy(%s) sets year %d\n", diff --git a/test/daemon/april6_2019.log b/test/daemon/april6_2019.log index 6e33f3d1..c2abd321 100644 --- a/test/daemon/april6_2019.log +++ b/test/daemon/april6_2019.log @@ -3,7 +3,11 @@ # Submitter: Gary E. Miller <gem@rellim.com> # Date: 2019-3-14 # Location: 48 29.0005 N, 000 22.0016 E -# Note: Bad year at moment of 2nd GPS epoch roll over +# Note: Bad year at moment of 1st GPS epoch roll over on: +# "1999-08-22T00:02:31.420Z" +# 99 becomes -1 +# 1999 shown as 2099 +# GPRMC hhmmss goes backwards! # From the Telit App note: # https://rutronik-tec.com/wp-content/uploads/2019/02/Telit_Cellular_WeekRollover_Application_Note_r0.pdf # diff --git a/test/daemon/april6_2019.log.chk b/test/daemon/april6_2019.log.chk index a0f5cadc..f529e996 100644 --- a/test/daemon/april6_2019.log.chk +++ b/test/daemon/april6_2019.log.chk @@ -2,4 +2,4 @@ $GPRMC,,V,,,,,,,,,,N*53 $GPRMC,000231.42,A,4829.0005,N,00022.0016,E,0.16,212.28,220899,,,A*59 {"class":"TPV","mode":2,"time":"2099-08-22T00:02:31.420Z","ept":0.005,"lat":48.483341667,"lon":0.366693333,"track":212.2800,"speed":0.082}
$GPRMC,000231.099,A,4829.0005,N,00022.0015,E,0.15,212.28,2208-1,,,A*73 -{"class":"TPV","mode":2,"time":"1971-08-22T00:02:31.099Z","ept":0.005,"lat":48.483341667,"lon":0.366691667,"track":212.2800,"speed":0.077}
+{"class":"TPV","mode":2,"time":"2099-08-22T00:02:31.420Z","ept":0.005,"lat":48.483341667,"lon":0.366691667,"track":212.2800,"speed":0.077}
|