Miroslav Lichvar
2014-09-17 09:11:15 UTC
Don't overwrite the last NUL with strncpy() and also replace strcpy()
with strncpy().
Signed-off-by: Miroslav Lichvar <***@redhat.com>
---
hwstamp_ctl.c | 2 +-
sk.c | 6 +++---
2 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/hwstamp_ctl.c b/hwstamp_ctl.c
index ec5dd6d..0d21843 100644
--- a/hwstamp_ctl.c
+++ b/hwstamp_ctl.c
@@ -131,7 +131,7 @@ int main(int argc, char *argv[])
memset(&ifreq, 0, sizeof(ifreq));
memset(&cfg, 0, sizeof(cfg));
- strncpy(ifreq.ifr_name, device, sizeof(ifreq.ifr_name));
+ strncpy(ifreq.ifr_name, device, sizeof(ifreq.ifr_name) - 1);
ifreq.ifr_data = (void *) &cfg;
diff --git a/sk.c b/sk.c
index f694bbd..a9133fd 100644
--- a/sk.c
+++ b/sk.c
@@ -51,7 +51,7 @@ static int hwts_init(int fd, const char *device, int rx_filter, int one_step)
memset(&ifreq, 0, sizeof(ifreq));
memset(&cfg, 0, sizeof(cfg));
- strncpy(ifreq.ifr_name, device, sizeof(ifreq.ifr_name));
+ strncpy(ifreq.ifr_name, device, sizeof(ifreq.ifr_name) - 1);
ifreq.ifr_data = (void *) &cfg;
cfg.tx_type = one_step ? HWTSTAMP_TX_ONESTEP_SYNC : HWTSTAMP_TX_ON;
@@ -85,7 +85,7 @@ int sk_interface_index(int fd, const char *name)
int err;
memset(&ifreq, 0, sizeof(ifreq));
- strcpy(ifreq.ifr_name, name);
+ strncpy(ifreq.ifr_name, name, sizeof(ifreq.ifr_name) - 1);
err = ioctl(fd, SIOCGIFINDEX, &ifreq);
if (err < 0) {
pr_err("ioctl SIOCGIFINDEX failed: %m");
@@ -154,7 +154,7 @@ int sk_interface_macaddr(const char *name, struct address *mac)
int err, fd;
memset(&ifreq, 0, sizeof(ifreq));
- strcpy(ifreq.ifr_name, name);
+ strncpy(ifreq.ifr_name, name, sizeof(ifreq.ifr_name) - 1);
fd = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP);
if (fd < 0) {
with strncpy().
Signed-off-by: Miroslav Lichvar <***@redhat.com>
---
hwstamp_ctl.c | 2 +-
sk.c | 6 +++---
2 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/hwstamp_ctl.c b/hwstamp_ctl.c
index ec5dd6d..0d21843 100644
--- a/hwstamp_ctl.c
+++ b/hwstamp_ctl.c
@@ -131,7 +131,7 @@ int main(int argc, char *argv[])
memset(&ifreq, 0, sizeof(ifreq));
memset(&cfg, 0, sizeof(cfg));
- strncpy(ifreq.ifr_name, device, sizeof(ifreq.ifr_name));
+ strncpy(ifreq.ifr_name, device, sizeof(ifreq.ifr_name) - 1);
ifreq.ifr_data = (void *) &cfg;
diff --git a/sk.c b/sk.c
index f694bbd..a9133fd 100644
--- a/sk.c
+++ b/sk.c
@@ -51,7 +51,7 @@ static int hwts_init(int fd, const char *device, int rx_filter, int one_step)
memset(&ifreq, 0, sizeof(ifreq));
memset(&cfg, 0, sizeof(cfg));
- strncpy(ifreq.ifr_name, device, sizeof(ifreq.ifr_name));
+ strncpy(ifreq.ifr_name, device, sizeof(ifreq.ifr_name) - 1);
ifreq.ifr_data = (void *) &cfg;
cfg.tx_type = one_step ? HWTSTAMP_TX_ONESTEP_SYNC : HWTSTAMP_TX_ON;
@@ -85,7 +85,7 @@ int sk_interface_index(int fd, const char *name)
int err;
memset(&ifreq, 0, sizeof(ifreq));
- strcpy(ifreq.ifr_name, name);
+ strncpy(ifreq.ifr_name, name, sizeof(ifreq.ifr_name) - 1);
err = ioctl(fd, SIOCGIFINDEX, &ifreq);
if (err < 0) {
pr_err("ioctl SIOCGIFINDEX failed: %m");
@@ -154,7 +154,7 @@ int sk_interface_macaddr(const char *name, struct address *mac)
int err, fd;
memset(&ifreq, 0, sizeof(ifreq));
- strcpy(ifreq.ifr_name, name);
+ strncpy(ifreq.ifr_name, name, sizeof(ifreq.ifr_name) - 1);
fd = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP);
if (fd < 0) {
--
1.9.3
1.9.3