diff options
author | Oliver Kunz <okunz@google.com> | 2024-01-29 03:22:32 -0800 |
---|---|---|
committer | Copybara-Service <copybara-worker@google.com> | 2024-01-29 03:23:45 -0800 |
commit | f2840b37a328c67c839f218326f41fc7867aed59 (patch) | |
tree | 441f2ad684eb358083083c9352bacd028a6866b1 | |
parent | fa5360351b8ba7abffd20d3ff9fc5e2415bc768f (diff) | |
download | sandboxed-api-f2840b37a328c67c839f218326f41fc7867aed59.tar.gz |
NullPtr: Change SAPI to accept regular `nullptr` for sandboxed API calls.
This change allows to use a `nullptr` instead to having to instantiate a `sapi::v::NullPtr` object.
```
sapi::v::NullPtr null;
SAPI_RETURN_IF_ERROR(api.testNullPtr(&null);
```
Becomes:
```
SAPI_RETURN_IF_ERROR(api.testNullPtr(nullptr);
```
PiperOrigin-RevId: 602333882
Change-Id: Ie2517dbedab8c514d7a102c4ef4bad90b34a219d
-rw-r--r-- | sandboxed_api/sandbox.cc | 13 | ||||
-rw-r--r-- | sandboxed_api/var_ptr.h | 5 |
2 files changed, 15 insertions, 3 deletions
diff --git a/sandboxed_api/sandbox.cc b/sandboxed_api/sandbox.cc index 5541b75..02cc51c 100644 --- a/sandboxed_api/sandbox.cc +++ b/sandboxed_api/sandbox.cc @@ -324,6 +324,14 @@ absl::Status Sandbox::Call(const std::string& func, v::Callable* ret, // Copy all arguments into rfcall. int i = 0; for (auto* arg : args) { + if (arg == nullptr) { + rfcall.arg_type[i] = v::Type::kPointer; + rfcall.arg_size[i] = sizeof(void*); + rfcall.args[i].arg_int = 0; + VLOG(1) << "CALL ARG: (" << i << "): nullptr"; + ++i; + continue; + } rfcall.arg_size[i] = arg->GetSize(); rfcall.arg_type[i] = arg->GetType(); @@ -357,7 +365,6 @@ absl::Status Sandbox::Call(const std::string& func, v::Callable* ret, } rfcall.args[i].arg_int = fd->GetRemoteFd(); } - VLOG(1) << "CALL ARG: (" << i << "), Type: " << arg->GetTypeString() << ", Size: " << arg->GetSize() << ", Val: " << arg->ToString(); ++i; @@ -382,7 +389,9 @@ absl::Status Sandbox::Call(const std::string& func, v::Callable* ret, // Synchronize all pointers after the call if it's needed. for (auto* arg : args) { - SAPI_RETURN_IF_ERROR(SynchronizePtrAfter(arg)); + if (arg != nullptr) { + SAPI_RETURN_IF_ERROR(SynchronizePtrAfter(arg)); + } } VLOG(1) << "CALL EXIT: Type: " << ret->GetTypeString() diff --git a/sandboxed_api/var_ptr.h b/sandboxed_api/var_ptr.h index ad2568c..2c9894f 100644 --- a/sandboxed_api/var_ptr.h +++ b/sandboxed_api/var_ptr.h @@ -20,6 +20,7 @@ #include <memory> #include <string> +#include "absl/base/attributes.h" #include "absl/base/macros.h" #include "absl/strings/str_format.h" #include "sandboxed_api/var_abstract.h" @@ -79,7 +80,9 @@ class Ptr : public Reg<Var*> { }; // Good, old nullptr -class NullPtr : public Ptr { +class ABSL_DEPRECATED( + "Use regular `nullptr` or `NULL` instead. This class will eventually get " + "removed") NullPtr : public Ptr { public: NullPtr() : Ptr(&void_obj_, SyncType::kSyncNone) {} |