More O_DIRECTORY | O_NOFOLLOW changes
Fix a few other spots where we're not using O_NOFOLLOW
with O_DIRECTORY.
Add O_CLOEXEC for good measure.
https://code.google.com/p/android/issues/detail?id=181945
Bug: 23044050
Change-Id: Ib535cbba29cdd587443ea9e1e75831f57fd7a93c
diff --git a/cmds/installd/utils.cpp b/cmds/installd/utils.cpp
index 4fcb1f5..5dfdf03 100644
--- a/cmds/installd/utils.cpp
+++ b/cmds/installd/utils.cpp
@@ -234,7 +234,7 @@
if ((name[1] == '.') && (name[2] == 0)) continue;
}
- subfd = openat(dfd, name, O_RDONLY | O_DIRECTORY | O_NOFOLLOW);
+ subfd = openat(dfd, name, O_RDONLY | O_DIRECTORY | O_NOFOLLOW | O_CLOEXEC);
if (subfd < 0) {
ALOGE("Couldn't openat %s: %s\n", name, strerror(errno));
result = -1;
@@ -294,7 +294,7 @@
int fd, res;
DIR *d;
- fd = openat(dfd, name, O_RDONLY | O_DIRECTORY);
+ fd = openat(dfd, name, O_RDONLY | O_DIRECTORY | O_NOFOLLOW | O_CLOEXEC);
if (fd < 0) {
ALOGE("Couldn't openat %s: %s\n", name, strerror(errno));
return -1;
@@ -634,7 +634,7 @@
if ((name[1] == '.') && (name[2] == 0)) continue;
}
- subfd = openat(dfd, name, O_RDONLY | O_DIRECTORY);
+ subfd = openat(dfd, name, O_RDONLY | O_DIRECTORY | O_NOFOLLOW | O_CLOEXEC);
if (subfd < 0) {
ALOGE("Couldn't openat %s: %s\n", name, strerror(errno));
continue;