From: robertl Date: Mon, 21 Feb 2011 16:55:33 +0000 (+0000) Subject: Improve handling of bogus NMEA. X-Git-Tag: archive/raspbian/1.10.0+ds-2+rpi1~1^2~12^2~11^2~902 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=1140b7ad2b5bb98a638c487ce8bc61550fd56da8;p=gpsbabel.git Improve handling of bogus NMEA. --- diff --git a/gpsbabel/nmea.c b/gpsbabel/nmea.c index df3da62bd..a3bac09b5 100644 --- a/gpsbabel/nmea.c +++ b/gpsbabel/nmea.c @@ -532,8 +532,12 @@ gprmc_parse(char *ibuf) } /* Skip past nine commas in ibuf to reach the dmy value */ - for (dmybuf=ibuf,i=0; i<9 && dmybuf != NULL; i++) { + for (dmybuf=ibuf,i=0; i<9; i++) { dmybuf= strchr(dmybuf, ','); + if(dmybuf==NULL) { + /* If we run out of commas, the sentence is invalid. */ + return; + } dmybuf++; } @@ -910,6 +914,12 @@ nmea_parse_one_line(char *ibuf) had_checksum = 0; return; } + + if(strstr(tbuf+1,"$")!=NULL) + { + /* If line has more than one $, there is probably an error in it. */ + return; + } /* @@@ zmarties: The parse routines all assume all fields are present, but the NMEA format allows any field to be missed out if there is no data