Fix security issues related with overflow and move ctor semantic 27/219227/5
authorOskar Chodowicz <o.chodowicz@partner.samsung.com>
Tue, 3 Dec 2019 11:31:33 +0000 (12:31 +0100)
committerLukasz Oleksak <l.oleksak@samsung.com>
Tue, 3 Dec 2019 13:38:46 +0000 (13:38 +0000)
Fix issuess with potential unsigned int overflow.
Restore semantic of move constructor.

Change-Id: I7fd86e253a3fc3d840cfb94b535c99cba19149eb

13 files changed:
src/ChangeIntTypeVconfKeyActivity.cpp
src/MenuBuilder.cpp
src/NavigationInterface.cpp
src/SelectActivity.cpp
src/Subject.hpp
src/batch/BatchRunner.cpp
src/batch/EvaluationValue.hpp
src/batch/EvaluationValueUIElement.cpp
src/batch/EvaluationValueVector.cpp
src/batch/Evaluator.cpp
src/utils.hpp
tests/no-ui-scenarios/BatchExecTests.cpp
tests/ui-scenarios/MenuBuilderTests.cpp

index d5b02544ccf4c03d77d209aa969c594d635e7c05..09068738eddfab887a24e0a20461fd0558170ed9 100644 (file)
@@ -45,7 +45,7 @@ public:
        {
                static_assert(GET_SIZE(DerivedType::KEYS) == GET_SIZE(DerivedType::STATES), "Incorrect activity");
 
-               for (auto i = 0u; i < GET_SIZE(DerivedType::KEYS); i++) {
+               for (size_t i = 0u; i < GET_SIZE(DerivedType::KEYS); i++) {
                        auto state = Singleton<VConfInterface>::instance().get({DerivedType::KEYS[i]}, 0);
                        if (!state) {
                                markAsCompleted();
index 634cbed23b4b85898e4c32518af36ef415150485..5baf31e6ce9e2955913ffaf1eafc45749799a89d 100644 (file)
@@ -227,7 +227,7 @@ VconfBoolTypeMenuItem::VconfBoolTypeMenuItem(std::vector<std::string> names, std
 size_t VconfBoolTypeMenuItem::getIndex() const
 {
        auto idx = 0;
-       for (auto i = 0u; i < vconfStateKeys.size(); ++i) {
+       for (size_t i = 0u; i < vconfStateKeys.size(); ++i) {
                auto val = Singleton<VConfInterface>::instance().get(vconfStateKeys[i], false) ? 1 : 0;
                idx += val * (1 << i);
        }
index f0c9a0b5f99860f4fa760b90a366724691ddd26e..b3db2f2b7e31bbda8f35fa0b88d17172f7f67cd1 100644 (file)
@@ -759,7 +759,7 @@ private:
                                                                t->elems = std::move(std::get<0>(elems));
                                                                t->names.resize(t->elems.size());
                                                                auto atspi = Singleton<UniversalSwitch>::instance().getAtspi();
-                                                               for (auto i = 0u; i < t->elems.size(); ++i) {
+                                                               for (size_t i = 0u; i < t->elems.size(); ++i) {
                                                                        atspi->getName(t->elems[i], [ = ](DBus::ValueOrError<std::string> name) {
                                                                                if (name) t->names[i] = std::move(std::get<0>(name));
                                                                        });
index 1d3d993036acd379972f5307c3c2787a1c09a0e9..80fcc30688cc2ee9604f05aed056f2e67ea562ac 100644 (file)
@@ -375,7 +375,7 @@ std::string SelectActivity::findActivityInMenu(int x, int y)
 
        auto fakeElem = Rectangle{{menuGeo.position.x, menuGeo.position.y}, {itemSize}};
 
-       for (auto i = 0u; i < itemsNo; ++i) {
+       for (size_t i = 0u; i < itemsNo; ++i) {
                if (x > fakeElem.position.x && x < fakeElem.position.x + itemSize.width && y > fakeElem.position.y && y < fakeElem.position.y + itemSize.height)
                        return gengridItemsData[i].first->getName();
 
@@ -548,7 +548,7 @@ Optional<telephony_call_status_e>  SelectActivity::getPhoneCallState()
                return {};
        }
 
-       for (auto i = 0u; i < list.count; i++) {
+       for (size_t i = 0u; i < list.count; i++) {
                telephony_call_h *callList;
                unsigned int callCount;
 
@@ -558,7 +558,7 @@ Optional<telephony_call_status_e>  SelectActivity::getPhoneCallState()
                        break;
                }
 
-               for (auto k = 0u; k < callCount; ++k) {
+               for (size_t k = 0u; k < callCount; ++k) {
                        telephony_call_status_e callState;
                        error = telephony_call_get_status(callList[i], &callState);
                        if (error != TELEPHONY_ERROR_NONE) {
@@ -606,7 +606,7 @@ std::string SelectActivity::getCompleteLabelOfButtonsKeysMenu()
                return "IDS_MENU_BUTTONS_KEYS_WIFI";
        }
 
-       for (auto i = 0u; i < list.count; i++) {
+       for (size_t i = 0u; i < list.count; i++) {
                telephony_sim_state_e simState;
                error = telephony_sim_get_state(list.handle[i], &simState);
                if (error != TELEPHONY_ERROR_NONE) {
index 78f302eb44179aa442e633191bf1c4969867b4e5..5c45af7338d8f8d2091bf1deae1412011f88376c 100644 (file)
@@ -33,7 +33,7 @@ public:
 
        virtual void detach(const Observer<T> *observer, const T *item)
        {
-               for (auto i = 0u; i < observers.size();) {
+               for (size_t i = 0u; i < observers.size();) {
                        auto tempObserver = observers[i].first.lock();
 
                        if (!tempObserver || (tempObserver.get() == observer && observers[i].second->getItem().get() == item)) {
index 217e6734528346a4c97bf6c4316698553c27d2fd..de8d078317d91d72b134ab39e2cf2871b782a355 100644 (file)
@@ -430,7 +430,7 @@ void BatchExecutor::makeUIElements(std::vector<AtspiAccessiblePtr> sources,
        auto exec = std::make_shared<Exec>();
        exec->callback = std::move(callback);
        exec->results.resize(sources.size());
-       for (auto i = 0u; i < sources.size(); ++i) {
+       for (size_t i = 0u; i < sources.size(); ++i) {
                makeUIElement(sources[i], [i, exec](DBus::ValueOrError<std::shared_ptr<UIElement>> ui) {
                        if (!ui) {
                                if (!exec->error)
@@ -749,7 +749,7 @@ void BatchExecutor::clearApplications()
 
        auto data = ApplicationInfoIterCbDataType{ nullptr, {}, this, "" };
 
-       for (auto row = 0; row < rows; ++row) {
+       for (size_t row = 0; row < rows; ++row) {
                rua_history_get_rec(&record, table, rows, cols, row);
                std::get<0>(data) = &record;
 
@@ -1028,7 +1028,7 @@ void BatchExecutor::insertMethods()
                                }
 
                                auto sleep_until = std::chrono::high_resolution_clock::now() + std::chrono::milliseconds{ 400 };
-                               for (auto i = 0u; i < tapCount; ++i)
+                               for (size_t i = 0u; i < tapCount; ++i)
                                {
                                        executeOnMainThread([&]() {
                                                auto res = utils::generateTapGesture(coord.x, coord.y, 0.0f, fingerCount);
index da199aa3df737c736a747c2e264b399006221f16..d4a5708b4d979cc87f92bb41de47104d6452d73d 100644 (file)
@@ -624,7 +624,7 @@ private:
                        {
                                std::vector<bool> used(expectedArgCount, false);
                                detail::Converter<0, expectedArgCount>::convert(args, sourceArgs, firstDefaultArgIndex, defaultArguments, sourceArgs.size());
-                               for (auto i = 0u; i < sourceArgs.size(); ++i) used[i] = true;
+                               for (size_t i = 0u; i < sourceArgs.size(); ++i) used[i] = true;
                                for (auto &val : sourceArgs.keywords()) {
                                        auto it = keywordIndexes.find(val.first);
                                        if (it == keywordIndexes.end()) {
@@ -636,12 +636,12 @@ private:
                                        used[it->second] = true;
                                        detail::Converter<0, expectedArgCount>::convertSingleArgumentByIndex(args, val.second, it->second);
                                }
-                               for (auto i = 0u; i < firstDefaultArgIndex; ++i) {
+                               for (size_t i = 0u; i < firstDefaultArgIndex; ++i) {
                                        if (!used[i]) {
                                                throw EvaluationFailure{} << "argument " << (i + 1) << " not set";
                                        }
                                }
-                               for (auto i = firstDefaultArgIndex; i < expectedArgCount; ++i) {
+                               for (size_t i = firstDefaultArgIndex; i < expectedArgCount; ++i) {
                                        if (!used[i]) {
                                                auto &val = defaultArguments[i - firstDefaultArgIndex];
                                                detail::Converter<0, expectedArgCount>::convertSingleArgumentByIndex(args, val, i);
index 3a8a92267833aabfd8dceeff70eb73a1691f6e2a..c7af5ab5597073e12e6a8ba9d2f5a05247839093 100644 (file)
@@ -90,7 +90,7 @@ public:
                if (name == "states") {
                        auto tmp = EvaluationContext::getCurrentEvaluationContext().executionInterface().getUIElementStates(value);
                        EvaluationValueSet v;
-                       for (auto i = 0u; i < tmp.size(); ++i) {
+                       for (size_t i = 0u; i < tmp.size(); ++i) {
                                if (tmp[i])
                                        v.insert(i);
                        }
index 228347ce68f48a5009e3489a031e8cd09ea56081..eb75b81a040a2a28e1be5c45e64cc753913d4502 100644 (file)
@@ -75,7 +75,7 @@ public:
                        return EvaluationValueBase::oper_order(other);
 
                auto &o = other->asVector();
-               for (auto i = 0u; i < std::min(value.size(), o.size()); ++i) {
+               for (size_t i = 0u; i < std::min(value.size(), o.size()); ++i) {
                        if (value[i] == o[i]) continue;
                        return value[i] < o[i] ? -1 : 1;
                }
@@ -151,7 +151,7 @@ public:
                auto indexes = getDoubleIndexes(from, to, value.size());
                std::vector<EvaluationValue> tmp;
                tmp.reserve(indexes.second - indexes.first);
-               for (auto i = indexes.first; i < indexes.second; ++i)
+               for (size_t i = indexes.first; i < indexes.second; ++i)
                        tmp.push_back(value[i]);
                return create(std::move(tmp));
        }
index 853aca1808b15b905a5f98cb805d41c4b08cc50e..d96dcb2dd06f0bd50f69ec5538a15a937f70e3b8 100644 (file)
@@ -287,7 +287,7 @@ EvaluationValue ArraySetDictEvaluator::evaluateImpl() const
 
        ASSERT(kind == Kind::DICT);
        EvaluationValueDict tmp;
-       for (auto i = 0u; i < vals.size(); i += 2) {
+       for (size_t i = 0u; i < vals.size(); i += 2) {
                tmp.insert({ std::move(vals[i]), std::move(vals[i + 1]) });
        }
        return std::move(tmp);
@@ -310,7 +310,7 @@ void ArraySetDictEvaluator::printSelfInfo(unsigned int depth) const
                }
        }
        if (kind == Kind::SET || kind == Kind::VECTOR) {
-               for (auto i = 0u; i < values.size(); ++i) {
+               for (size_t i = 0u; i < values.size(); ++i) {
                        printLocationAndIndent(location(), depth) << "element " << (i + 1);
                        values[i]->printSelfInfo(depth + 1);
                }
@@ -459,7 +459,7 @@ void OperatorEvaluator::printSelfInfo(unsigned int depth) const
 
                os << desc;
        }
-       for (auto i = 0u; i < args.size(); ++i) {
+       for (size_t i = 0u; i < args.size(); ++i) {
                printLocationAndIndent(location(), depth) << "element " << (i + 1);
                args[i]->printSelfInfo(depth + 1);
        }
@@ -490,7 +490,7 @@ EvaluationValue CompOperatorEvaluator::evaluateImpl() const
                return false;
        };
        auto l = args[0]->evaluate();
-       for (auto i = 0u; i < kinds.size(); ++i) {
+       for (size_t i = 0u; i < kinds.size(); ++i) {
                auto r = args[i + 1]->evaluate();
                if (!cmp(l, r, locations[i], kinds[i]))
                        return false;
@@ -530,7 +530,7 @@ void CompOperatorEvaluator::printSelfInfo(unsigned int depth) const
                }
        }
 
-       for (auto i = 0u; i < args.size(); ++i) {
+       for (size_t i = 0u; i < args.size(); ++i) {
                printLocationAndIndent(location(), depth) << "argument " << (i + 1) << " key";
                args[i]->printSelfInfo(depth + 1);
        }
@@ -592,7 +592,7 @@ void CallEvaluator::printSelfInfo(unsigned int depth) const
 {
        printLocationAndIndent(location(), depth) << "function call";
        function->printSelfInfo(depth + 1);
-       for (auto i = 0u; i < args.size(); ++i) {
+       for (size_t i = 0u; i < args.size(); ++i) {
                printLocationAndIndent(location(), depth) << "arg " << i << " is";
                args[i]->printSelfInfo(depth + 1);
        }
@@ -608,7 +608,7 @@ EvaluationValue LambdaEvaluator::evaluateImpl() const
                        if (this->argNames.size() != args.size())
                                throw EvaluationFailure{} << "invalid number of arguments";
                        EvaluationContext ctx;
-                       for (auto i = 0u; i < args.size(); ++i)
+                       for (size_t i = 0u; i < args.size(); ++i)
                        {
                                ctx.setVariable(argNames[i], args[i]);
                        }
@@ -630,7 +630,7 @@ EvaluationValue LambdaEvaluator::evaluateImpl() const
 void LambdaEvaluator::printSelfInfo(unsigned int depth) const
 {
        printLocationAndIndent(location(), depth) << "lambda definition";
-       for (auto i = 0u; i < argNames.size(); ++i) {
+       for (size_t i = 0u; i < argNames.size(); ++i) {
                printLocationAndIndent(location(), depth) << "arg " << i << " is " << argNames[i];
        }
        printLocationAndIndent(location(), depth) << "body";
@@ -648,7 +648,7 @@ void FunctionEvaluator::evaluateImpl() const
                        if (this->argNames.size() != args.size())
                                throw EvaluationFailure{} << "invalid number of arguments";
                        EvaluationContext ctx(data);
-                       for (auto i = 0u; i < args.size(); ++i)
+                       for (size_t i = 0u; i < args.size(); ++i)
                        {
                                ctx.setVariable(argNames[i], args[i]);
                        }
@@ -668,7 +668,7 @@ void FunctionEvaluator::evaluateImpl() const
 void FunctionEvaluator::printSelfInfo(unsigned int depth) const
 {
        printLocationAndIndent(location(), depth) << "function definition " << functionName;
-       for (auto i = 0u; i < argNames.size(); ++i) {
+       for (size_t i = 0u; i < argNames.size(); ++i) {
                printLocationAndIndent(location(), depth) << "arg " << i << " is " << argNames[i];
        }
        printLocationAndIndent(location(), depth) << "body";
@@ -745,7 +745,7 @@ void WaitEvaluator::evaluateImpl() const
        DebugEvaluator{} << getDebugId() << ": executing main block of wait clause";
        exec->evaluate();
        DebugEvaluator{} << getDebugId() << ": joining waiters (" << waits.size() << ")";
-       for (auto i = 0u; i < waits.size(); ++i) {
+       for (size_t i = 0u; i < waits.size(); ++i) {
                DebugEvaluator{} << getDebugId() << ": joining waiter " << i << " from " << waits[i]->getDebugId();
                auto &w = waitsValues[i];
                w.asWait()->join();
index 06cdf551aba3cac07552c8181d941545b74a242b..dcbe57b52c8f69956d1b5d5c2501b514b34a7133 100644 (file)
@@ -106,18 +106,17 @@ public:
                if (f) f();
        }
        DefferedCall(const DefferedCall &) = delete;
-       DefferedCall(DefferedCall &&o)
+       DefferedCall(DefferedCall &&o) noexcept : f(std::move(o.f))
        {
-               f = o.f;
                o.f = {};
        }
 
        DefferedCall &operator = (const DefferedCall &) = delete;
-       DefferedCall &operator = (DefferedCall &&o)
+       DefferedCall &operator = (DefferedCall &&o) noexcept
        {
                if (this != &o) {
                        if (f) f();
-                       f = o.f;
+                       f = std::move(o.f);
                        o.f = {};
                }
                return *this;
index 22b19dcabb3b812bee3b3ce202733e57791121cb..c537ce4ccd516cfe42177f2a80b38cb36d8bc24f 100644 (file)
@@ -97,7 +97,7 @@ TEST(TestExec, simpleLexer)
 
        ASSERT_EQ(tokens.size(), expectedTokens.size());
 
-       for (auto i = 0u; i < tokens.size(); ++i) {
+       for (size_t i = 0u; i < tokens.size(); ++i) {
                ASSERT_EQ(tokens[i].text(), std::get<0>(expectedTokens[i])) << "token " << i;
                ASSERT_EQ(tokens[i].location().lineNum(), std::get<1>(expectedTokens[i])) << "token " << i;
                ASSERT_EQ(tokens[i].location().offsetNum(), std::get<2>(expectedTokens[i])) << "token " << i;
@@ -249,7 +249,7 @@ protected:
                                                if (q < ' ') q = ' ';
                                        output << std::setw(2) << c << ": " << m << "\n";
                                        if (e.hasLocation() && c == e.location().lineNum()) {
-                                               for (auto i = 1u; i < e.location().offsetNum(); ++i)
+                                               for (size_t i = 1u; i < e.location().offsetNum(); ++i)
                                                        output << " ";
                                                output << "    ^\n";
                                        }
index 0668ade17c71d0cb51e2311e9afc09bd385f60c5..48287e39861ebb7fe0d3bc19c6fed6e36ed355cd 100644 (file)
@@ -108,7 +108,7 @@ public:
 
                EXPECT_EQ(actualMenuItems.size(), expectedMenuItemsNames.size());
 
-               for (auto ii = 0u; ii < actualMenuItems.size(); ++ii) {
+               for (size_t ii = 0u; ii < actualMenuItems.size(); ++ii) {
                        EXPECT_EQ(actualMenuItems[ii]->getName(), expectedMenuItemsNames[ii]);
                }
        }
@@ -140,7 +140,7 @@ public:
 
        void testVconfTypeMenuItemStates(MenuItem *item, const std::string &key, const std::vector<std::string> &requiredStates, int typeShift)
        {
-               for (auto ii = 0u; ii < requiredStates.size(); ++ii) {
+               for (size_t ii = 0u; ii < requiredStates.size(); ++ii) {
                        eventLoop::run([&]() {
                                if (typeShift)
                                        Singleton<VConfInterface>::instance().set(key, int(ii + typeShift));