diff options
-rw-r--r-- | driver_garmin_txt.c | 6 | ||||
-rw-r--r-- | driver_nmea.c | 12 | ||||
-rw-r--r-- | gpsdclient.c | 2 | ||||
-rw-r--r-- | json.c | 2 | ||||
-rw-r--r-- | libgps_sock.c | 4 | ||||
-rw-r--r-- | net_ntrip.c | 18 |
6 files changed, 27 insertions, 17 deletions
diff --git a/driver_garmin_txt.c b/driver_garmin_txt.c index 74b1ce57..c67a39b3 100644 --- a/driver_garmin_txt.c +++ b/driver_garmin_txt.c @@ -156,7 +156,7 @@ static int gar_decode(const char *data, const size_t length, const char *prefix, } bzero(buf, (int)sizeof(buf)); - (void)strncpy(buf, data, length); + (void)strlcpy(buf, data, length); gpsd_report(LOG_RAW + 2, "Decoded string: %s\n", buf); if (strchr(buf, '_') != NULL) { @@ -224,7 +224,7 @@ static int gar_int_decode(const char *data, const size_t length, } bzero(buf, (int)sizeof(buf)); - (void)strncpy(buf, data, length); + (void)strlcpy(buf, data, length); gpsd_report(LOG_RAW + 2, "Decoded string: %s\n", buf); if (strchr(buf, '_') != NULL) { @@ -277,7 +277,7 @@ gps_mask_t garmintxt_parse(struct gps_device_t * session) session->packet.type = GARMINTXT_PACKET; /* TAG message as GTXT, Garmin Simple Text Message */ - strncpy(session->gpsdata.tag, "GTXT", MAXTAGLEN); + (void)strlcpy(session->gpsdata.tag, "GTXT", MAXTAGLEN); /* only one message, set cycle start */ session->cycle_end_reliable = true; diff --git a/driver_nmea.c b/driver_nmea.c index 90746ce6..1ed293fc 100644 --- a/driver_nmea.c +++ b/driver_nmea.c @@ -26,7 +26,7 @@ static void do_lat_lon(char *field[], struct gps_fix_t *out) char str[20], *p; if (*(p = field[0]) != '\0') { - strncpy(str, p, 20); + (void)strlcpy(str, p, sizeof(str)); (void)sscanf(p, "%lf", &lat); m = 100.0 * modf(lat / 100.0, &d); lat = d + m / 60.0; @@ -36,7 +36,7 @@ static void do_lat_lon(char *field[], struct gps_fix_t *out) out->latitude = lat; } if (*(p = field[2]) != '\0') { - strncpy(str, p, 20); + (void)strlcpy(str, p, sizeof(str)); (void)sscanf(p, "%lf", &lon); m = 100.0 * modf(lon / 100.0, &d); lon = d + m / 60.0; @@ -342,7 +342,7 @@ static gps_mask_t processGPGGA(int c UNUSED, char *field[], session->gpsdata.status = STATUS_NO_FIX; session->newdata.mode = MODE_NO_FIX; } else - (void)strncpy(session->driver.nmea.last_gga_timestamp, + (void)strlcpy(session->driver.nmea.last_gga_timestamp, field[1], sizeof(session->driver.nmea.last_gga_timestamp)); /* if we have a fix and the mode latch is off, go... */ @@ -1055,7 +1055,7 @@ gps_mask_t nmea_parse(char *sentence, struct gps_device_t * session) /*@ -usedef @*//* splint 3.1.1 seems to have a bug here */ /* make an editable copy of the sentence */ - strncpy((char *)session->driver.nmea.fieldcopy, sentence, NMEA_MAX); + (void)strlcpy((char *)session->driver.nmea.fieldcopy, sentence, NMEA_MAX); /* discard the checksum part */ for (p = (char *)session->driver.nmea.fieldcopy; (*p != '*') && (*p >= ' ');) @@ -1104,7 +1104,9 @@ gps_mask_t nmea_parse(char *sentence, struct gps_device_t * session) (nmea_phrase[i].decoder) (count, session->driver.nmea.field, session); - strncpy(session->gpsdata.tag, nmea_phrase[i].name, MAXTAGLEN); + (void)strlcpy(session->gpsdata.tag, + nmea_phrase[i].name, + MAXTAGLEN); /* * Must force this to be nz, as we're going to rely on a zero * value to mean "no previous tag" later. diff --git a/gpsdclient.c b/gpsdclient.c index 22f2b0af..cd52835f 100644 --- a/gpsdclient.c +++ b/gpsdclient.c @@ -32,7 +32,7 @@ double fdsec, fsec, fdeg, fmin; if (f < 0 || f > 360) { - (void)strlcpy(str, "nan", 40); + (void)strlcpy(str, "nan", sizeof(str)); return str; } @@ -442,7 +442,7 @@ static int json_internal_read_object(const char *cp, && parent->element_type != t_structobject && offset > 0) return JSON_ERR_NOPARSTR; - (void)strncpy(lptr, valbuf, cursor->len); + (void)strlcpy(lptr, valbuf, cursor->len); break; case t_boolean: *((bool *) lptr) = (strcmp(valbuf, "true") == 0); diff --git a/libgps_sock.c b/libgps_sock.c index 4bf5121f..18a932d0 100644 --- a/libgps_sock.c +++ b/libgps_sock.c @@ -295,7 +295,7 @@ int gps_unpack(char *buf, struct gps_data_t *gpsdata) gpsdata->dev.path[0] = '\0'; else { /*@ -mayaliasunique @*/ - strncpy(gpsdata->dev.path, sp + 2, + (void)strlcpy(gpsdata->dev.path, sp + 2, sizeof(gpsdata->dev.path)); /*@ +mayaliasunique @*/ gpsdata->set |= DEVICE_SET; @@ -402,7 +402,7 @@ int gps_unpack(char *buf, struct gps_data_t *gpsdata) (void)sscanf(sp, "Y=%8s %20s %d ", tag, timestamp, &gpsdata->satellites_visible); - (void)strncpy(gpsdata->tag, tag, MAXTAGLEN); + (void)strlcpy(gpsdata->tag, tag, MAXTAGLEN); if (timestamp[0] != '?') { gpsdata->set |= TIME_SET; } diff --git a/net_ntrip.c b/net_ntrip.c index 53285caa..27b1de15 100644 --- a/net_ntrip.c +++ b/net_ntrip.c @@ -74,7 +74,7 @@ static void ntrip_str_parse(char *str, size_t len, /* <mountpoint> */ if ((s = ntrip_field_iterate(str, NULL, eol))) - strncpy(hold->mountpoint, s, sizeof(hold->mountpoint) - 1); + (void)strlcpy(hold->mountpoint, s, sizeof(hold->mountpoint)); /* <identifier> */ s = ntrip_field_iterate(NULL, s, eol); /* <format> */ @@ -485,10 +485,18 @@ int ntrip_open(struct gps_device_t *device, char *caster) port = DEFAULT_RTCM_PORT; } - strncpy(device->ntrip.stream.mountpoint, stream, 101); /* magic numbers from struct definitions */ - strncpy(device->ntrip.stream.credentials, auth, 128); /* magic numbers from struct definitions */ - strncpy(device->ntrip.stream.url, url, 256); - strncpy(device->ntrip.stream.port, port, 32); + (void)strlcpy(device->ntrip.stream.mountpoint, + stream, + sizeof(device->ntrip.stream.mountpoint)); + (void)strlcpy(device->ntrip.stream.credentials, + auth, + sizeof(device->ntrip.stream.credentials)); + (void)strlcpy(device->ntrip.stream.url, + url, + sizeof(device->ntrip.stream.url)); + (void)strlcpy(device->ntrip.stream.port, + port, + sizeof(device->ntrip.stream.port)); ret = ntrip_stream_req_probe(&device->ntrip.stream); if (ret == -1) { |