add CLOEXECs
Ensure that open file descriptors do not leak across an execve()
boundary by setting the O_CLOEXEC flag on them. Leaking file descriptors
to exec()d processes may prevent file descriptors from being properly
freed, introduce security bugs if the child process is untrusted, and
causes problems for systems like SELinux which perform strict checking
of passed file descriptors.
Bug: 112357170
Test: cts-tradefed run cts -m CtsRenderscriptTestCases
Change-Id: I91107f5712c2f5b4648b3dc45d6cbbc97d13762d
diff --git a/rsg_generator.c b/rsg_generator.c
index 5d30770..d0a95a2 100644
--- a/rsg_generator.c
+++ b/rsg_generator.c
@@ -472,7 +472,7 @@
}
const char* rsgFile = argv[1];
const char* outFile = argv[2];
- FILE* input = fopen(rsgFile, "r");
+ FILE* input = fopen(rsgFile, "re");
char choice = fgetc(input);
fclose(input);
@@ -485,7 +485,7 @@
yylex();
// printf("# of lines = %d\n", num_lines);
- FILE *f = fopen(outFile, "w");
+ FILE *f = fopen(outFile, "we");
printFileHeader(f);
switch (choice) {