Siddhesh Poyarekar has uploaded this change for review. (
https://gem5-review.googlesource.com/8561
Change subject: dev: Leave last byte in strncpy for NULL
......................................................................
dev: Leave last byte in strncpy for NULL
The length of the strncpy should be one less than the destination to
ensure that there is space for the last NULL byte in case the source
is longer than the destination.
Change-Id: Iea65fa6327c8242bd8ddf4bf9a5a2b5164996495
Signed-off-by: Siddhesh Poyarekar <[email protected]>
---
M src/dev/net/ethertap.cc
M src/dev/virtio/fs9p.cc
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/dev/net/ethertap.cc b/src/dev/net/ethertap.cc
index 4b5b9bd..ca19b48 100644
--- a/src/dev/net/ethertap.cc
+++ b/src/dev/net/ethertap.cc
@@ -404,7 +404,7 @@
struct ifreq ifr;
memset(&ifr, 0, sizeof(ifr));
ifr.ifr_flags = IFF_TAP | IFF_NO_PI;
- strncpy(ifr.ifr_name, p->tap_device_name.c_str(), IFNAMSIZ);
+ strncpy(ifr.ifr_name, p->tap_device_name.c_str(), IFNAMSIZ - 1);
if (ioctl(fd, TUNSETIFF, (void *)&ifr) < 0)
panic("Failed to access tap device %s.\n", ifr.ifr_name);
diff --git a/src/dev/virtio/fs9p.cc b/src/dev/virtio/fs9p.cc
index f2eb8ba..7857fea 100644
--- a/src/dev/virtio/fs9p.cc
+++ b/src/dev/virtio/fs9p.cc
@@ -371,7 +371,7 @@
fatal_if(sizeof(socket_address.sun_path) <= socket_path.length(),
"Incorrect length of socket path");
strncpy(socket_address.sun_path, socket_path.c_str(),
- sizeof(socket_address.sun_path));
+ sizeof(socket_address.sun_path) - 1);
if (bind(socket_id, (struct sockaddr*) &socket_address,
sizeof(struct sockaddr_un)) == -1){
perror("Socket binding");
--
To view, visit https://gem5-review.googlesource.com/8561
To unsubscribe, or for help writing mail filters, visit
https://gem5-review.googlesource.com/settings
Gerrit-Project: public/gem5
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: Iea65fa6327c8242bd8ddf4bf9a5a2b5164996495
Gerrit-Change-Number: 8561
Gerrit-PatchSet: 1
Gerrit-Owner: Siddhesh Poyarekar <[email protected]>
_______________________________________________
gem5-dev mailing list
[email protected]
http://m5sim.org/mailman/listinfo/gem5-dev