Skip to content

Commit

Permalink
Merge pull request #461 from analogdevicesinc/rgetz-fix-remaining-snp…
Browse files Browse the repository at this point in the history
…rintf-issues

fix remaining snprintf issues
  • Loading branch information
rgetz authored Apr 27, 2020
2 parents 7033763 + 3f305ee commit a82bf21
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 16 deletions.
2 changes: 1 addition & 1 deletion dns_sd.c
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ int dnssd_discover_host(char *addr_str, size_t addr_len, uint16_t *port)

if (ddata) {
*port = ddata->port;
strncpy(addr_str, ddata->addr_str, addr_len);
iio_strlcpy(addr_str, ddata->addr_str, addr_len);
}

host_fail:
Expand Down
4 changes: 2 additions & 2 deletions dns_sd_bonjour.c
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,9 @@ static void __cfnet_browser_cb (
dd->port = port;
dd->hostname = strdup(hostname);
if (have_v4) {
strncpy(dd->addr_str, address_v4, sizeof(dd->addr_str));
iio_strlcpy(dd->addr_str, address_v4, sizeof(dd->addr_str));
} else if(have_v6) {
strncpy(dd->addr_str, address_v6, sizeof(dd->addr_str));
iio_strlcpy(dd->addr_str, address_v6, sizeof(dd->addr_str));
}

IIO_DEBUG("DNS SD: added %s (%s:%d)\n", hostname, dd->addr_str, port);
Expand Down
15 changes: 11 additions & 4 deletions iiod-client.c
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ int iiod_client_get_version(struct iiod_client *client, void *desc,
if (minor)
*minor = (unsigned int) min;
if (git_tag)
strncpy(git_tag, ptr, 8);
iio_strlcpy(git_tag, ptr, 8);
return 0;
}

Expand Down Expand Up @@ -534,17 +534,24 @@ int iiod_client_open_unlocked(struct iiod_client *client, void *desc,
{
char buf[1024], *ptr;
size_t i;
ssize_t len;

iio_snprintf(buf, sizeof(buf), "OPEN %s %lu ",
len = sizeof(buf);
len -= iio_snprintf(buf, len, "OPEN %s %lu ",
iio_device_get_id(dev), (unsigned long) samples_count);
ptr = buf + strlen(buf);

for (i = dev->words; i > 0; i--, ptr += 8) {
iio_snprintf(ptr, (ptr - buf) + i * 8, "%08" PRIx32,
len -= iio_snprintf(ptr, len, "%08" PRIx32,
dev->mask[i - 1]);
}

strcpy(ptr, cyclic ? " CYCLIC\r\n" : "\r\n");
len -= iio_strlcpy(ptr, cyclic ? " CYCLIC\r\n" : "\r\n", len);

if (len < 0) {
IIO_ERROR("strlength problem in iiod_client_open_unlocked\n");
return -ENOMEM;
}

return iiod_client_exec_command(client, desc, buf);
}
Expand Down
2 changes: 1 addition & 1 deletion iiod/ops.c
Original file line number Diff line number Diff line change
Expand Up @@ -1262,7 +1262,7 @@ ssize_t get_trigger(struct parser_pdata *pdata, struct iio_device *dev)
ret = strlen(trigger->name);
print_value(pdata, ret);

snprintf(buf, sizeof(buf), "%s\n", trigger->name);
iio_snprintf(buf, sizeof(buf), "%s\n", trigger->name);
ret = write_all(pdata, buf, ret + 1);
} else {
print_value(pdata, ret);
Expand Down
6 changes: 3 additions & 3 deletions iiod/usbd.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,14 @@ static int usb_open_pipe(struct usbd_pdata *pdata, unsigned int pipe_id)
* before opening the endpoints again. */
thread_pool_stop_and_wait(pdata->pool[pipe_id]);

snprintf(buf, sizeof(buf), "%s/ep%u", pdata->ffs, pipe_id * 2 + 1);
iio_snprintf(buf, sizeof(buf), "%s/ep%u", pdata->ffs, pipe_id * 2 + 1);
cpdata->ep_out = open(buf, O_WRONLY);
if (cpdata->ep_out < 0) {
err = -errno;
goto err_free_cpdata;
}

snprintf(buf, sizeof(buf), "%s/ep%u", pdata->ffs, pipe_id * 2 + 2);
iio_snprintf(buf, sizeof(buf), "%s/ep%u", pdata->ffs, pipe_id * 2 + 2);
cpdata->ep_in = open(buf, O_RDONLY);
if (cpdata->ep_in < 0) {
err = -errno;
Expand Down Expand Up @@ -361,7 +361,7 @@ int start_usb_daemon(struct iio_context *ctx, const char *ffs,
goto err_free_pdata_pool;
}

snprintf(buf, sizeof(buf), "%s/ep0", ffs);
iio_snprintf(buf, sizeof(buf), "%s/ep0", ffs);

pdata->ep0_fd = open(buf, O_RDWR);
if (pdata->ep0_fd < 0) {
Expand Down
3 changes: 1 addition & 2 deletions local.c
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,7 @@ static int set_channel_name(struct iio_channel *chn)
name = malloc(prefix_len);
if (!name)
return -ENOMEM;
strncpy(name, attr0, prefix_len - 1);
name[prefix_len - 1] = '\0';
iio_strlcpy(name, attr0, prefix_len - 1);
IIO_DEBUG("Setting name of channel %s to %s\n", chn->id, name);
chn->name = name;

Expand Down
2 changes: 1 addition & 1 deletion network.c
Original file line number Diff line number Diff line change
Expand Up @@ -1424,7 +1424,7 @@ struct iio_context * network_create_context(const char *host)
inet_ntop(AF_INET, &in->sin_addr, description, INET_ADDRSTRLEN);
#else
char *tmp = inet_ntoa(in->sin_addr);
strncpy(description, tmp, len);
iio_strlcpy(description, tmp, len);
#endif
}

Expand Down
3 changes: 1 addition & 2 deletions utilities.c
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,7 @@ void iio_library_get_version(unsigned int *major,
if (minor)
*minor = LIBIIO_VERSION_MINOR;
if (git_tag) {
strncpy(git_tag, LIBIIO_VERSION_GIT, 8);
git_tag[7] = '\0';
iio_strlcpy(git_tag, LIBIIO_VERSION_GIT, 8);
}
}

Expand Down

0 comments on commit a82bf21

Please sign in to comment.