diff options
author | sbc <sbc@chromium.org> | 2014-10-20 12:29:38 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-10-20 19:30:07 +0000 |
commit | 9664c614f4d853fd7887fcb4d8249183a1169f0e (patch) | |
tree | 7ccfd11876376fc993703dc500601edb9e581a8e /native_client_sdk | |
parent | 1124df6b0a9a980605f8ce342bf1a49403656a84 (diff) | |
download | chromium_src-9664c614f4d853fd7887fcb4d8249183a1169f0e.zip chromium_src-9664c614f4d853fd7887fcb4d8249183a1169f0e.tar.gz chromium_src-9664c614f4d853fd7887fcb4d8249183a1169f0e.tar.bz2 |
[NaCl SDK] nacl_io: Fix utime() on directories.
It was previously failing with EISDIR. This is because
utime() internally acquires the node as O_WRONLY in
order to call the Futimens method. This was failing
because the check for opening a directory for write
was done in Open() rather than CanOpen().
Review URL: https://codereview.chromium.org/660353003
Cr-Commit-Position: refs/heads/master@{#300313}
Diffstat (limited to 'native_client_sdk')
5 files changed, 25 insertions, 7 deletions
diff --git a/native_client_sdk/src/libraries/nacl_io/kernel_handle.cc b/native_client_sdk/src/libraries/nacl_io/kernel_handle.cc index f7bf163..4f88bbf 100644 --- a/native_client_sdk/src/libraries/nacl_io/kernel_handle.cc +++ b/native_client_sdk/src/libraries/nacl_io/kernel_handle.cc @@ -44,6 +44,11 @@ Error KernelHandle::Init(int open_flags) { return EACCES; } + // Directories can only be opened read-only. + if ((open_flags & 3) != O_RDONLY && node_->IsaDir()) { + return EISDIR; + } + if (open_flags & O_APPEND) { Error error = node_->GetSize(&handle_attr_.offs); if (error) diff --git a/native_client_sdk/src/libraries/nacl_io/kernel_proxy.cc b/native_client_sdk/src/libraries/nacl_io/kernel_proxy.cc index 89c8e36..0837647 100644 --- a/native_client_sdk/src/libraries/nacl_io/kernel_proxy.cc +++ b/native_client_sdk/src/libraries/nacl_io/kernel_proxy.cc @@ -792,6 +792,11 @@ int KernelProxy::truncate(const char* path, off_t len) { return -1; } + // Directories cannot be truncated. + if (node->IsaDir()) { + return EISDIR; + } + if (!node->CanOpen(O_WRONLY)) { errno = EACCES; return -1; diff --git a/native_client_sdk/src/libraries/nacl_io/memfs/mem_fs.cc b/native_client_sdk/src/libraries/nacl_io/memfs/mem_fs.cc index 38c5070..70da25c 100644 --- a/native_client_sdk/src/libraries/nacl_io/memfs/mem_fs.cc +++ b/native_client_sdk/src/libraries/nacl_io/memfs/mem_fs.cc @@ -105,10 +105,6 @@ Error MemFs::OpenWithMode(const Path& path, int open_flags, mode_t mode, } else { // Opening an existing file. - // Directories can only be opened read-only. - if (node->IsaDir() && (open_flags & 3) != O_RDONLY) - return EISDIR; - // If we were expected to create it exclusively, fail if (open_flags & O_EXCL) return EEXIST; diff --git a/native_client_sdk/src/tests/nacl_io_test/filesystem_test.cc b/native_client_sdk/src/tests/nacl_io_test/filesystem_test.cc index d957991..0152cdf 100644 --- a/native_client_sdk/src/tests/nacl_io_test/filesystem_test.cc +++ b/native_client_sdk/src/tests/nacl_io_test/filesystem_test.cc @@ -77,9 +77,6 @@ TEST(FilesystemTest, Sanity) { EXPECT_EQ(0, fs.Open(Path("/"), O_RDONLY, &root)); ASSERT_EQ(0, root->GetStat(&buf)); ASSERT_EQ(S_IRWXU, buf.st_mode & S_IRWXU); - // Opening a directory for write should fail. - EXPECT_EQ(EISDIR, fs.Open(Path("/"), O_RDWR, &root)); - EXPECT_EQ(2, fs.num_nodes()); // Open the root directory, should not create a new file EXPECT_EQ(0, fs.Open(Path("/"), O_RDONLY, &root)); diff --git a/native_client_sdk/src/tests/nacl_io_test/kernel_proxy_test.cc b/native_client_sdk/src/tests/nacl_io_test/kernel_proxy_test.cc index c42ba59..ae3ee82 100644 --- a/native_client_sdk/src/tests/nacl_io_test/kernel_proxy_test.cc +++ b/native_client_sdk/src/tests/nacl_io_test/kernel_proxy_test.cc @@ -549,6 +549,18 @@ TEST_F(KernelProxyTest, Lstat) { EXPECT_EQ(0, ki_lstat("/foo", &buf)); } +TEST_F(KernelProxyTest, OpenDirectory) { + // Opening a directory for read should succeed. + int fd = ki_open("/", O_RDONLY, 0); + ASSERT_GT(fd, -1); + + // Opening a directory for write should fail. + EXPECT_EQ(-1, ki_open("/", O_RDWR, 0)); + EXPECT_EQ(errno, EISDIR); + EXPECT_EQ(-1, ki_open("/", O_WRONLY, 0)); + EXPECT_EQ(errno, EISDIR); +} + TEST_F(KernelProxyTest, OpenWithMode) { int fd = ki_open("/foo", O_CREAT | O_RDWR, 0723); ASSERT_GT(fd, -1); @@ -586,6 +598,9 @@ TEST_F(KernelProxyTest, Utimes) { // utime should work if the file is write-only. EXPECT_EQ(0, ki_utimes("/dummy", times)); + // utime should work on directories (which can never be opened for write) + EXPECT_EQ(0, ki_utimes("/", times)); + // or if the file is read-only. EXPECT_EQ(0, ki_chmod("/dummy", 0444)); EXPECT_EQ(0, ki_utimes("/dummy", times)); |