mirror of
https://github.com/google/sandboxed-api.git
synced 2024-03-22 13:11:30 +08:00
Remove deprecated VecStringToCharPtrArr
PiperOrigin-RevId: 563374332 Change-Id: I6873ca0d45fd5de6ad8eab1cbc395032130e9697
This commit is contained in:
parent
b350a41a10
commit
f614862e07
|
@ -19,7 +19,7 @@
|
||||||
#include "sandboxed_api/util/status_macros.h"
|
#include "sandboxed_api/util/status_macros.h"
|
||||||
|
|
||||||
absl::Status CreateArchive(const char* initial_filename, int compress,
|
absl::Status CreateArchive(const char* initial_filename, int compress,
|
||||||
const char** argv, bool verbose) {
|
const std::vector<std::string>& argv, bool verbose) {
|
||||||
// We split the filename path into dirname and filename. To the filename we
|
// We split the filename path into dirname and filename. To the filename we
|
||||||
// prepend "/output/"" so that it will work with the security policy.
|
// prepend "/output/"" so that it will work with the security policy.
|
||||||
std::string abs_path = MakeAbsolutePathAtCWD(std::string(initial_filename));
|
std::string abs_path = MakeAbsolutePathAtCWD(std::string(initial_filename));
|
||||||
|
@ -28,9 +28,7 @@ absl::Status CreateArchive(const char* initial_filename, int compress,
|
||||||
|
|
||||||
std::string filename = sandbox2::file::JoinPath("/output/", filename_tmp);
|
std::string filename = sandbox2::file::JoinPath("/output/", filename_tmp);
|
||||||
|
|
||||||
std::vector<std::string> absolute_paths;
|
std::vector<std::string> absolute_paths = argv;
|
||||||
sandbox2::util::CharPtrArrToVecString(const_cast<char* const*>(argv),
|
|
||||||
&absolute_paths);
|
|
||||||
|
|
||||||
std::vector<std::string> relative_paths = absolute_paths;
|
std::vector<std::string> relative_paths = absolute_paths;
|
||||||
|
|
||||||
|
|
|
@ -101,7 +101,9 @@ int main(int unused_argc, char* argv[]) {
|
||||||
absl::Status status;
|
absl::Status status;
|
||||||
switch (mode) {
|
switch (mode) {
|
||||||
case 'c':
|
case 'c':
|
||||||
status = CreateArchive(filename, compress, argv, verbose);
|
status = CreateArchive(filename, compress,
|
||||||
|
sandbox2::util::CharArrPtr(argv).ToStringVector(),
|
||||||
|
verbose);
|
||||||
if (!status.ok()) {
|
if (!status.ok()) {
|
||||||
LOG(ERROR) << "Archive creation failed with message: "
|
LOG(ERROR) << "Archive creation failed with message: "
|
||||||
<< status.message();
|
<< status.message();
|
||||||
|
|
|
@ -23,7 +23,6 @@
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
using ::sandbox2::util::VecStringToCharPtrArr;
|
|
||||||
using ::sapi::IsOk;
|
using ::sapi::IsOk;
|
||||||
using ::sapi::file::JoinPath;
|
using ::sapi::file::JoinPath;
|
||||||
using ::sapi::file_util::fileops::Exists;
|
using ::sapi::file_util::fileops::Exists;
|
||||||
|
@ -164,8 +163,7 @@ std::string* MiniTarTest::init_wd_;
|
||||||
TEST_F(MiniTarTest, TestFileSimple) {
|
TEST_F(MiniTarTest, TestFileSimple) {
|
||||||
std::vector<std::string> v = {kFile1.data()};
|
std::vector<std::string> v = {kFile1.data()};
|
||||||
|
|
||||||
ASSERT_THAT(CreateArchive(id_.data(), 0, VecStringToCharPtrArr(v), false),
|
ASSERT_THAT(CreateArchive(id_.data(), 0, v, false), IsOk());
|
||||||
IsOk());
|
|
||||||
|
|
||||||
ASSERT_THAT(chdir(tmp_dir_.data()), Eq(0))
|
ASSERT_THAT(chdir(tmp_dir_.data()), Eq(0))
|
||||||
<< "Could not chdir into test data directory";
|
<< "Could not chdir into test data directory";
|
||||||
|
@ -178,8 +176,7 @@ TEST_F(MiniTarTest, TestFileSimple) {
|
||||||
|
|
||||||
TEST_F(MiniTarTest, TestMultipleFiles) {
|
TEST_F(MiniTarTest, TestMultipleFiles) {
|
||||||
std::vector<std::string> v = {kFile1.data(), kFile2.data(), kFile3.data()};
|
std::vector<std::string> v = {kFile1.data(), kFile2.data(), kFile3.data()};
|
||||||
ASSERT_THAT(CreateArchive(id_.data(), 0, VecStringToCharPtrArr(v), false),
|
ASSERT_THAT(CreateArchive(id_.data(), 0, v, false), IsOk());
|
||||||
IsOk());
|
|
||||||
ASSERT_THAT(Exists(id_.data(), false), IsTrue())
|
ASSERT_THAT(Exists(id_.data(), false), IsTrue())
|
||||||
<< "Archive file was not created";
|
<< "Archive file was not created";
|
||||||
|
|
||||||
|
@ -196,8 +193,7 @@ TEST_F(MiniTarTest, TestMultipleFiles) {
|
||||||
|
|
||||||
TEST_F(MiniTarTest, TestDirectorySimple) {
|
TEST_F(MiniTarTest, TestDirectorySimple) {
|
||||||
std::vector<std::string> v = {kDir2.data()};
|
std::vector<std::string> v = {kDir2.data()};
|
||||||
ASSERT_THAT(CreateArchive(id_.data(), 0, VecStringToCharPtrArr(v), false),
|
ASSERT_THAT(CreateArchive(id_.data(), 0, v, false), IsOk());
|
||||||
IsOk());
|
|
||||||
|
|
||||||
ASSERT_THAT(chdir(tmp_dir_.data()), Eq(0))
|
ASSERT_THAT(chdir(tmp_dir_.data()), Eq(0))
|
||||||
<< "Could not chdir into test data directory";
|
<< "Could not chdir into test data directory";
|
||||||
|
@ -210,8 +206,7 @@ TEST_F(MiniTarTest, TestDirectorySimple) {
|
||||||
|
|
||||||
TEST_F(MiniTarTest, TestDirectoryNested) {
|
TEST_F(MiniTarTest, TestDirectoryNested) {
|
||||||
std::vector<std::string> v = {kDir1.data()};
|
std::vector<std::string> v = {kDir1.data()};
|
||||||
ASSERT_THAT(CreateArchive(id_.data(), 0, VecStringToCharPtrArr(v), false),
|
ASSERT_THAT(CreateArchive(id_.data(), 0, v, false), IsOk());
|
||||||
IsOk());
|
|
||||||
|
|
||||||
ASSERT_THAT(chdir(tmp_dir_.data()), Eq(0))
|
ASSERT_THAT(chdir(tmp_dir_.data()), Eq(0))
|
||||||
<< "Could not chdir into test data directory";
|
<< "Could not chdir into test data directory";
|
||||||
|
@ -225,8 +220,7 @@ TEST_F(MiniTarTest, TestDirectoryNested) {
|
||||||
|
|
||||||
TEST_F(MiniTarTest, TestComplex) {
|
TEST_F(MiniTarTest, TestComplex) {
|
||||||
std::vector<std::string> v = {kFile1.data(), kDir1.data()};
|
std::vector<std::string> v = {kFile1.data(), kDir1.data()};
|
||||||
ASSERT_THAT(CreateArchive(id_.data(), 0, VecStringToCharPtrArr(v), false),
|
ASSERT_THAT(CreateArchive(id_.data(), 0, v, false), IsOk());
|
||||||
IsOk());
|
|
||||||
|
|
||||||
ASSERT_THAT(chdir(tmp_dir_.data()), Eq(0))
|
ASSERT_THAT(chdir(tmp_dir_.data()), Eq(0))
|
||||||
<< "Could not chdir into test data directory";
|
<< "Could not chdir into test data directory";
|
||||||
|
@ -242,9 +236,7 @@ TEST_F(MiniTarTest, TestComplex) {
|
||||||
TEST_F(MiniTarTest, TestCompress) {
|
TEST_F(MiniTarTest, TestCompress) {
|
||||||
std::vector<std::string> v = {kFile1.data(), kDir1.data()};
|
std::vector<std::string> v = {kFile1.data(), kDir1.data()};
|
||||||
int compress = 'Z';
|
int compress = 'Z';
|
||||||
ASSERT_THAT(
|
ASSERT_THAT(CreateArchive(id_.data(), compress, v, false), IsOk());
|
||||||
CreateArchive(id_.data(), compress, VecStringToCharPtrArr(v), false),
|
|
||||||
IsOk());
|
|
||||||
|
|
||||||
ASSERT_THAT(chdir(tmp_dir_.data()), Eq(0))
|
ASSERT_THAT(chdir(tmp_dir_.data()), Eq(0))
|
||||||
<< "Could not chdir into test data directory";
|
<< "Could not chdir into test data directory";
|
||||||
|
@ -259,9 +251,7 @@ TEST_F(MiniTarTest, TestCompress) {
|
||||||
TEST_F(MiniTarTest, TestGZIP) {
|
TEST_F(MiniTarTest, TestGZIP) {
|
||||||
std::vector<std::string> v = {kFile1.data(), kDir1.data()};
|
std::vector<std::string> v = {kFile1.data(), kDir1.data()};
|
||||||
int compress = 'z';
|
int compress = 'z';
|
||||||
ASSERT_THAT(
|
ASSERT_THAT(CreateArchive(id_.data(), compress, v, false), IsOk());
|
||||||
CreateArchive(id_.data(), compress, VecStringToCharPtrArr(v), false),
|
|
||||||
IsOk());
|
|
||||||
|
|
||||||
ASSERT_THAT(chdir(tmp_dir_.data()), Eq(0))
|
ASSERT_THAT(chdir(tmp_dir_.data()), Eq(0))
|
||||||
<< "Could not chdir into test data directory";
|
<< "Could not chdir into test data directory";
|
||||||
|
@ -276,9 +266,7 @@ TEST_F(MiniTarTest, TestGZIP) {
|
||||||
TEST_F(MiniTarTest, TestBZIP2) {
|
TEST_F(MiniTarTest, TestBZIP2) {
|
||||||
std::vector<std::string> v = {kFile1.data(), kDir1.data()};
|
std::vector<std::string> v = {kFile1.data(), kDir1.data()};
|
||||||
int compress = 'j';
|
int compress = 'j';
|
||||||
ASSERT_THAT(
|
ASSERT_THAT(CreateArchive(id_.data(), compress, v, false), IsOk());
|
||||||
CreateArchive(id_.data(), compress, VecStringToCharPtrArr(v), false),
|
|
||||||
IsOk());
|
|
||||||
|
|
||||||
ASSERT_THAT(chdir(tmp_dir_.data()), Eq(0))
|
ASSERT_THAT(chdir(tmp_dir_.data()), Eq(0))
|
||||||
<< "Could not chdir into test data directory";
|
<< "Could not chdir into test data directory";
|
||||||
|
@ -294,8 +282,7 @@ TEST_F(MiniTarTest, TestPaths) {
|
||||||
// These should be equivalent to kFile1 and kDir1 after cleaning.
|
// These should be equivalent to kFile1 and kDir1 after cleaning.
|
||||||
std::vector<std::string> v = {JoinPath("a/b/../../c/../", kFile1).data(),
|
std::vector<std::string> v = {JoinPath("a/b/../../c/../", kFile1).data(),
|
||||||
JoinPath("d/../e/././///../", kDir1).data()};
|
JoinPath("d/../e/././///../", kDir1).data()};
|
||||||
ASSERT_THAT(CreateArchive(id_.data(), 0, VecStringToCharPtrArr(v), false),
|
ASSERT_THAT(CreateArchive(id_.data(), 0, v, false), IsOk());
|
||||||
IsOk());
|
|
||||||
|
|
||||||
ASSERT_THAT(chdir(tmp_dir_.data()), Eq(0))
|
ASSERT_THAT(chdir(tmp_dir_.data()), Eq(0))
|
||||||
<< "Could not chdir into test data directory";
|
<< "Could not chdir into test data directory";
|
||||||
|
|
|
@ -96,20 +96,6 @@ void DumpCoverageData() {
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void CharPtrArrToVecString(char* const* arr, std::vector<std::string>* vec) {
|
|
||||||
*vec = CharPtrArray(arr).ToStringVector();
|
|
||||||
}
|
|
||||||
|
|
||||||
const char** VecStringToCharPtrArr(const std::vector<std::string>& vec) {
|
|
||||||
const int vec_size = vec.size();
|
|
||||||
const char** arr = new const char*[vec_size + 1];
|
|
||||||
for (int i = 0; i < vec_size; ++i) {
|
|
||||||
arr[i] = vec[i].c_str();
|
|
||||||
}
|
|
||||||
arr[vec_size] = nullptr;
|
|
||||||
return arr;
|
|
||||||
}
|
|
||||||
|
|
||||||
CharPtrArray::CharPtrArray(char* const* arr) : content_(ConcatenateAll(arr)) {
|
CharPtrArray::CharPtrArray(char* const* arr) : content_(ConcatenateAll(arr)) {
|
||||||
for (auto it = content_.begin(); it != content_.end();
|
for (auto it = content_.begin(); it != content_.end();
|
||||||
it += strlen(&*it) + 1) {
|
it += strlen(&*it) + 1) {
|
||||||
|
|
|
@ -25,23 +25,13 @@
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "absl/base/attributes.h"
|
#include "absl/base/attributes.h"
|
||||||
|
#include "absl/base/macros.h"
|
||||||
#include "absl/status/statusor.h"
|
#include "absl/status/statusor.h"
|
||||||
|
|
||||||
namespace sandbox2::util {
|
namespace sandbox2::util {
|
||||||
|
|
||||||
void DumpCoverageData();
|
void DumpCoverageData();
|
||||||
|
|
||||||
// Converts an array of char* (terminated by a nullptr, like argv, or environ
|
|
||||||
// arrays), to an std::vector<std::string>.
|
|
||||||
ABSL_DEPRECATED("Use CharPtrArray(arr).ToStringVector() instead")
|
|
||||||
void CharPtrArrToVecString(char* const* arr, std::vector<std::string>* vec);
|
|
||||||
|
|
||||||
// Converts a vector of strings to a newly allocated array. The array is limited
|
|
||||||
// by the terminating nullptr entry (like environ or argv). It must be freed by
|
|
||||||
// the caller.
|
|
||||||
ABSL_DEPRECATED("Use CharPtrArray class instead")
|
|
||||||
const char** VecStringToCharPtrArr(const std::vector<std::string>& vec);
|
|
||||||
|
|
||||||
// An char ptr array limited by the terminating nullptr entry (like environ
|
// An char ptr array limited by the terminating nullptr entry (like environ
|
||||||
// or argv).
|
// or argv).
|
||||||
class CharPtrArray {
|
class CharPtrArray {
|
||||||
|
@ -62,6 +52,14 @@ class CharPtrArray {
|
||||||
std::vector<const char*> array_;
|
std::vector<const char*> array_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Converts an array of char* (terminated by a nullptr, like argv, or environ
|
||||||
|
// arrays), to an std::vector<std::string>.
|
||||||
|
ABSL_DEPRECATED("Use CharPtrArray(arr).ToStringVector() instead")
|
||||||
|
inline void CharPtrArrToVecString(char* const* arr,
|
||||||
|
std::vector<std::string>* vec) {
|
||||||
|
*vec = sandbox2::util::CharPtrArray(arr).ToStringVector();
|
||||||
|
}
|
||||||
|
|
||||||
// Returns the program name (via /proc/self/comm) for a given PID.
|
// Returns the program name (via /proc/self/comm) for a given PID.
|
||||||
std::string GetProgName(pid_t pid);
|
std::string GetProgName(pid_t pid);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user