Refactor logic to check sending buffer size.
authorHyunbin Lee <hyunbin.lee@samsung.com>
Fri, 5 Apr 2013 08:42:59 +0000 (17:42 +0900)
committerHyunbin Lee <hyunbin.lee@samsung.com>
Fri, 5 Apr 2013 09:11:12 +0000 (18:11 +0900)
Change-Id: Ib64d1742ae3363b33f3359c82c2731faed47eea0
Signed-off-by: Hyunbin Lee <hyunbin.lee@samsung.com>
src/app/FApp_AppControlManager.cpp
src/app/FApp_Aul.cpp
src/app/FApp_DataControlProviderManagerImpl.cpp
src/app/FApp_MapDataControlImpl.cpp
src/app/FApp_SqlDataControlImpl.cpp
src/app/FApp_SqlDataControlImpl.h

index 2fcfe60..de50e3f 100755 (executable)
@@ -83,7 +83,6 @@ namespace Tizen { namespace App
 const wchar_t TIZEN_OPERATION_PICK[] = L"http://tizen.org/appcontrol/operation/pick";
 const wchar_t SELECTOR_NOTI_KEY[] = L"__APP_SVC_CALLER_NOTI__";
 const int _MAX_PACKAGE_ID_LENGTH = 10;
-const int _MAX_DATA_ARGUMENT_LENGTH = 32768; // 32KB
 
 _InProcessInfo::~_InProcessInfo(void)
 {
@@ -501,14 +500,6 @@ _AppControlManager::LaunchApp(const AppId& appId, _AppArg* pArg, int req)
        // [INFO] Ugly solution for submode support
        pArg->UpdateAppId(tempId);
        kb = pArg->GetBundle();
-
-       bundle_raw* dataBuf = null;
-       int dataLen = 0;
-       int res = bundle_encode(kb, &dataBuf, &dataLen);
-       bundle_free_encoded_rawdata(&dataBuf);
-       SysTryReturnResult(NID_APP, res == 0, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
-       SysTryReturnResult(NID_APP, dataLen <= _MAX_DATA_ARGUMENT_LENGTH, E_MAX_EXCEEDED,
-                       "The data length (%d) exceeds the maximum limit.", dataLen);
        
        pid = appsvc_run_service(kb, req, LaunchResultCb, this);
        if (pid > 0)
index 171a22d..529f6fe 100755 (executable)
@@ -72,7 +72,6 @@ const int _MAX_TIZEN_SVC_DESC_LEN = 1024;
 
 const int _MAX_CATEGORY = 12;
 const int _MAX_PACKAGE_ID_LENGTH = 10;
-const int _MAX_DATA_ARGUMENT_LENGTH = 32768; // 32KB
 
 // borrowed from app-svc/include/pri_key.h
 #define APP_SVC_K_RES_VAL      "__APP_SVC_K_RES_VAL__"
@@ -137,14 +136,6 @@ _Aul::SendResult(bundle* b, appsvc_result_val res)
        snprintf(tmp, 32, "%d", static_cast<int>(res));
        appsvc_add_data(b, APP_SVC_K_RES_VAL, tmp);
 
-       bundle_raw* dataBuf = null;
-       int dataLen = 0;
-       int ret = bundle_encode(b, &dataBuf, &dataLen);
-       bundle_free_encoded_rawdata(&dataBuf);
-       SysTryReturnResult(NID_APP, ret == 0, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
-       SysTryReturnResult(NID_APP, dataLen <= _MAX_DATA_ARGUMENT_LENGTH, E_MAX_EXCEEDED,
-                       "The data length (%d) exceeds the maximum limit.", dataLen);
-
        int aul_ret = aul_send_service_result(b);
 
        return GetConvertedResult(aul_ret, "SendResult");
index e3eecb6..d4ab5a4 100644 (file)
@@ -55,6 +55,8 @@ extern const char* _DATACONTROL_RESULTSET_DIR;
 namespace Tizen { namespace App
 {
 
+static const int _MAX_ARGUMENT_SIZE = 16384; // 16KB
+
 result
 _DataControlProviderManagerImpl::SetSqlDataControlProviderEventListener(ISqlDataControlProviderEventListener* pListener)
 {
@@ -161,6 +163,8 @@ _DataControlProviderManagerImpl::SendDataControlResult(RequestId reqId, _DataCon
        }
        SysTryCatch(NID_APP, pErrorMessage, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY,
                        "[E_OUT_OF_MEMORY] The memory was insufficient.");
+       SysTryCatch(NID_APP, pErrorMessage->GetLength() <= _MAX_ARGUMENT_SIZE, r = E_MAX_EXCEEDED, E_MAX_EXCEEDED,
+                       "[E_MAX_EXCEEDED] The size of sending argument (%d) exceeds the maximum limit.", pErrorMessage->GetLength());
        pResultArgList->Add(*pErrorMessage); // result list[1]
 
        switch (requestType)
@@ -230,6 +234,7 @@ _DataControlProviderManagerImpl::SendDataControlResult(RequestId reqId, _DataCon
                                        "[E_OUT_OF_MEMORY] The memory was insufficient.");
                        pResultArgList->Add(*pResultCount); // result list[2]
 
+                       long long argSize = 0;
                        for (int i = currentoffset; i < num; i++)
                        {
                                String* pTempValue = dynamic_cast< String* >(pResultValueList->GetAt(i));
@@ -240,7 +245,10 @@ _DataControlProviderManagerImpl::SendDataControlResult(RequestId reqId, _DataCon
                                SysTryCatch(NID_APP, pResultValue, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY,
                                                "[E_OUT_OF_MEMORY] The memory was insufficient.");
                                pResultArgList->Add(*pResultValue); // list[3] ~
+                               argSize += pResultValue->GetLength() * sizeof(wchar_t);
                        }
+                       SysTryCatch(NID_APP, argSize <= _MAX_ARGUMENT_SIZE, r = E_MAX_EXCEEDED, E_MAX_EXCEEDED,
+                                       "[E_MAX_EXCEEDED] The size of sending argument (%d) exceeds the maximum limit.", argSize);
                }
                break;
        }
index 0cf7b3c..6b2e2d6 100644 (file)
@@ -50,6 +50,7 @@ namespace Tizen { namespace App
 {
 
 static const int MAX_REQUEST_COUNT = 128;
+static const int _MAX_ARGUMENT_SIZE = 16384; // 16KB
 
 class _MapDataControlEventArg
        : public IEventArg
@@ -205,21 +206,26 @@ _MapDataControlImpl::GetValue(const String& dataId, const String& key,
        SysTryReturnResult(NID_APP, (__access & _DATACONTROL_ACCESS_READ) > 0, E_ILLEGAL_ACCESS,
                        "The GetValue query is not permitted by DataControl provider.");
 
+       String* pPageNo = null;
+       String* pCountPerPage = null;
        int id = 0;
        result r = E_SUCCESS;
 
-       ArrayList* pArgList = null;
-       pArgList = new ArrayList();
+       ArrayList* pArgList = new ArrayList();
        pArgList->Construct();
 
        pArgList->Add(*(new String(dataId)));
        pArgList->Add(*(new String(key)));
+       long long argSize = dataId.GetLength() * sizeof(wchar_t);
+       argSize += key.GetLength() * sizeof(wchar_t);
+       SysTryCatch(NID_APP, argSize <= _MAX_ARGUMENT_SIZE, r = E_MAX_EXCEEDED, E_MAX_EXCEEDED,
+                       "[E_MAX_EXCEEDED] The size of sending argument (%d) exceeds the maximum limit.", argSize);
 
-       String* pPageNo = new String();
+       pPageNo = new (std::nothrow) String();
        pPageNo->Append(pageNo);
        pArgList->Add(*pPageNo);
 
-       String* pCountPerPage = new String();
+       pCountPerPage = new (std::nothrow) String();
        pCountPerPage->Append(countPerPage);
        pArgList->Add(*pCountPerPage);
 
@@ -450,6 +456,11 @@ _MapDataControlImpl::AddValue(const String& dataId, const String& key,
        pArgList->Add(*(new String(dataId)));
        pArgList->Add(*(new String(key)));
        pArgList->Add(*(new String(value)));
+       long long argSize = dataId.GetLength() * sizeof(wchar_t);
+       argSize += key.GetLength() * sizeof(wchar_t);
+       argSize += value.GetLength() * sizeof(wchar_t);
+       SysTryCatch(NID_APP, argSize <= _MAX_ARGUMENT_SIZE, r = E_MAX_EXCEEDED, E_MAX_EXCEEDED,
+                       "[E_MAX_EXCEEDED] The size of sending argument (%d) exceeds the maximum limit.", argSize);
 
        r = StartMapDataControl(_DATACONTROL_REQUEST_TYPE_MAP_INSERT, pArgList, &id);
        SysTryCatch(NID_APP, !IsFailed(r), , r, "[%s] Propagating to caller...", GetErrorMessage(r));
@@ -485,6 +496,12 @@ _MapDataControlImpl::SetValue(const String& dataId, const String& key,
        pArgList->Add(*(new String(key)));
        pArgList->Add(*(new String(oldValue)));
        pArgList->Add(*(new String(newValue)));
+       long long argSize = dataId.GetLength() * sizeof(wchar_t);
+       argSize += key.GetLength() * sizeof(wchar_t);
+       argSize += oldValue.GetLength() * sizeof(wchar_t);
+       argSize += newValue.GetLength() * sizeof(wchar_t);
+       SysTryCatch(NID_APP, argSize <= _MAX_ARGUMENT_SIZE, r = E_MAX_EXCEEDED, E_MAX_EXCEEDED,
+                       "[E_MAX_EXCEEDED] The size of sending argument (%d) exceeds the maximum limit.", argSize);
 
        r = StartMapDataControl(_DATACONTROL_REQUEST_TYPE_MAP_UPDATE, pArgList, &id);
        SysTryCatch(NID_APP, !IsFailed(r), , r, "[%s] Propagating to caller...", GetErrorMessage(r));
@@ -519,6 +536,11 @@ _MapDataControlImpl::RemoveValue(const String& dataId, const String& key,
        pArgList->Add(*(new String(dataId)));
        pArgList->Add(*(new String(key)));
        pArgList->Add(*(new String(value)));
+       long long argSize = dataId.GetLength() * sizeof(wchar_t);
+       argSize += key.GetLength() * sizeof(wchar_t);
+       argSize += value.GetLength() * sizeof(wchar_t);
+       SysTryCatch(NID_APP, argSize <= _MAX_ARGUMENT_SIZE, r = E_MAX_EXCEEDED, E_MAX_EXCEEDED,
+                       "[E_MAX_EXCEEDED] The size of sending argument (%d) exceeds the maximum limit.", argSize);
 
        r = StartMapDataControl(_DATACONTROL_REQUEST_TYPE_MAP_DELETE, pArgList, &id);
        SysTryCatch(NID_APP, !IsFailed(r), , r, "[%s] Propagating to caller...", GetErrorMessage(r));
index 6dce4b6..9aaa9d9 100644 (file)
@@ -57,6 +57,7 @@ namespace Tizen { namespace App
 {
 
 static const int MAX_REQUEST_COUNT = 128;
+static const int _MAX_ARGUMENT_SIZE = 16384; // 16KB
 
 class _SqlDataControlEventArg
        : public IEventArg
@@ -219,6 +220,7 @@ _SqlDataControlImpl::Select(const String& dataId, const IList* pColumnList, cons
        pArgList->Construct();
 
        pArgList->Add(*(new String(dataId))); // list(0): data ID
+       long long argSize = dataId.GetLength() * sizeof(wchar_t);
 
        if (pColumnList != null)
        {
@@ -237,6 +239,7 @@ _SqlDataControlImpl::Select(const String& dataId, const IList* pColumnList, cons
                                        "[E_INVALID_ARG] The object is not String class.");
 
                        pArgList->Add(*(new String(*pColumn)));
+                       argSize += pColumn->GetLength() * sizeof(wchar_t);
                        SysLog(NID_APP, "[DC_CALLER] column[%d]: %ls", i, pColumn->GetPointer());
                        i++;
                }
@@ -249,6 +252,7 @@ _SqlDataControlImpl::Select(const String& dataId, const IList* pColumnList, cons
        if (pWhere != null)     // list(3): where clause
        {
                pArgList->Add(*(new String(*pWhere)));
+               argSize += pWhere->GetLength() * sizeof(wchar_t);
                SysLog(NID_APP, "[DC_CALLER] pWhere: %ls", pWhere->GetPointer());
        }
        else
@@ -259,12 +263,15 @@ _SqlDataControlImpl::Select(const String& dataId, const IList* pColumnList, cons
        if (pOrder != null)     // list(4): order clause
        {
                pArgList->Add(*(new String(*pOrder)));
+               argSize += pOrder->GetLength() * sizeof(wchar_t);
                SysLog(NID_APP, "[DC_CALLER] pOrder: %ls", pOrder->GetPointer());
        }
        else
        {
                pArgList->Add(*(new String(L"NULL")));
        }
+       SysTryCatch(NID_APP, argSize <= _MAX_ARGUMENT_SIZE, r = E_MAX_EXCEEDED, E_MAX_EXCEEDED,
+                       "[E_MAX_EXCEEDED] The size of sending argument (%d) exceeds the maximum limit.", argSize);
 
        pArgList->Add(*(new String(Integer::ToString(pageNo)))); // list(5): page number
 
@@ -483,8 +490,7 @@ CATCH:
 }
 
 result
-_SqlDataControlImpl::Insert(const Tizen::Base::String& dataId, const Tizen::Base::Collection::IMap& insertMap,
-               RequestId& reqId)
+_SqlDataControlImpl::Insert(const String& dataId, const IMap& insertMap, RequestId& reqId)
 {
        SysTryReturnResult(NID_APP, (__access & _DATACONTROL_ACCESS_WRITE) > 0, E_ILLEGAL_ACCESS,
                        "The INSERT query is not permitted by DataControl provider.");
@@ -502,6 +508,7 @@ _SqlDataControlImpl::Insert(const Tizen::Base::String& dataId, const Tizen::Base
        pArgList->Construct();
 
        pArgList->Add(*(new String(dataId))); // list(0): data ID
+       long long argSize = dataId.GetLength() * sizeof(wchar_t);
 
        pArgList->Add(*(new String(Integer::ToString(columnCount)))); // list(1): inserted column count
        SysLog(NID_APP, "[DC_CALLER] inserted column count: %d", columnCount);
@@ -523,8 +530,12 @@ _SqlDataControlImpl::Insert(const Tizen::Base::String& dataId, const Tizen::Base
                pArgList->Add(*(new String(*pValue)));
                SysLog(NID_APP, "[DC_CALLER] pValue[%d]: %ls", i, pValue->GetPointer());
 
+               argSize += pColumn->GetLength() * sizeof(wchar_t);
+               argSize += pValue->GetLength() * sizeof(wchar_t);
                i++;
        }
+       SysTryCatch(NID_APP, argSize <= _MAX_ARGUMENT_SIZE, r = E_MAX_EXCEEDED, E_MAX_EXCEEDED,
+                       "[E_MAX_EXCEEDED] The size of sending argument (%d) exceeds the maximum limit.", argSize);
 
        r = StartSqlDataControl(_DATACONTROL_REQUEST_TYPE_SQL_INSERT, pArgList, &id);
        SysTryCatch(NID_APP, !IsFailed(r), , r, "[%s] Propagating to caller...", GetErrorMessage(r));
@@ -544,8 +555,7 @@ CATCH:
 }
 
 result
-_SqlDataControlImpl::Update(const Tizen::Base::String& dataId, const Tizen::Base::Collection::IMap& updateMap,
-                       const Tizen::Base::String* pWhere, RequestId& reqId)
+_SqlDataControlImpl::Update(const String& dataId, const IMap& updateMap, const String* pWhere, RequestId& reqId)
 {
        SysTryReturnResult(NID_APP, (__access & _DATACONTROL_ACCESS_WRITE) > 0, E_ILLEGAL_ACCESS,
                        "The UPDATE query is not permitted by DataControl provider.");
@@ -563,6 +573,7 @@ _SqlDataControlImpl::Update(const Tizen::Base::String& dataId, const Tizen::Base
        pArgList->Construct();
 
        pArgList->Add(*(new String(dataId))); // list(0): data ID
+       long long argSize = dataId.GetLength() * sizeof(wchar_t);
 
        pArgList->Add(*(new String(Integer::ToString(columnCount)))); // list(1): updated column count
        SysLog(NID_APP, "[DC_CALLER] updated column count: %d", columnCount);
@@ -584,18 +595,23 @@ _SqlDataControlImpl::Update(const Tizen::Base::String& dataId, const Tizen::Base
                pArgList->Add(*(new String(*pValue)));
                SysLog(NID_APP, "[DC_CALLER] pValue[%d]: %ls", i, pValue->GetPointer());
 
+               argSize += pColumn->GetLength() * sizeof(wchar_t);
+               argSize += pValue->GetLength() * sizeof(wchar_t);
                i++;
        }
 
        if (pWhere != null)     // list(3): where clause
        {
                pArgList->Add(*(new String(*pWhere)));
+               argSize += pWhere->GetLength() * sizeof(wchar_t);
                SysLog(NID_APP, "[DC_CALLER] pWhere: %ls", pWhere->GetPointer());
        }
        else
        {
                pArgList->Add(*(new String(L"NULL")));
        }
+       SysTryCatch(NID_APP, argSize <= _MAX_ARGUMENT_SIZE, r = E_MAX_EXCEEDED, E_MAX_EXCEEDED,
+                       "[E_MAX_EXCEEDED] The size of sending argument (%d) exceeds the maximum limit.", argSize);
 
        r = StartSqlDataControl(_DATACONTROL_REQUEST_TYPE_SQL_UPDATE, pArgList, &id);
        SysTryCatch(NID_APP, !IsFailed(r), , r, "[%s] Propagating to caller...", GetErrorMessage(r));
@@ -616,7 +632,7 @@ CATCH:
 }
 
 result
-_SqlDataControlImpl::Delete(const Tizen::Base::String& dataId, const Tizen::Base::String* pWhere, RequestId& reqId)
+_SqlDataControlImpl::Delete(const String& dataId, const String* pWhere, RequestId& reqId)
 {
        SysTryReturnResult(NID_APP, (__access & _DATACONTROL_ACCESS_WRITE) > 0, E_ILLEGAL_ACCESS,
                        "The DELETE query is not permitted by DataControl provider.");
@@ -629,16 +645,20 @@ _SqlDataControlImpl::Delete(const Tizen::Base::String& dataId, const Tizen::Base
        pArgList->Construct();
 
        pArgList->Add(*(new String(dataId))); // list(0): data ID
+       long long argSize = dataId.GetLength() * sizeof(wchar_t);
 
        if (pWhere != null)     // list(1): where clause
        {
                pArgList->Add(*(new String(*pWhere)));
+               argSize += pWhere->GetLength() * sizeof(wchar_t);
                SysLog(NID_APP, "[DC_CALLER] pWhere: %ls", pWhere->GetPointer());
        }
        else
        {
                pArgList->Add(*(new String(L"NULL")));
        }
+       SysTryCatch(NID_APP, argSize <= _MAX_ARGUMENT_SIZE, r = E_MAX_EXCEEDED, E_MAX_EXCEEDED,
+                       "[E_MAX_EXCEEDED] The size of sending argument (%d) exceeds the maximum limit.", argSize);
 
        r = StartSqlDataControl(_DATACONTROL_REQUEST_TYPE_SQL_DELETE, pArgList, &id);
        SysTryCatch(NID_APP, !IsFailed(r), , r, "[%s] Propagating to caller...", GetErrorMessage(r));
index 6439fa7..87590d4 100644 (file)
@@ -77,7 +77,7 @@ private:
        _SqlDataControlImpl(void);
 
        static SqlDataControl* CreateSqlDataControl(const Tizen::Base::String& appId, const Tizen::Base::String& providerId,
-            const Tizen::Base::String& access);
+                       const Tizen::Base::String& access);
 
        result StartSqlDataControl(int type, const Tizen::Base::Collection::IList* pDataList, int* pReq);