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

Side by Side Diff: dbus/message.cc

Issue 2081153002: No dbus::FileDescriptor in DebugDaemonClient (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address comments Created 4 years, 4 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 unified diff | Download patch
« no previous file with comments | « dbus/message.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "dbus/message.h" 5 #include "dbus/message.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/format_macros.h" 9 #include "base/format_macros.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 696 matching lines...) Expand 10 before | Expand all | Expand 10 after
707 707
708 void MessageWriter::AppendVariantOfBasic(int dbus_type, const void* value) { 708 void MessageWriter::AppendVariantOfBasic(int dbus_type, const void* value) {
709 const std::string signature(1u, // length 709 const std::string signature(1u, // length
710 base::checked_cast<char>(dbus_type)); 710 base::checked_cast<char>(dbus_type));
711 MessageWriter variant_writer(message_); 711 MessageWriter variant_writer(message_);
712 OpenVariant(signature, &variant_writer); 712 OpenVariant(signature, &variant_writer);
713 variant_writer.AppendBasic(dbus_type, value); 713 variant_writer.AppendBasic(dbus_type, value);
714 CloseContainer(&variant_writer); 714 CloseContainer(&variant_writer);
715 } 715 }
716 716
717 void MessageWriter::AppendFileDescriptor(int value) {
718 CHECK(IsDBusTypeUnixFdSupported());
719 AppendBasic(DBUS_TYPE_UNIX_FD, &value); // This duplicates the FD.
720 }
721
717 void MessageWriter::AppendFileDescriptor(const FileDescriptor& value) { 722 void MessageWriter::AppendFileDescriptor(const FileDescriptor& value) {
718 CHECK(IsDBusTypeUnixFdSupported()); 723 CHECK(IsDBusTypeUnixFdSupported());
719 724
720 if (!value.is_valid()) { 725 if (!value.is_valid()) {
721 // NB: sending a directory potentially enables sandbox escape 726 // NB: sending a directory potentially enables sandbox escape
722 LOG(FATAL) << "Attempt to pass invalid file descriptor"; 727 LOG(FATAL) << "Attempt to pass invalid file descriptor";
723 } 728 }
724 int fd = value.value(); 729 int fd = value.value();
725 AppendBasic(DBUS_TYPE_UNIX_FD, &fd); 730 AppendBasic(DBUS_TYPE_UNIX_FD, &fd);
726 } 731 }
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after
1009 return true; 1014 return true;
1010 } 1015 }
1011 1016
1012 bool MessageReader::PopVariantOfBasic(int dbus_type, void* value) { 1017 bool MessageReader::PopVariantOfBasic(int dbus_type, void* value) {
1013 MessageReader variant_reader(message_); 1018 MessageReader variant_reader(message_);
1014 if (!PopVariant(&variant_reader)) 1019 if (!PopVariant(&variant_reader))
1015 return false; 1020 return false;
1016 return variant_reader.PopBasic(dbus_type, value); 1021 return variant_reader.PopBasic(dbus_type, value);
1017 } 1022 }
1018 1023
1024 bool MessageReader::PopFileDescriptor(base::ScopedFD* value) {
1025 CHECK(IsDBusTypeUnixFdSupported());
1026
1027 int fd = -1;
1028 const bool success = PopBasic(DBUS_TYPE_UNIX_FD, &fd);
1029 if (!success)
1030 return false;
1031
1032 *value = base::ScopedFD(fd);
1033 return true;
1034 }
1035
1019 bool MessageReader::PopFileDescriptor(FileDescriptor* value) { 1036 bool MessageReader::PopFileDescriptor(FileDescriptor* value) {
1020 CHECK(IsDBusTypeUnixFdSupported()); 1037 CHECK(IsDBusTypeUnixFdSupported());
1021 1038
1022 int fd = -1; 1039 int fd = -1;
1023 const bool success = PopBasic(DBUS_TYPE_UNIX_FD, &fd); 1040 const bool success = PopBasic(DBUS_TYPE_UNIX_FD, &fd);
1024 if (!success) 1041 if (!success)
1025 return false; 1042 return false;
1026 1043
1027 value->PutValue(fd); 1044 value->PutValue(fd);
1028 // NB: the caller must check validity before using the value 1045 // NB: the caller must check validity before using the value
1029 return true; 1046 return true;
1030 } 1047 }
1031 1048
1032 } // namespace dbus 1049 } // namespace dbus
OLDNEW
« no previous file with comments | « dbus/message.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698