Commit 055248e4 authored by Matthew Denton's avatar Matthew Denton Committed by Commit Bot

Linux sandbox: make BrokerClient::Readlink consistent with kernel

BrokerClient::Readlink returns -ENAMETOOLONG if the buffer is too small
for the pathname, but this is inconsistent with POSIX which fills up
the buffer with part of the pathname, and only returns -ENAMETOOLONG
if the actual pathname is longer than PATH_MAX or an individual
pathname component is longer than NAME_MAX.

Change-Id: I282f2ead6814bbd799e286a6e80ed5991ceeb54e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2379470
Commit-Queue: Matthew Denton <mpdenton@chromium.org>
Reviewed-by: default avatarRobert Sesek <rsesek@chromium.org>
Reviewed-by: default avatarTom Sepez <tsepez@chromium.org>
Cr-Commit-Position: refs/heads/master@{#802436}
parent 1ad72569
...@@ -112,11 +112,14 @@ int BrokerClient::Readlink(const char* path, char* buf, size_t bufsize) const { ...@@ -112,11 +112,14 @@ int BrokerClient::Readlink(const char* path, char* buf, size_t bufsize) const {
return -ENOMEM; return -ENOMEM;
if (return_length < 0) if (return_length < 0)
return -ENOMEM; return -ENOMEM;
// Sanity check that our broker is behaving correctly.
RAW_CHECK(return_length == static_cast<size_t>(return_value));
if (static_cast<size_t>(return_length) > bufsize) if (return_length > bufsize) {
return -ENAMETOOLONG; return_length = bufsize;
}
memcpy(buf, return_data, return_length); memcpy(buf, return_data, return_length);
return return_value; return return_length;
} }
int BrokerClient::Rename(const char* oldpath, const char* newpath) const { int BrokerClient::Rename(const char* oldpath, const char* newpath) const {
......
...@@ -1094,7 +1094,7 @@ void TestReadlinkHelper(bool fast_check_in_client) { ...@@ -1094,7 +1094,7 @@ void TestReadlinkHelper(bool fast_check_in_client) {
BrokerProcess open_broker(kFakeErrnoSentinel, command_set, permissions, BrokerProcess open_broker(kFakeErrnoSentinel, command_set, permissions,
fast_check_in_client); fast_check_in_client);
ASSERT_TRUE(open_broker.Init(base::BindOnce(&NoOpCallback))); ASSERT_TRUE(open_broker.Init(base::BindOnce(&NoOpCallback)));
EXPECT_EQ(-ENAMETOOLONG, open_broker.Readlink(newpath_name, buf, 4)); EXPECT_EQ(4, open_broker.Readlink(newpath_name, buf, 4));
} }
// Cleanup both paths. // Cleanup both paths.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment