From: Pawel Wasowski Date: Tue, 19 Jan 2021 01:36:44 +0000 (+0100) Subject: [Datacontrol] Prevent crashes by purging code with undefined behavior X-Git-Tag: submit/tizen/20210128.113801~12 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=687dc363d3f61052d695e425da69460d9faa2434;p=platform%2Fcore%2Fapi%2Fwebapi-plugins.git [Datacontrol] Prevent crashes by purging code with undefined behavior The following line caused crashes: IdMap[info->requestId] = info.release(); Argument evaluation order was not strictly defined in C++ before C++17 - behavior of the expression above was undefined. C++17 introduced more strict rules and their implementation in GCC caused a crash after setting -std=c++17 - it seems, that info.release() would be now called before info->requestId. [Verification] tct-datacontrol-tizen-tests (auto, c++14 and c++17 build): 100% pass rate The snippet below crashed apps 100% times when webapi-plugins were compiled with C++17. Now, the snippet works fine var PROVIDER_ID = "http://tizen.org/datacontrol/provider/DictionaryDataControlProvider"; var DATA_ID = "Dictionary"; var TYPE_SQL = "SQL"; var TYPE_MAP = "MAP"; var globalDataControl = tizen.datacontrol.getDataControlConsumer(PROVIDER_ID, DATA_ID, TYPE_MAP); function successcb(id) { console.log("Ok: reqid " + id); } function errorcb(id, error) { console.log("Error id: " + id + ", error msg: " + error.message); } try { globalDataControl.addValue(123, "tizen", "Foo", successcb, errorcb); } catch (err) { console.log(err.name + ": " + err.message); } Change-Id: Ibd80f60d100a616b8a9607c27e9eebf8a64e7a10 --- diff --git a/src/datacontrol/datacontrol_instance.cc b/src/datacontrol/datacontrol_instance.cc index d954fa75..16488964 100644 --- a/src/datacontrol/datacontrol_instance.cc +++ b/src/datacontrol/datacontrol_instance.cc @@ -490,7 +490,8 @@ int DatacontrolInstance::RunMAPDataControlJob(const std::string& providerId, result = job(handle, &info->requestId); RETURN_IF_FAIL(result, "Doing job failed with error"); - IdMap[info->requestId] = info.release(); + auto requestId = info->requestId; + IdMap[requestId] = info.release(); return result; } @@ -524,7 +525,8 @@ int DatacontrolInstance::RunSQLDataControlJob(const std::string& providerId, result = job(handle, &info->requestId); RETURN_IF_FAIL(result, "Doing job failed with error"); - IdMap[info->requestId] = info.release(); + auto requestId = info->requestId; + IdMap[requestId] = info.release(); return result; }