From 87a3f0f7ca5ef706f0a8977c034205d5b79dad77 Mon Sep 17 00:00:00 2001 From: Jon Schlueter Date: Sat, 29 May 2010 22:33:24 -0400 Subject: patch to keep gpsmon from crashing on unchecked data from sirf MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit gpsmon crashes in binary sirf mode if it receives a DGPS status message (1b) with negative first byte. Although this value is not documented by the sirf docs, my gps sends it. patch from Ladislav Sládeček --- monitor_sirf.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'monitor_sirf.c') diff --git a/monitor_sirf.c b/monitor_sirf.c index 7a0430fc..af03e2b8 100644 --- a/monitor_sirf.c +++ b/monitor_sirf.c @@ -59,6 +59,8 @@ static char *dgpsvec[] = { "Software", }; +#define CHECK_RANGE(vec, i) (((i) >= 0) && ((i) < sizeof(vec)/sizeof(vec[0]))) + /***************************************************************************** * * SiRF packet-decoding routines @@ -300,6 +302,7 @@ static void sirf_update(void) int i, j, ch, off, cn; unsigned char *buf; size_t len; + uint8_t dgps; assert(mid27win != NULL); buf = session.packet.outbuffer + 4; @@ -526,8 +529,9 @@ static void sirf_update(void) total 3 x 12 = 36 bytes ******************************************************************/ + dgps = getub(buf, 1); display(mid27win, 1, 14, "%d (%s)", - getub(buf, 1), dgpsvec[(int)getub(buf, 1)]); + dgps, (CHECK_RANGE(dgpsvec, dgps) ? dgpsvec[dgps] : "???")); /*@ -type @*/ //(void) wmove(mid27win, 2, 0); for (i = j = 0; i < 12; i++) { -- cgit v1.2.1