[prev in list] [next in list] [prev in thread] [next in thread] 

List:       gpsd-commit-watch
Subject:    [Gpsd-commit-watch] r3403 - trunk
From:       ckuethe () mail ! berlios ! de (ckuethe at BerliOS)
Date:       2006-08-19 5:31:05
Message-ID: 200608190531.k7J5V5Ho013315 () sheep ! berlios ! de
[Download RAW message or body]

Author: ckuethe
Date: 2006-08-19 07:30:49 +0200 (Sat, 19 Aug 2006)
New Revision: 3403

Modified:
   trunk/cgps.c
   trunk/gpsd.c
   trunk/gpsflash.c
   trunk/gpsutils.c
   trunk/libgps.c
   trunk/libgpsd_core.c
   trunk/nmea_parse.c
   trunk/rtcm.c
   trunk/rtcmdecode.c
   trunk/sirf.c
   trunk/sirfmon.c
   trunk/truenorth.c
   trunk/xgps.c
   trunk/xgpsspeed.c
   trunk/zodiac.c
Log:
String safety, courtesy of snprintf, strlcat and strlcpy. GPSD is now free
from the often-misused strcat, strcpy and sprintf. Future code should not use
unbounded string functions. Glibc users, please verify that the integrated
strlcat and strlcpy are correctly linked in.


Modified: trunk/cgps.c
===================================================================
--- trunk/cgps.c	2006-08-18 23:42:08 UTC (rev 3402)
+++ trunk/cgps.c	2006-08-19 05:30:49 UTC (rev 3403)
@@ -422,11 +422,13 @@
 
     /* If the user requested a specific device, try to change to it. */
     if (device) {
-	char *channelcmd = (char *)malloc(strlen(device)+3);
+	char *channelcmd;
+	size_t l;
+	l = strlen(device)+4;
 
-	if (channelcmd) {
-	    /*@i@*/(void)strcpy(channelcmd, "F=");
-	    (void)strcpy(channelcmd+2, device);
+	if ((channelcmd = (char *)malloc(l)) != NULL){
+	    /*@i@*/(void)strlcpy(channelcmd, "F=", l);
+	    (void)strlcpy(channelcmd+2, device, l);
 	    (void)gps_query(gpsdata, channelcmd);
 	    (void)free(channelcmd);
 	}

Modified: trunk/gpsd.c
===================================================================
--- trunk/gpsd.c	2006-08-18 23:42:08 UTC (rev 3402)
+++ trunk/gpsd.c	2006-08-19 05:30:49 UTC (rev 3403)
@@ -155,7 +155,7 @@
 	(void)pthread_mutex_lock(&report_mutex);
 	/* +unrecog */
 #endif /* PPS_ENABLE */
-	(void)strcpy(buf, "gpsd: ");
+	(void)strlcpy(buf, "gpsd: ", BUFSIZ);
 	va_start(ap, fmt) ;
 	(void)vsnprintf(buf + strlen(buf), sizeof(buf)-strlen(buf), fmt, ap);
 	va_end(ap);
@@ -279,7 +279,7 @@
 	gpsd_report(0, "Can't create device-control socket\n");
 	return -1;
     }
-    (void)strcpy(addr.sun_path, filename);
+    (void)strlcpy(addr.sun_path, filename, 104); /* from sys/un.h */
     /*@i1@*/addr.sun_family = AF_UNIX;
     (void)bind(sock, (struct sockaddr *) &addr,  (int)sizeof(addr));
     if (listen(sock, QLEN) < 0) {
@@ -614,7 +614,7 @@
     struct subscriber_t *whoami = subscribers + cfd;
     struct gps_device_t *newchan;
 
-    (void)strcpy(reply, "GPSD");
+    (void)strlcpy(reply, "GPSD", BUFSIZ);
     p = buf;
     while (*p != '\0' && p - buf < buflen) {
 	phrase[0] = '\0';
@@ -626,7 +626,7 @@
 		(void)snprintf(phrase, sizeof(phrase), ",A=%.3f", 
 			whoami->fixbuffer.altitude);
 	    else
-		(void)strcpy(phrase, ",A=?");
+		(void)strlcpy(phrase, ",A=?", BUFSIZ);
 	    break;
 #ifndef FIXED_PORT_SPEED
 	case 'B':		/* change baud rate (SiRF/Zodiac only) */
@@ -668,13 +668,13 @@
 			(int)whoami->device->gpsdata.parity,
 			whoami->device->gpsdata.stopbits);
 	    } else {
-		(void)strcpy(phrase, ",B=?");
+		(void)strlcpy(phrase, ",B=?", BUFSIZ);
 	    }
 	    break;
 #endif
 	case 'C':
 	    if (!assign_channel(whoami) || whoami->device->device_type==NULL)
-		(void)strcpy(phrase, ",C=?");
+		(void)strlcpy(phrase, ",C=?", BUFSIZ);
 	    else {
 		struct gps_type_t *dev = whoami->device->device_type;
 		double mincycle = (dev->cycle_chars * 10.0) / whoami->device->gpsdata.baudrate;
@@ -694,15 +694,15 @@
 	    }
 	    break;
 	case 'D':
-	    (void)strcpy(phrase, ",D=");
+	    (void)strlcpy(phrase, ",D=", BUFSIZ);
 	    if (assign_channel(whoami) && isnan(whoami->fixbuffer.time)==0)
 		(void)unix_to_iso8601(whoami->fixbuffer.time, 
 				phrase+3, (int)(sizeof(phrase)-3));
 	    else
-		(void)strcat(phrase, "?");
+		(void)strlcat(phrase, "?", BUFSIZ);
 	    break;
 	case 'E':
-	    (void)strcpy(phrase, ",E=?");
+	    (void)strlcpy(phrase, ",E=?", BUFSIZ);
 	    if (assign_channel(whoami) && have_fix(whoami->device))
 		(void)snprintf(phrase, sizeof(phrase), ",E=%.2f %.2f %.2f", 
 			       whoami->device->gpsdata.epe, 
@@ -724,7 +724,7 @@
 		(void)snprintf(phrase, sizeof(phrase), ",F=%s", 
 			 whoami->device->gpsdata.gps_device);
 	    else
-		(void)strcpy(phrase, ",F=?");
+		(void)strlcpy(phrase, ",F=?", BUFSIZ);
 	    break;
 	case 'G':
 	    if (*p == '=') {
@@ -739,7 +739,7 @@
 	    }
 	    (void)assign_channel(whoami);
 	    if (whoami->device==NULL||whoami->device->packet_type==BAD_PACKET)
-		(void)strcpy(phrase, ",G=?");
+		(void)strlcpy(phrase, ",G=?", BUFSIZ);
 	    else if (whoami->device->packet_type == RTCM_PACKET)
 		(void)snprintf(phrase, sizeof(phrase), ",G=RTCM104");
 	    else
@@ -750,7 +750,7 @@
 	    if (assign_channel(whoami) && have_fix(whoami->device) && \
isnan(whoami->fixbuffer.heading)==0)  (void)snprintf(phrase, sizeof(phrase), \
",H=%.4f", whoami->fixbuffer.heading);  else
-		(void)strcpy(phrase, ",H=?");
+		(void)strlcpy(phrase, ",H=?", BUFSIZ);
 	    break;
 #endif /* HEADING_FIX */
 	case 'I':
@@ -758,14 +758,14 @@
 		(void)snprintf(phrase, sizeof(phrase), ",I=%s", 
 			 whoami->device->device_type->typename);
 	    else
-		(void)strcpy(phrase, ",I=?");
+		(void)strlcpy(phrase, ",I=?", BUFSIZ);
 	    break;
 #ifndef WIRED_POLICY
 	case 'j':
 	    if (!assign_channel(whoami) || whoami->device->device_type == NULL)
-		(void)strcpy(phrase, ",J=?");
+		(void)strlcpy(phrase, ",J=?", BUFSIZ);
 	    else if (!whoami->device->device_type->mode_switcher)
-		(void)strcpy(phrase, ",J=0");
+		(void)strlcpy(phrase, ",J=0", BUFSIZ);
 	    else if (privileged_user(whoami)) {
 		if (*p == '=') ++p;
 		if (*p == '1' || *p == '+') {
@@ -789,8 +789,8 @@
 	    (void)snprintf(phrase, sizeof(phrase), ",K=%d ", j);
 	    for (i = 0; i < MAXDEVICES; i++) {
 		if (allocated_channel(&channels[i]) && \
                strlen(phrase)+strlen(channels[i].gpsdata.gps_device)+1 < \
                sizeof(phrase)) {
-		    (void)strcat(phrase, channels[i].gpsdata.gps_device);
-		    (void)strcat(phrase, " ");
+		    (void)strlcat(phrase, channels[i].gpsdata.gps_device, BUFSIZ);
+		    (void)strlcat(phrase, " ", BUFSIZ);
 		}
 	    }
 	    phrase[strlen(phrase)-1] = '\0';
@@ -800,15 +800,15 @@
 	    break;
 	case 'M':
 	    if (!assign_channel(whoami) && (!whoami->device || whoami->fixbuffer.mode == \
                MODE_NOT_SEEN))
-		(void)strcpy(phrase, ",M=?");
+		(void)strlcpy(phrase, ",M=?", BUFSIZ);
 	    else
 		(void)snprintf(phrase, sizeof(phrase), ",M=%d", whoami->fixbuffer.mode);
 	    break;
 	case 'N':
 	    if (!assign_channel(whoami) || whoami->device->device_type == NULL)
-		(void)strcpy(phrase, ",N=?");
+		(void)strlcpy(phrase, ",N=?", BUFSIZ);
 	    else if (!whoami->device->device_type->mode_switcher)
-		(void)strcpy(phrase, ",N=0");
+		(void)strlcpy(phrase, ",N=0", BUFSIZ);
 	    else if (privileged_user(whoami)) {
 		if (*p == '=') ++p;
 		if (*p == '1' || *p == '+') {
@@ -826,7 +826,7 @@
 	    break;
 	case 'O':
 	    if (!assign_channel(whoami) || !have_fix(whoami->device))
-		(void)strcpy(phrase, ",O=?");
+		(void)strlcpy(phrase, ",O=?", BUFSIZ);
 	    else {
 		(void)snprintf(phrase, sizeof(phrase), ",O=%s",
 			       whoami->device->gpsdata.tag[0]!='\0' ? whoami->device->gpsdata.tag : "-");
@@ -836,47 +836,47 @@
 				   " %.2f",
 				   whoami->fixbuffer.time);
 		else
-		    (void)strcat(phrase, "          ?");
+		    (void)strlcat(phrase, "          ?", BUFSIZ);
 		if (isnan(whoami->fixbuffer.ept)==0)
 		    (void)snprintf(phrase+strlen(phrase),
 				   sizeof(phrase)-strlen(phrase),
 				   " %.3f",
 				   whoami->fixbuffer.ept);
 		else
-		    (void)strcat(phrase, "          ?");
+		    (void)strlcat(phrase, "          ?", BUFSIZ);
 		if (isnan(whoami->fixbuffer.latitude)==0)
 		    (void)snprintf(phrase+strlen(phrase),
 				   sizeof(phrase)-strlen(phrase),
 				   " %.6f",
 				   whoami->fixbuffer.latitude);
 		else
-		    (void)strcat(phrase, "          ?");
+		    (void)strlcat(phrase, "          ?", BUFSIZ);
 		if (isnan(whoami->fixbuffer.longitude)==0)
 		    (void)snprintf(phrase+strlen(phrase),
 				   sizeof(phrase)-strlen(phrase),
 				   " %.6f",
 				   whoami->fixbuffer.longitude);
 		else
-		    (void)strcat(phrase, "          ?");
+		    (void)strlcat(phrase, "          ?", BUFSIZ);
 		if (isnan(whoami->fixbuffer.altitude)==0)
 		    (void)snprintf(phrase+strlen(phrase),
 				   sizeof(phrase)-strlen(phrase),
 				   " %7.2f",
 				   whoami->fixbuffer.altitude);
 		else
-		    (void)strcat(phrase, "          ?");
+		    (void)strlcat(phrase, "          ?", BUFSIZ);
 		if (isnan(whoami->fixbuffer.eph)==0)
 		    (void)snprintf(phrase+strlen(phrase), 
 				   sizeof(phrase)-strlen(phrase),
 				  " %5.2f",  whoami->fixbuffer.eph);
 		else
-		    (void)strcat(phrase, "        ?");
+		    (void)strlcat(phrase, "        ?", BUFSIZ);
 		if (isnan(whoami->fixbuffer.epv)==0)
 		    (void)snprintf(phrase+strlen(phrase), 
 				   sizeof(phrase)-strlen(phrase),
 				   " %5.2f",  whoami->fixbuffer.epv);
 		else
-		    (void)strcat(phrase, "        ?");
+		    (void)strlcat(phrase, "        ?", BUFSIZ);
 		if (isnan(whoami->fixbuffer.track)==0)
 		    (void)snprintf(phrase+strlen(phrase), 
 				   sizeof(phrase)-strlen(phrase),
@@ -884,39 +884,39 @@
 				   whoami->fixbuffer.track, 
 				   whoami->fixbuffer.speed);
 		else
-		    (void)strcat(phrase, "             ?            ?");
+		    (void)strlcat(phrase, "             ?            ?", BUFSIZ);
 		if (isnan(whoami->fixbuffer.climb)==0)
 		    (void)snprintf(phrase+strlen(phrase),
 				   sizeof(phrase)-strlen(phrase),
 				   " %6.3f", 
 				   whoami->fixbuffer.climb);
 		else
-		    (void)strcat(phrase, "          ?");
+		    (void)strlcat(phrase, "          ?", BUFSIZ);
 		if (isnan(whoami->fixbuffer.epd)==0)
 		    (void)snprintf(phrase+strlen(phrase), 
 				   sizeof(phrase)-strlen(phrase),
 				   " %8.4f",
 				   whoami->fixbuffer.epd);
 		else
-		    (void)strcat(phrase, "             ?");
+		    (void)strlcat(phrase, "             ?", BUFSIZ);
 		if (isnan(whoami->fixbuffer.eps)==0)
 		    (void)snprintf(phrase+strlen(phrase),
 			     sizeof(phrase)-strlen(phrase),
 			     " %5.2f", whoami->fixbuffer.eps);		    
 		else
-		    (void)strcat(phrase, "        ?");
+		    (void)strlcat(phrase, "        ?", BUFSIZ);
 		if (isnan(whoami->fixbuffer.epc)==0)
 		    (void)snprintf(phrase+strlen(phrase),
 			     sizeof(phrase)-strlen(phrase),
 			     " %5.2f", whoami->fixbuffer.epc);		    
 		else
-		    (void)strcat(phrase, "        ?");
+		    (void)strlcat(phrase, "        ?", BUFSIZ);
 		if (whoami->fixbuffer.mode > 0)
 		    (void)snprintf(phrase+strlen(phrase),
 			     sizeof(phrase)-strlen(phrase),
 			     " %d", whoami->fixbuffer.mode);		    
 		else
-		    (void)strcat(phrase, "        ?");
+		    (void)strlcat(phrase, "        ?", BUFSIZ);
 	    }
 	    break;
 	case 'P':
@@ -925,7 +925,7 @@
 			whoami->fixbuffer.latitude, 
 			whoami->fixbuffer.longitude);
 	    else
-		(void)strcpy(phrase, ",P=?");
+		(void)strlcpy(phrase, ",P=?", BUFSIZ);
 	    break;
 	case 'Q':
 #define ZEROIZE(x)	(isnan(x)!=0 ? 0.0 : x)  
@@ -941,7 +941,7 @@
 			ZEROIZE(whoami->device->gpsdata.tdop),
 			ZEROIZE(whoami->device->gpsdata.gdop));
 	    else
-		(void)strcpy(phrase, ",Q=?");
+		(void)strlcpy(phrase, ",Q=?", BUFSIZ);
 #undef ZEROIZE
 	    break;
 	case 'R':
@@ -978,25 +978,25 @@
 	    if (assign_channel(whoami))
 		(void)snprintf(phrase, sizeof(phrase), ",S=%d", whoami->device->gpsdata.status);
 	    else
-		(void)strcpy(phrase, ",S=?");
+		(void)strlcpy(phrase, ",S=?", BUFSIZ);
 	    break;
 	case 'T':
 	    if (assign_channel(whoami) && have_fix(whoami->device) && \
isnan(whoami->fixbuffer.track)==0)  (void)snprintf(phrase, sizeof(phrase), ",T=%.4f", \
whoami->fixbuffer.track);  else
-		(void)strcpy(phrase, ",T=?");
+		(void)strlcpy(phrase, ",T=?", BUFSIZ);
 	    break;
 	case 'U':
 	    if (assign_channel(whoami) && have_fix(whoami->device) && \
whoami->fixbuffer.mode == MODE_3D)  (void)snprintf(phrase, sizeof(phrase), ",U=%.3f", \
whoami->fixbuffer.climb);  else
-		(void)strcpy(phrase, ",U=?");
+		(void)strlcpy(phrase, ",U=?", BUFSIZ);
 	    break;
 	case 'V':
 	    if (assign_channel(whoami) && have_fix(whoami->device) && \
isnan(whoami->fixbuffer.speed)==0)  (void)snprintf(phrase, sizeof(phrase), ",V=%.3f", \
whoami->fixbuffer.speed * MPS_TO_KNOTS);  else
-		(void)strcpy(phrase, ",V=?");
+		(void)strlcpy(phrase, ",V=?", BUFSIZ);
 	    break;
 	case 'W':
 	    if (*p == '=') ++p;
@@ -1023,23 +1023,23 @@
 	    if (assign_channel(whoami) && whoami->device != NULL)
 		(void)snprintf(phrase, sizeof(phrase), ",X=%f", whoami->device->gpsdata.online);
 	    else
-		(void)strcpy(phrase, ",X=?");
+		(void)strlcpy(phrase, ",X=?", BUFSIZ);
 	    break;
 	case 'Y':
 	    if (assign_channel(whoami) && whoami->device->gpsdata.satellites > 0) {
 		int used, reported = 0;
-		(void)strcpy(phrase, ",Y=");
+		(void)strlcpy(phrase, ",Y=", BUFSIZ);
 		if (whoami->device->gpsdata.tag[0] != '\0')
-		    (void)strcat(phrase, whoami->device->gpsdata.tag);
+		    (void)strlcat(phrase, whoami->device->gpsdata.tag, BUFSIZ);
 		else
-		    (void)strcat(phrase, "-");
+		    (void)strlcat(phrase, "-", BUFSIZ);
 		if (isnan(whoami->device->gpsdata.sentence_time)==0)
 		    (void)snprintf(phrase+strlen(phrase), 
 				   sizeof(phrase)-strlen(phrase),
 				   " %f ",
 				   whoami->device->gpsdata.sentence_time);
 		else
-		    (void)strcat(phrase, " ? ");
+		    (void)strlcat(phrase, " ? ", BUFSIZ);
 		(void)snprintf(phrase+strlen(phrase), 
 			       sizeof(phrase)-strlen(phrase),
 			       "%d:", whoami->device->gpsdata.satellites);
@@ -1065,7 +1065,7 @@
 		    gpsd_report(1,"Satellite count %d != PRN count %d\n",
 				whoami->device->gpsdata.satellites, reported);
 	    } else
-		(void)strcpy(phrase, ",Y=?");
+		(void)strlcpy(phrase, ",Y=?", BUFSIZ);
 	    break;
 	case 'Z':
 	    (void)assign_channel(whoami); 
@@ -1092,7 +1092,7 @@
 	    break;
         case '$':
 	    if (!assign_channel(whoami))
-		(void)strcpy(phrase, ",$=?");
+		(void)strlcpy(phrase, ",$=?", BUFSIZ);
 	    else if (whoami->device->gpsdata.sentence_time!=0)
 		(void)snprintf(phrase, sizeof(phrase), ",$=%s %d %lf %lf %lf %lf %lf %lf",
 			whoami->device->gpsdata.tag,
@@ -1117,12 +1117,12 @@
 	    goto breakout;
 	}
 	if (strlen(reply) + strlen(phrase) < sizeof(reply) - 1)
-	    (void)strcat(reply, phrase);
+	    (void)strlcat(reply, phrase, BUFSIZ);
 	else
 	    return -1;	/* Buffer would overflow.  Just return an error */
     }
  breakout:
-    (void)strcat(reply, "\r\n");
+    (void)strlcat(reply, "\r\n", BUFSIZ);
 
     return (int)throttled_write(cfd, reply, (ssize_t)strlen(reply));
 }
@@ -1434,7 +1434,7 @@
 		    (void)snprintf(dbuf + strlen(dbuf), 
 				   sizeof(dbuf)-strlen(dbuf),
 				   " %d", cfd);
-	    strcat(dbuf, "} -> {");
+	    strlcat(dbuf, "} -> {", BUFSIZ);
 	    for (cfd = 0; cfd < FD_SETSIZE; cfd++)
 		if (FD_ISSET(cfd, &rfds))
 		    (void)snprintf(dbuf + strlen(dbuf), 
@@ -1607,11 +1607,11 @@
 		    channel->poll_times[cfd] = timestamp();
 		    if (changed &~ ONLINE_SET) {
 			if (changed & (LATLON_SET | MODE_SET))
-			    (void)strcat(cmds, "o");
+			    (void)strlcat(cmds, "o", 4);
 			if (changed & SATELLITE_SET)
-			    (void)strcat(cmds, "y");
+			    (void)strlcat(cmds, "y", 4);
 			if (channel->gpsdata.profiling!=0)
-			    (void)strcat(cmds, "$");
+			    (void)strlcat(cmds, "$", 4);
 		    }
 		    if (cmds[0] != '\0')
 			(void)handle_gpsd_request(cfd, cmds, (int)strlen(cmds));

Modified: trunk/gpsflash.c
===================================================================
--- trunk/gpsflash.c	2006-08-18 23:42:08 UTC (rev 3402)
+++ trunk/gpsflash.c	2006-08-19 05:30:49 UTC (rev 3403)
@@ -20,8 +20,8 @@
 	char buf[BUFSIZ];
 	va_list ap;
 
-	strcpy(buf, progname);
-	strcat(buf, ": ");
+	strlcpy(buf, progname, BUFSIZ);
+	strlcat(buf, ": ", BUFSIZ);
 	va_start(ap, fmt) ;
 	(void)vsnprintf(buf + strlen(buf), sizeof(buf)-strlen(buf), fmt, ap);
 	va_end(ap);

Modified: trunk/gpsutils.c
===================================================================
--- trunk/gpsutils.c	2006-08-18 23:42:08 UTC (rev 3402)
+++ trunk/gpsutils.c	2006-08-19 05:30:49 UTC (rev 3403)
@@ -132,7 +132,7 @@
     /*@ -aliasunique @*/
     (void)memcpy(isotime+slen, isotime+slen+1, strlen(isotime+slen+1));
     /*@ -aliasunique @*/
-    (void)strcat(isotime, "Z");
+    (void)strlcat(isotime, "Z", 28);
     return isotime;
 }
 

Modified: trunk/libgps.c
===================================================================
--- trunk/libgps.c	2006-08-18 23:42:08 UTC (rev 3402)
+++ trunk/libgps.c	2006-08-19 05:30:49 UTC (rev 3403)
@@ -32,7 +32,7 @@
     double fdsec, fsec, fdeg, fmin;
 
     if ( f < 0 || f > 360 ) {
-	strcpy( str, "nan");
+	strlcpy( str, "nan", 40);
 	return str;
     }
 
@@ -358,7 +358,7 @@
 			    nf.pitch = nf.roll = nf.dip = nf.heading = NAN;
 #endif /* HEADING_FIX */
 			    gpsdata->fix = nf;
-			    (void)strcpy(gpsdata->tag, tag);
+			    (void)strlcpy(gpsdata->tag, tag, MAXTAGLEN+1);
 			    gpsdata->set |= TIME_SET|TIMERR_SET|LATLON_SET|MODE_SET;
 			    gpsdata->status = STATUS_FIX;
 			    gpsdata->set |= STATUS_SET;
@@ -770,8 +770,8 @@
     collect = gps_open(NULL, 0);
     gps_set_raw_hook(collect, dumpline);
     if (optind < argc) {
-	strcpy(buf, argv[optind]);
-	strcat(buf,"\n");
+	strlcpy(buf, argv[optind], BUFSIZ);
+	strlcat(buf,"\n", BUFSIZ);
 	gps_query(collect, buf);
 	data_dump(collect, time(NULL));
     } else {

Modified: trunk/libgpsd_core.c
===================================================================
--- trunk/libgpsd_core.c	2006-08-18 23:42:08 UTC (rev 3402)
+++ trunk/libgpsd_core.c	2006-08-19 05:30:49 UTC (rev 3403)
@@ -235,27 +235,27 @@
 		session->gpsdata.fix.mode,
 		session->gpsdata.satellites_used);
 	if (isnan(session->gpsdata.hdop))
-	    (void)strcat(bufp, ",");
+	    (void)strlcat(bufp, ",", len);
 	else
 	    (void)snprintf(bufp+strlen(bufp), len-strlen(bufp),
 			   "%.2f,",session->gpsdata.hdop);
 	if (isnan(session->gpsdata.fix.altitude))
-	    (void)strcat(bufp, ",");
+	    (void)strlcat(bufp, ",", len);
 	else
 	    (void)snprintf(bufp+strlen(bufp), len-strlen(bufp), 
 			   "%.1f,M,", session->gpsdata.fix.altitude);
 	if (isnan(session->gpsdata.separation))
-	    (void)strcat(bufp, ",");
+	    (void)strlcat(bufp, ",", len);
 	else
 	    (void)snprintf(bufp+strlen(bufp), len-strlen(bufp), 
 			   "%.3f,M,", session->gpsdata.separation);
 	if (isnan(session->mag_var)) 
-	    (void)strcat(bufp, ",");
+	    (void)strlcat(bufp, ",", len);
 	else {
 	    (void)snprintf(bufp+strlen(bufp),
 			   len-strlen(bufp),
 			   "%3.2f,", fabs(session->mag_var));
-	    (void)strcat(bufp, (session->mag_var > 0) ? "E": "W");
+	    (void)strlcat(bufp, (session->mag_var > 0) ? "E": "W", len);
 	}
 	nmea_add_checksum(bufp);
     }
@@ -332,7 +332,7 @@
     if (session->packet_type == ZODIAC_PACKET && session->driver.zodiac.Zs[0] != 0) \
{  bufp += strlen(bufp);
 	bufp2 = bufp;
-	strcpy(bufp, "$PRWIZCH");
+	(void)strlcpy(bufp, "$PRWIZCH", len);
 	for (i = 0; i < ZODIAC_CHANNELS; i++) {
 	    len -= snprintf(bufp+strlen(bufp), len,
 			  ",%02u,%X", 
@@ -363,12 +363,12 @@
     }
     for (i = j; i < session->device_type->channels; i++) {
 	bufp += strlen(bufp);
-	(void)strcpy(bufp, ",");
+	(void)strlcpy(bufp, ",", len);
     }
     bufp += strlen(bufp);
 #define ZEROIZE(x)	(isnan(x)!=0 ? 0.0 : x)  
     if (session->gpsdata.fix.mode == MODE_NO_FIX)
-	(void)strcat(bufp, ",,,");
+	(void)strlcat(bufp, ",,,", len);
     else
 	(void)snprintf(bufp, len-strlen(bufp),
 		       "%.1f,%.1f,%.1f*", 

Modified: trunk/nmea_parse.c
===================================================================
--- trunk/nmea_parse.c	2006-08-18 23:42:08 UTC (rev 3402)
+++ trunk/nmea_parse.c	2006-08-19 05:30:49 UTC (rev 3403)
@@ -684,10 +684,10 @@
     (void)vsnprintf(buf, sizeof(buf)-5, fmt, ap);
     va_end(ap);
     if (fmt[0] == '$') {
-	strcat(buf, "*");
+	strlcat(buf, "*", BUFSIZ);
 	nmea_add_checksum(buf);
     } else
-	strcat(buf, "\r\n");
+	strlcat(buf, "\r\n", BUFSIZ);
     status = (int)write(fd, buf, strlen(buf));
     if (status == (int)strlen(buf)) {
 	gpsd_report(2, "=> GPS: %s\n", buf);

Modified: trunk/rtcm.c
===================================================================
--- trunk/rtcm.c	2006-08-18 23:42:08 UTC (rev 3402)
+++ trunk/rtcm.c	2006-08-19 05:30:49 UTC (rev 3403)
@@ -953,7 +953,7 @@
 	break;
 
     case 6: 			/* NOP msg */
-	strcat(buf, "N\n");
+	strlcat(buf, "N\n", buflen);
 	break;
 
     case 7:

Modified: trunk/rtcmdecode.c
===================================================================
--- trunk/rtcmdecode.c	2006-08-18 23:42:08 UTC (rev 3402)
+++ trunk/rtcmdecode.c	2006-08-19 05:30:49 UTC (rev 3403)
@@ -18,7 +18,7 @@
 	char buf[BUFSIZ];
 	va_list ap;
 
-	strcpy(buf, "rtcmdecode: ");
+	strlcpy(buf, "rtcmdecode: ", BUFSIZ);
 	va_start(ap, fmt) ;
 	(void)vsnprintf(buf + strlen(buf), sizeof(buf)-strlen(buf), fmt, ap);
 	va_end(ap);

Modified: trunk/sirf.c
===================================================================
--- trunk/sirf.c	2006-08-18 23:42:08 UTC (rev 3402)
+++ trunk/sirf.c	2006-08-19 05:30:49 UTC (rev 3403)
@@ -491,7 +491,7 @@
 	    /* HDOP should be available at byte 89, but in 231 it's zero. */
 	    mask |= SPEED_SET | TRACK_SET | CLIMB_SET | CYCLE_START_SET; 
 	    session->gpsdata.sentence_length = 91;
-	    strcpy(session->gpsdata.tag, "GND");
+	    strlcpy(session->gpsdata.tag, "GND",MAXTAGLEN+1);
 	}
 	return mask;
 

Modified: trunk/sirfmon.c
===================================================================
--- trunk/sirfmon.c	2006-08-18 23:42:08 UTC (rev 3402)
+++ trunk/sirfmon.c	2006-08-19 05:30:49 UTC (rev 3403)
@@ -144,7 +144,7 @@
     va_start(ap, fmt) ;
     (void)vsnprintf(buf, sizeof(buf)-5, fmt, ap);
     va_end(ap);
-    strcat(buf, "*");
+    strlcat(buf, "*", BUFLEN);
     nmea_add_checksum(buf);
     (void)fputs(buf, stderr);		/* so user can watch the baud hunt */
     status = (size_t)write(fd, buf, strlen(buf));

Modified: trunk/truenorth.c
===================================================================
--- trunk/truenorth.c	2006-08-18 23:42:08 UTC (rev 3402)
+++ trunk/truenorth.c	2006-08-19 05:30:49 UTC (rev 3403)
@@ -47,7 +47,7 @@
 	p++;
     }
     *p++ = '*';
-    /*@i@*/sprintf(p, "%02X\r\n", sum);
+    /*@i@*/snprintf(p, 4, "%02X\r\n", sum);
 }
 
 static int tnt_send(int fd, const char *fmt, ... )
@@ -59,7 +59,7 @@
     va_start(ap, fmt) ;
     (void)vsnprintf(buf, sizeof(buf)-5, fmt, ap);
     va_end(ap);
-    strcat(buf, "*");
+    strlcat(buf, "*", BUFSIZ);
     tnt_add_checksum(buf);
     status = (int)write(fd, buf, strlen(buf));
     if (status == (int)strlen(buf)) {

Modified: trunk/xgps.c
===================================================================
--- trunk/xgps.c	2006-08-18 23:42:08 UTC (rev 3402)
+++ trunk/xgps.c	2006-08-19 05:30:49 UTC (rev 3403)
@@ -292,7 +292,7 @@
 			       gpsdata->elevation[i], gpsdata->azimuth[i], 
 			       gpsdata->ss[i],	gpsdata->used[i] ? 'Y' : 'N');
 	    } else
-		(void)strcpy(s, "                  ");
+		(void)strlcpy(s, "                  ", 128);
 	    string[i+1] = XmStringCreateSimple(s);
 	}
 	XmListReplaceItemsPos(satellite_list, string, (int)sizeof(string), 1);
@@ -304,57 +304,57 @@
 	    (void)unix_to_iso8601(gpsdata->fix.time, s, (int)sizeof(s));
 	    newtxt = 1;
 	} else {
-	    newtxt = (lfok>0) ? 0 : ((void)strcpy(s, "n/a"), 1);
+	    newtxt = (lfok>0) ? 0 : ((void)strlcpy(s, "n/a", 128), 1);
 	}
 	if (newtxt != 0) XmTextFieldSetString(text_1, s);
 	if (gpsdata->fix.mode >= MODE_2D) {
 	    latlon = deg_to_str(deg_type,  fabs(gpsdata->fix.latitude));
 	    newtxt = snprintf(s, sizeof(s), "%s %c", latlon, (gpsdata->fix.latitude < 0) ? \
'S' : 'N');  } else {
-	    newtxt = (lfok>0) ? 0 : ((void)strcpy(s, "n/a"), 1);
+	    newtxt = (lfok>0) ? 0 : ((void)strlcpy(s, "n/a", 128), 1);
 	}
 	if (newtxt != 0) XmTextFieldSetString(text_2, s);
 	if (gpsdata->fix.mode >= MODE_2D) {
 	    latlon = deg_to_str(deg_type,  fabs(gpsdata->fix.longitude));
 	    newtxt = snprintf(s, sizeof(s), "%s %c", latlon, (gpsdata->fix.longitude < 0) ? \
'W' : 'E');  } else {
-	    newtxt = (lfok>0) ? 0 : ((void)strcpy(s, "n/a"), 1);
+	    newtxt = (lfok>0) ? 0 : ((void)strlcpy(s, "n/a", 128), 1);
 	}
 	if (newtxt != 0) XmTextFieldSetString(text_3, s);
 	if (gpsdata->fix.mode == MODE_3D) {
 	    newtxt = snprintf(s, sizeof(s), "%f %s",gpsdata->fix.altitude*altunits->factor, \
altunits->legend);  } else {
-	    newtxt = (lfok>0) ? 0 : ((void)strcpy(s, "n/a"), 1);
+	    newtxt = (lfok>0) ? 0 : ((void)strlcpy(s, "n/a", 128), 1);
 	}
 	if (newtxt != 0) XmTextFieldSetString(text_4, s);
 	if (gpsdata->fix.mode >= MODE_2D && isnan(gpsdata->fix.track)==0) {
 	    newtxt = snprintf(s, sizeof(s), "%f %s", gpsdata->fix.speed*speedunits->factor, \
speedunits->legend);  } else {
-	    newtxt = (lfok>0) ? 0 : ((void)strcpy(s, "n/a"), 1);
+	    newtxt = (lfok>0) ? 0 : ((void)strlcpy(s, "n/a", 128), 1);
 	}
 	if (newtxt != 0) XmTextFieldSetString(text_5, s);
 	if (gpsdata->fix.mode >= MODE_2D && isnan(gpsdata->fix.track)==0) {
 	    newtxt = snprintf(s, sizeof(s), "%f degrees", gpsdata->fix.track);
 	} else {
-	    newtxt = (lfok>0) ? 0 : ((void)strcpy(s, "n/a"), 1);
+	    newtxt = (lfok>0) ? 0 : ((void)strlcpy(s, "n/a",128), 1);
 	}
 	if (newtxt != 0) XmTextFieldSetString(text_6, s);
 	if (isnan(gpsdata->fix.eph)==0) {
 	    newtxt = snprintf(s, sizeof(s), "%f %s", gpsdata->fix.eph * altunits->factor, \
altunits->legend);  } else {
-	    newtxt = (lfok>0) ? 0 : ((void)strcpy(s, "n/a"), 1);
+	    newtxt = (lfok>0) ? 0 : ((void)strlcpy(s, "n/a", 128), 1);
 	}
 	if (newtxt != 0) XmTextFieldSetString(text_7, s);
 	if (isnan(gpsdata->fix.epv)==0) {
 	    newtxt = snprintf(s, sizeof(s), "%f %s", gpsdata->fix.epv * altunits->factor, \
altunits->legend);  } else {
-	    newtxt = (lfok>0) ? 0 : ((void)strcpy(s, "n/a"), 1);
+	    newtxt = (lfok>0) ? 0 : ((void)strlcpy(s, "n/a", 128), 1);
 	}
 	if (newtxt != 0) XmTextFieldSetString(text_8, s);
 	if (gpsdata->fix.mode == MODE_3D && isnan(gpsdata->fix.climb)==0) {
 	    newtxt = snprintf(s, sizeof(s), "%f %s/sec", gpsdata->fix.climb * \
altunits->factor, altunits->legend);  } else {
-	    newtxt = (lfok>0) ? 0 : ((void)strcpy(s, "n/a"), 1);
+	    newtxt = (lfok>0) ? 0 : ((void)strlcpy(s, "n/a", 128), 1);
 	}
 	if (newtxt != 0) XmTextFieldSetString(text_9, s);
 
@@ -522,16 +522,18 @@
     gps_set_raw_hook(gpsdata, update_panel);
 
     if (device) {
-	char *channelcmd = (char *)malloc(strlen(device)+3);
+	char *channelcmd;
+	size_t l;
+	l = strlen(device)+4;
 
-	if (channelcmd) {
-	    /*@i1@*/(void)strcpy(channelcmd, "F=");
-	    (void)strcpy(channelcmd+2, device);
+	if ((channelcmd = (char *)malloc(l)) != NULL){
+	    /*@i1@*/(void)strlcpy(channelcmd, "F=", l);
+	    (void)strlcpy(channelcmd+2, device, l);
 	    (void)gps_query(gpsdata, channelcmd);
 	    (void)free(channelcmd);
 	}
     }
-	
+
     (void)gps_query(gpsdata, "w+x\n");
 
     (void)XtAppAddInput(app, gpsdata->gps_fd, 

Modified: trunk/xgpsspeed.c
===================================================================
--- trunk/xgpsspeed.c	2006-08-18 23:42:08 UTC (rev 3402)
+++ trunk/xgpsspeed.c	2006-08-19 05:30:49 UTC (rev 3403)
@@ -174,16 +174,18 @@
     gps_set_raw_hook(gpsdata, update_display);
 
     if (device) {
-	char *channelcmd = (char *)malloc(strlen(device)+3);
+	char *channelcmd;
+	size_t l;
+	l = strlen(device)+4;
 
-	if (channelcmd) {
-	    /*@i1@*/(void)strcpy(channelcmd, "F=");
-	    (void)strcpy(channelcmd+2, device);
+	if ((channelcmd = (char *)malloc(l)) != NULL){
+	    /*@i1@*/(void)strlcpy(channelcmd, "F=", l);
+	    (void)strlcpy(channelcmd+2, device, l);
 	    (void)gps_query(gpsdata, channelcmd);
 	    (void)free(channelcmd);
 	}
     }
-	
+
     (void)gps_query(gpsdata, "w+x\n");
 
     (void)XtAppMainLoop(app);

Modified: trunk/zodiac.c
===================================================================
--- trunk/zodiac.c	2006-08-18 23:42:08 UTC (rev 3402)
+++ trunk/zodiac.c	2006-08-19 05:30:49 UTC (rev 3403)
@@ -372,7 +372,7 @@
     for (i = 0; i < (int)session->outbuflen; i++)
 	(void)snprintf(buf+strlen(buf), sizeof(buf)-strlen(buf),
 		       "%02x", (unsigned int)session->outbuffer[i]);
-    (void)strcat(buf, "\n");
+    (void)strlcat(buf, "\n", BUFSIZ);
     gpsd_report(5, "Raw Zodiac packet type %d length %d: \
%s\n",id,session->outbuflen,buf);  
     if (session->outbuflen < 10)


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic