Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(936)

Unified Diff: dbus/message.cc

Issue 9700072: dbus: add support for passing file descriptors (Closed) Base URL: http://git.chromium.org/git/chromium/src@master
Patch Set: unit test nits Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « dbus/message.h ('k') | dbus/message_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: dbus/message.cc
diff --git a/dbus/message.cc b/dbus/message.cc
index 43fb3bb8b593718b6fc01961c1f97a705f66fde8..d52591217e47bedadb04afcaf57dfcc5b3fcb435 100644
--- a/dbus/message.cc
+++ b/dbus/message.cc
@@ -9,6 +9,7 @@
#include "base/basictypes.h"
#include "base/format_macros.h"
#include "base/logging.h"
+#include "base/platform_file.h"
#include "base/stringprintf.h"
#include "dbus/object_path.h"
#include "third_party/protobuf/src/google/protobuf/message_lite.h"
@@ -199,6 +200,16 @@ std::string Message::ToStringInternal(const std::string& indent,
output += ToStringInternal(indent + " ", &sub_reader);
break;
}
+ case UNIX_FD: {
+ CHECK(kDBusTypeUnixFdIsSupported);
+
+ FileDescriptor file_descriptor;
+ if (!reader->PopFileDescriptor(&file_descriptor))
+ return kBrokenMessage;
+ output += indent + "fd#" +
+ base::StringPrintf("%d", file_descriptor.value()) + "\n";
+ break;
+ }
default:
LOG(FATAL) << "Unknown type: " << type;
}
@@ -677,6 +688,19 @@ void MessageWriter::AppendVariantOfBasic(int dbus_type, const void* value) {
CloseContainer(&variant_writer);
}
+void MessageWriter::AppendFileDescriptor(const FileDescriptor& value) {
+ CHECK(kDBusTypeUnixFdIsSupported);
+
+ base::PlatformFileInfo info;
+ int fd = value.value();
+ bool ok = base::GetPlatformFileInfo(fd, &info);
+ if (!ok || info.is_directory) {
+ // NB: sending a directory potentially enables sandbox escape
+ LOG(FATAL) << "Attempt to pass invalid file descriptor";
+ }
+ AppendBasic(DBUS_TYPE_UNIX_FD, &fd);
+}
+
//
// MessageReader implementation.
//
@@ -936,4 +960,24 @@ bool MessageReader::PopVariantOfBasic(int dbus_type, void* value) {
return variant_reader.PopBasic(dbus_type, value);
}
+bool MessageReader::PopFileDescriptor(FileDescriptor* value) {
+ CHECK(kDBusTypeUnixFdIsSupported);
+
+ int fd = -1;
+ const bool success = PopBasic(DBUS_TYPE_UNIX_FD, &fd);
+ if (!success)
+ return false;
+
+ base::PlatformFileInfo info;
+ bool ok = base::GetPlatformFileInfo(fd, &info);
+ if (!ok || info.is_directory) {
+ base::ClosePlatformFile(fd);
+ // NB: receiving a directory potentially enables sandbox escape
+ LOG(FATAL) << "Attempt to receive invalid file descriptor";
+ return false; // NB: not reached
+ }
+ value->PutValue(fd);
+ return true;
+}
+
} // namespace dbus
« no previous file with comments | « dbus/message.h ('k') | dbus/message_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698