OSDN Git Service

lpdumpd: Do not use stack to store arguments.
authorDavid Anderson <dvander@google.com>
Wed, 20 Nov 2019 01:04:39 +0000 (17:04 -0800)
committerDavid Anderson <dvander@google.com>
Wed, 20 Nov 2019 20:15:42 +0000 (20:15 +0000)
Bug: 144052321
Test: manual test
Change-Id: I700e22ef5c6c0a0c6a5f05c5bb4ea29b0077b34e

partition_tools/lpdumpd.cc

index 6110f33..7717e11 100644 (file)
@@ -40,18 +40,15 @@ class Lpdump : public BnLpdump {
     virtual ~Lpdump() = default;
 
     Status run(const std::vector<std::string>& args, std::string* aidl_return) override {
-        if (args.size() > std::numeric_limits<int>::max()) {
-            return Status::fromExceptionCode(Status::EX_ILLEGAL_ARGUMENT);
-        }
-        std::vector<std::string> m_args = args;
-        char* argv[m_args.size()];
-        for (size_t i = 0; i < m_args.size(); ++i) {
-            argv[i] = m_args[i].data();
+        std::vector<char*> local_argv;
+        std::vector<std::string> local_args = args;
+        for (auto& arg : local_args) {
+            local_argv.push_back(arg.data());
         }
         LOG(DEBUG) << "Dumping with args: " << base::Join(args, " ");
         std::stringstream output;
         std::stringstream error;
-        int ret = LpdumpMain((int)m_args.size(), argv, output, error);
+        int ret = LpdumpMain((int)local_argv.size(), local_argv.data(), output, error);
         std::string error_str = error.str();
         if (ret == 0) {
             if (!error_str.empty()) {