summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLorenzo Colitti <lorenzo@google.com>2019-04-10 23:22:30 +0900
committerMaciej Zenczykowski <maze@google.com>2019-05-02 00:49:33 +0000
commit3297c7d7bca85db2b178e8838138b71e9d2a86ad (patch)
tree0a8afeddec201ee6f1b47629cd6bdaefad13b8ca
parent35d9175db948861be168f20bf72f928802b85fe1 (diff)
downloadplatform_external_android-clat-3297c7d7bca85db2b178e8838138b71e9d2a86ad.tar.gz
platform_external_android-clat-3297c7d7bca85db2b178e8838138b71e9d2a86ad.tar.bz2
platform_external_android-clat-3297c7d7bca85db2b178e8838138b71e9d2a86ad.zip
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 Bug: 131268436 Change-Id: I9a5ea4de5f31d3c495871250a6493b07535a604b Merged-In: I9a5ea4de5f31d3c495871250a6493b07535a604b (cherry picked from commit 6a095dfa6bd2000f650308cdfa5a69e2635c02ec)
-rw-r--r--Android.bp14
-rw-r--r--clatd.c2
-rw-r--r--clatd_microbenchmark.c2
-rw-r--r--tun.c10
-rw-r--r--tun.h2
5 files changed, 23 insertions, 7 deletions
diff --git a/Android.bp b/Android.bp
index e0eeb2e..98b4010 100644
--- a/Android.bp
+++ b/Android.bp
@@ -54,6 +54,20 @@ cc_binary {
"liblog",
"libnetutils",
],
+
+ // Only enable clang-tidy for the daemon, not the tests, because enabling it for the
+ // tests substantially increases build/compile cycle times and doesn't really provide a
+ // security benefit.
+ tidy: true,
+ tidy_checks: [
+ "-*",
+ "cert-*",
+ "clang-analyzer-security*",
+ "android-*",
+ ],
+ tidy_flags: [
+ "-warnings-as-errors=clang-analyzer-security*,cert-*,android-*",
+ ],
}
// The configuration file.
diff --git a/clatd.c b/clatd.c
index 06ca799..d68dc05 100644
--- a/clatd.c
+++ b/clatd.c
@@ -381,7 +381,7 @@ void configure_interface(const char *uplink_interface, const char *plat_prefix,
logmsg(ANDROID_LOG_WARN, "ipv4mtu now set to = %d", Global_Clatd_Config.ipv4mtu);
}
- error = tun_alloc(tunnel->device4, tunnel->fd4);
+ error = tun_alloc(tunnel->device4, tunnel->fd4, sizeof(tunnel->device4));
if (error < 0) {
logmsg(ANDROID_LOG_FATAL, "tun_alloc/4 failed: %s", strerror(errno));
exit(1);
diff --git a/clatd_microbenchmark.c b/clatd_microbenchmark.c
index 91b0996..15a0376 100644
--- a/clatd_microbenchmark.c
+++ b/clatd_microbenchmark.c
@@ -67,7 +67,7 @@ int setup_tun() {
if (fd == -1) die("tun_open");
char dev[IFNAMSIZ] = DEVICENAME;
- int ret = tun_alloc(dev, fd);
+ int ret = tun_alloc(dev, fd, sizeof(dev));
if (ret == -1) die("tun_alloc");
struct ifreq ifr = {
.ifr_name = DEVICENAME,
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 @@ int tun_open() {
/* 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 @@ int tun_alloc(char *dev, int fd) {
close(fd);
return err;
}
- strcpy(dev, ifr.ifr_name);
+ strlcpy(dev, ifr.ifr_name, len);
return 0;
}
diff --git a/tun.h b/tun.h
index f0449b9..95650fa 100644
--- a/tun.h
+++ b/tun.h
@@ -30,7 +30,7 @@ struct tun_data {
};
int tun_open();
-int tun_alloc(char *dev, int fd);
+int tun_alloc(char *dev, int fd, size_t len);
int send_tun(int fd, clat_packet out, int iov_len);
int set_nonblocking(int fd);