summaryrefslogtreecommitdiff
path: root/libgps.c
diff options
context:
space:
mode:
authorChris Kuethe <chris.kuethe@gmail.com>2006-08-18 01:10:21 +0000
committerChris Kuethe <chris.kuethe@gmail.com>2006-08-18 01:10:21 +0000
commiteb1b318593531b0ac6b22b5213f3a562e74a59ef (patch)
tree781099c8b56932903a7c4106cab3337ab4da503f /libgps.c
parentaa006f20d82767f203f64a22b5c6921a431f3c8b (diff)
downloadgpsd-eb1b318593531b0ac6b22b5213f3a562e74a59ef.tar.gz
avoid a segfault if strchr returns NULL.
Yay for compiling with -g, linking with -static and having full debug symbols in my libraries. (gdb) bt #0 0x0532aad6 in sscanf (str=0x1 "", fmt=0x2b39f316 "%d %d %d %d %d") at /usr/src/lib/libc/stdio/sscanf.c:58 #1 0x0b3acda9 in gps_unpack () from /usr/local/lib/libgps.so.16.0 #2 0x0b3acfa1 in gps_poll () from /usr/local/lib/libgps.so.16.0
Diffstat (limited to 'libgps.c')
-rw-r--r--libgps.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/libgps.c b/libgps.c
index bab6497e..e404b796 100644
--- a/libgps.c
+++ b/libgps.c
@@ -455,7 +455,9 @@ static void gps_unpack(char *buf, struct gps_data_t *gpsdata)
PRN[j]=elevation[j]=azimuth[j]=ss[j]=used[j]=0;
}
for (j = 0, gpsdata->satellites_used = 0; j < gpsdata->satellites; j++) {
- sp = strchr(sp, ':') + 1;
+ if ((sp = strchr(sp, ':')) == NULL);
+ break;
+ sp++;
(void)sscanf(sp, "%d %d %d %d %d", &i1, &i2, &i3, &i4, &i5);
PRN[j] = i1;
elevation[j] = i2; azimuth[j] = i3;