[Non-ACR][Preventing SQL Injection Attack] 95/180095/1
authorAbhishek Vijay <abhishek.v@samsung.com>
Thu, 24 May 2018 15:53:21 +0000 (21:23 +0530)
committerAbhishek Vijay <abhishek.v@samsung.com>
Thu, 24 May 2018 15:53:21 +0000 (21:23 +0530)
Change-Id: I174d9983dc54cde93e32c87d04d600a0830b8f7e
Signed-off-by: Abhishek Vijay <abhishek.v@samsung.com>
include/private/AppHistoryTypes.h
src/server/usage-stats/InstallMonitor.cpp
src/server/usage-stats/InstallMonitor.h

index 95a64e6..b6615b2 100644 (file)
 #define VAL_ALERTING   VAL_CONNECTING
 #define VAL_INCOMING   VAL_CONNECTING
 
-
 #define COLUMN_NAME_DELIMITER ","
 
+#define APPHISTORY_SQL_LEN_MAX                 256
+#define APPHISTORY_SNPRINTF(dest, size, format, arg...)\
+       do {\
+               snprintf(dest, size-1, format, ##arg);\
+       } while (0)
+
 #endif
index eda93cf..10ef7b4 100644 (file)
@@ -80,23 +80,38 @@ void ctx::AppInstallMonitor::__packageEventCb(const char *type, const char *pack
 bool ctx::AppInstallMonitor::__appInfoCb(package_info_app_component_type_e compType, const char *appId, void *userData)
 {
        Database* database = DatabaseManager::getInstance();
+       int count = 1;
 
        if (__lastEventType == PACKAGE_MANAGER_EVENT_TYPE_INSTALL) {
-               std::stringstream query;
-               query << "INSERT INTO " APP_TABLE_REMOVABLE_APP " (" KEY_APP_ID ") VALUES ('" << appId << "')";
-               database->execute(query.str(), NULL);
+               apphistory_stmt hstmt = NULL;
+               char query[APPHISTORY_SQL_LEN_MAX] = {0, };
+
+               APPHISTORY_SNPRINTF(query, sizeof(query), "INSERT INTO %s(AppId) VALUES " "(?) ", APP_TABLE_REMOVABLE_APP);
+
+               hstmt = database->prepare_query(query);
+               database->query_bind_text(hstmt, count, appId);
+               database->execute(hstmt);
+
        } else if (__lastEventType == PACKAGE_MANAGER_EVENT_TYPE_UNINSTALL) {
-               database->execute(__createDeletionQuery(APP_TABLE_REMOVABLE_APP, appId), NULL);
-               database->execute(__createDeletionQuery(APP_TABLE_USAGE_LOG, appId), NULL);
+               database->execute(__createDeletionQuery(APP_TABLE_REMOVABLE_APP, appId));
+               database->execute(__createDeletionQuery(APP_TABLE_USAGE_LOG, appId));
        }
 
        return true;
 }
 
-std::string ctx::AppInstallMonitor::__createDeletionQuery(const char* tableName, const char* appId)
+apphistory_stmt ctx::AppInstallMonitor::__createDeletionQuery(const char* tableName, const char* appId)
 {
-       std::stringstream query;
-       query << "DELETE FROM " << tableName;
-       query << " WHERE " KEY_APP_ID " = '" << appId << "'";
-       return query.str();
+       Database *database = DatabaseManager::getInstance();
+       int count = 1;
+
+       apphistory_stmt hstmt = NULL;
+       char query[APPHISTORY_SQL_LEN_MAX] = {0, };
+
+       APPHISTORY_SNPRINTF(query, sizeof(query), "DELETE FROM %s(AppId) WHERE KEY_APP_ID = ? ", tableName);
+
+       hstmt = database->prepare_query(query);
+       database->query_bind_text(hstmt, count, appId);
+       return hstmt;
 }
+
index 123868f..94fbac6 100644 (file)
@@ -19,6 +19,9 @@
 
 #include <string>
 #include <package_manager.h>
+#include <sqlite3.h>
+
+typedef sqlite3_stmt*  apphistory_stmt;
 
 namespace ctx {
 
@@ -29,8 +32,9 @@ namespace ctx {
                bool __startMonitoring();
                void __stopMonitoring();
 
-               static std::string __createDeletionQuery(const char* tableName, const char* appId);
-               static void __packageEventCb(const char *type, const char *package, package_manager_event_type_e eventType, package_manager_event_state_e eventState, int progress, package_manager_error_e error, void *userData);
+               static apphistory_stmt __createDeletionQuery(const char* tableName, const char* appId);
+               static void __packageEventCb(const char *type, const char *package, package_manager_event_type_e eventType,
+                               package_manager_event_state_e eventState, int progress, package_manager_error_e error, void *userData);
                static bool __appInfoCb(package_info_app_component_type_e compType, const char *appId, void *userData);
 
        public: