mirror of
https://github.com/google/sandboxed-api.git
synced 2024-03-22 13:11:30 +08:00
Remove Tag
constructor, add standard comment for absl::WrapUnique(new T)
PiperOrigin-RevId: 483654433 Change-Id: I16b058a6b186f764f45bc5540f3f49d5a294ddeb
This commit is contained in:
parent
8d04efa62d
commit
6fbfb8f9bd
|
@ -603,11 +603,9 @@ cc_library(
|
||||||
visibility = ["//visibility:public"],
|
visibility = ["//visibility:public"],
|
||||||
deps = [
|
deps = [
|
||||||
":util",
|
":util",
|
||||||
"//sandboxed_api/util:status",
|
"@com_google_absl//absl/memory",
|
||||||
"@com_google_absl//absl/base:core_headers",
|
|
||||||
"@com_google_absl//absl/status",
|
"@com_google_absl//absl/status",
|
||||||
"@com_google_absl//absl/status:statusor",
|
"@com_google_absl//absl/status:statusor",
|
||||||
"@com_google_absl//absl/strings",
|
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -525,6 +525,7 @@ add_library(sandbox2_buffer ${SAPI_LIB_TYPE}
|
||||||
add_library(sandbox2::buffer ALIAS sandbox2_buffer)
|
add_library(sandbox2::buffer ALIAS sandbox2_buffer)
|
||||||
target_link_libraries(sandbox2_buffer
|
target_link_libraries(sandbox2_buffer
|
||||||
PRIVATE absl::core_headers
|
PRIVATE absl::core_headers
|
||||||
|
absl::memory
|
||||||
absl::status
|
absl::status
|
||||||
absl::strings
|
absl::strings
|
||||||
sapi::strerror
|
sapi::strerror
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
#include <cerrno>
|
#include <cerrno>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
|
#include "absl/memory/memory.h"
|
||||||
#include "absl/status/status.h"
|
#include "absl/status/status.h"
|
||||||
#include "absl/status/statusor.h"
|
#include "absl/status/statusor.h"
|
||||||
#include "sandboxed_api/sandbox2/util.h"
|
#include "sandboxed_api/sandbox2/util.h"
|
||||||
|
@ -29,7 +30,8 @@ namespace sandbox2 {
|
||||||
|
|
||||||
// Creates a new Buffer that is backed by the specified file descriptor.
|
// Creates a new Buffer that is backed by the specified file descriptor.
|
||||||
absl::StatusOr<std::unique_ptr<Buffer>> Buffer::CreateFromFd(int fd) {
|
absl::StatusOr<std::unique_ptr<Buffer>> Buffer::CreateFromFd(int fd) {
|
||||||
auto buffer = std::make_unique<Buffer>();
|
// Using `new` to access a non-public constructor.
|
||||||
|
auto buffer = absl::WrapUnique(new Buffer());
|
||||||
|
|
||||||
struct stat stat_buf;
|
struct stat stat_buf;
|
||||||
if (fstat(fd, &stat_buf) != 0) {
|
if (fstat(fd, &stat_buf) != 0) {
|
||||||
|
|
|
@ -28,11 +28,7 @@ namespace sandbox2 {
|
||||||
// The executor must distrust the content of this buffer, like everything
|
// The executor must distrust the content of this buffer, like everything
|
||||||
// else that comes under control of the sandboxee.
|
// else that comes under control of the sandboxee.
|
||||||
class Buffer final {
|
class Buffer final {
|
||||||
private:
|
|
||||||
struct Tag {};
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Buffer(Tag tag = {}) {}
|
|
||||||
~Buffer();
|
~Buffer();
|
||||||
|
|
||||||
Buffer(const Buffer&) = delete;
|
Buffer(const Buffer&) = delete;
|
||||||
|
@ -57,6 +53,8 @@ class Buffer final {
|
||||||
int fd() const { return fd_; }
|
int fd() const { return fd_; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
Buffer() = default;
|
||||||
|
|
||||||
uint8_t* buf_ = nullptr;
|
uint8_t* buf_ = nullptr;
|
||||||
int fd_ = -1;
|
int fd_ = -1;
|
||||||
size_t size_ = 0;
|
size_t size_ = 0;
|
||||||
|
|
|
@ -969,6 +969,7 @@ std::vector<sock_filter> PolicyBuilder::ResolveBpfFunc(BpfFunc f) {
|
||||||
}
|
}
|
||||||
|
|
||||||
absl::StatusOr<std::unique_ptr<Policy>> PolicyBuilder::TryBuild() {
|
absl::StatusOr<std::unique_ptr<Policy>> PolicyBuilder::TryBuild() {
|
||||||
|
// Using `new` to access a non-public constructor.
|
||||||
auto output = absl::WrapUnique(new Policy());
|
auto output = absl::WrapUnique(new Policy());
|
||||||
|
|
||||||
if (user_policy_.size() > kMaxUserPolicyLength) {
|
if (user_policy_.size() > kMaxUserPolicyLength) {
|
||||||
|
|
|
@ -169,12 +169,8 @@ absl::StatusOr<UnwindResult> StackTracePeer::LaunchLibunwindSandbox(
|
||||||
const Regs* regs, const Mounts& mounts) {
|
const Regs* regs, const Mounts& mounts) {
|
||||||
const pid_t pid = regs->pid();
|
const pid_t pid = regs->pid();
|
||||||
|
|
||||||
// Tell executor to use this special internal mode.
|
// Tell executor to use this special internal mode. Using `new` to access a
|
||||||
std::vector<std::string> argv;
|
// non-public constructor.
|
||||||
std::vector<std::string> envp;
|
|
||||||
|
|
||||||
// We're not using absl::make_unique here as we're a friend of this specific
|
|
||||||
// constructor and using make_unique won't work.
|
|
||||||
auto executor = absl::WrapUnique(new Executor(pid));
|
auto executor = absl::WrapUnique(new Executor(pid));
|
||||||
|
|
||||||
executor->limits()
|
executor->limits()
|
||||||
|
@ -264,9 +260,8 @@ absl::StatusOr<UnwindResult> StackTracePeer::LaunchLibunwindSandbox(
|
||||||
return absl::InternalError(
|
return absl::InternalError(
|
||||||
"Receiving status from libunwind sandbox failed");
|
"Receiving status from libunwind sandbox failed");
|
||||||
}
|
}
|
||||||
if (!status.ok()) {
|
SAPI_RETURN_IF_ERROR(status);
|
||||||
return status;
|
|
||||||
}
|
|
||||||
UnwindResult result;
|
UnwindResult result;
|
||||||
if (!comms->RecvProtoBuf(&result)) {
|
if (!comms->RecvProtoBuf(&result)) {
|
||||||
return absl::InternalError("Receiving libunwind result failed");
|
return absl::InternalError("Receiving libunwind result failed");
|
||||||
|
|
Loading…
Reference in New Issue
Block a user