Enable clang-tidy for clatd.
Enable the same warnings used elsewhere in the tree, and fix two
warnings it found (a safe use of strcpy, and a missing O_CLOEXEC
when opening the tun device node.
Test: builds, boots, clatd works
Test: m clatd clatd_test clatd_microbenchmark && atest clatd_test
Change-Id: I9a5ea4de5f31d3c495871250a6493b07535a604b
diff --git a/tun.c b/tun.c
index 406fc2f..7ecbf2c 100644
--- a/tun.c
+++ b/tun.c
@@ -32,9 +32,9 @@
int tun_open() {
int fd;
- fd = open("/dev/tun", O_RDWR);
+ fd = open("/dev/tun", O_RDWR | O_CLOEXEC);
if (fd < 0) {
- fd = open("/dev/net/tun", O_RDWR);
+ fd = open("/dev/net/tun", O_RDWR | O_CLOEXEC);
}
return fd;
@@ -43,8 +43,10 @@
/* function: tun_alloc
* creates a tun interface and names it
* dev - the name for the new tun device
+ * fd - an open fd to the tun device node
+ * len - the length of the buffer pointed to by dev
*/
-int tun_alloc(char *dev, int fd) {
+int tun_alloc(char *dev, int fd, size_t len) {
struct ifreq ifr;
int err;
@@ -60,7 +62,7 @@
close(fd);
return err;
}
- strcpy(dev, ifr.ifr_name);
+ strlcpy(dev, ifr.ifr_name, len);
return 0;
}