diff options
author | Elliott Hughes <enh@google.com> | 2015-02-17 10:16:04 -0800 |
---|---|---|
committer | Elliott Hughes <enh@google.com> | 2015-02-17 10:25:23 -0800 |
commit | 9d1f515ed1066d095b923c538e8ac19c73e045f4 (patch) | |
tree | f2acee23a529ca45233f719b1665ba01bcc85b55 /libutils/tests | |
parent | 29576ae8901eb95d4c8a34f242a282b2fb73d35f (diff) | |
download | system_core-9d1f515ed1066d095b923c538e8ac19c73e045f4.zip system_core-9d1f515ed1066d095b923c538e8ac19c73e045f4.tar.gz system_core-9d1f515ed1066d095b923c538e8ac19c73e045f4.tar.bz2 |
Fix the WriteStringToFile overload that takes mode/owner/group.
The actual bug is == instead of !=, but the real cause was me trying to be
too clever. This patch switches to much simpler code, and -- since the
intended use of this code is security anyway -- adds logging if anything
goes wrong.
Bug: 19361774
Change-Id: If2af07d31a5002f9010b838247b691f6b28bdfb1
Diffstat (limited to 'libutils/tests')
-rw-r--r-- | libutils/tests/file_test.cpp | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/libutils/tests/file_test.cpp b/libutils/tests/file_test.cpp index 3703a49..cea18b6 100644 --- a/libutils/tests/file_test.cpp +++ b/libutils/tests/file_test.cpp @@ -71,6 +71,20 @@ TEST(file, WriteStringToFile) { EXPECT_EQ("abc", s); } +TEST(file, WriteStringToFile2) { + TemporaryFile tf; + ASSERT_TRUE(tf.fd != -1); + ASSERT_TRUE(android::WriteStringToFile("abc", tf.filename, 0660, getuid(), getgid())) << errno; + struct stat sb; + ASSERT_EQ(0, stat(tf.filename, &sb)); + ASSERT_EQ(0660U, (sb.st_mode & ~S_IFMT)); + ASSERT_EQ(getuid(), sb.st_uid); + ASSERT_EQ(getgid(), sb.st_gid); + std::string s; + ASSERT_TRUE(android::ReadFileToString(tf.filename, &s)) << errno; + EXPECT_EQ("abc", s); +} + TEST(file, WriteStringToFd) { TemporaryFile tf; ASSERT_TRUE(tf.fd != -1); |