Add mode when open(O_CREAT) is used.
When creating a new file using open(..., O_CREAT), it is an error
to fail to specify a creation mode. If a mode is not specified, a
random stack provided value is used as the "mode".
This will become a runtime error in a future version of Android.
Change-Id: I00609f37d2ea68e21b6404d542830386be354202
diff --git a/toolbox/dd.c b/toolbox/dd.c
index 53a6206..350f1d2 100644
--- a/toolbox/dd.c
+++ b/toolbox/dd.c
@@ -95,6 +95,7 @@
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
+#define DEFFILEMODE (S_IRUSR | S_IWUSR)
static void dd_close(void);
static void dd_in(void);
@@ -185,14 +186,14 @@
} else {
#define OFLAGS \
(O_CREAT | (ddflags & (C_SEEK | C_NOTRUNC) ? 0 : O_TRUNC))
- out.fd = open(out.name, O_RDWR | OFLAGS /*, DEFFILEMODE */);
+ out.fd = open(out.name, O_RDWR | OFLAGS, DEFFILEMODE);
/*
* May not have read access, so try again with write only.
* Without read we may have a problem if output also does
* not support seeks.
*/
if (out.fd < 0) {
- out.fd = open(out.name, O_WRONLY | OFLAGS /*, DEFFILEMODE */);
+ out.fd = open(out.name, O_WRONLY | OFLAGS, DEFFILEMODE);
out.flags |= NOREAD;
}
if (out.fd < 0) {