Use macro for length of file path 23/295623/1
authorSuyeon Hwang <stom.hwang@samsung.com>
Tue, 11 Jul 2023 05:31:48 +0000 (14:31 +0900)
committerTizen AI <ai.tzn.sec@samsung.com>
Wed, 12 Jul 2023 02:02:11 +0000 (11:02 +0900)
Change-Id: I5352069100e10540f69cb763a88a560013644920
Signed-off-by: Suyeon Hwang <stom.hwang@samsung.com>
common/vc_cmd_db.c

index 6626bd5..dff7ec0 100644 (file)
@@ -19,6 +19,7 @@
 #include <dlog.h>
 #include <sqlite3.h>
 #include <tzplatform_config.h>
+#include <limits.h>
 
 #include "vc_cmd_db.h"
 #include "vc_main.h"
@@ -58,8 +59,8 @@ const char* vc_db_tag()
 //#define DB_PATH tzplatform_mkpath(TZ_USER_DB, ".vc_info.db")
 static sqlite3* g_db_handle = NULL;
 static sqlite3* g_db_backup_handle = NULL;
-static char g_path[256] = {0, };
-static char g_backup_path[256] = {0, };
+static char g_path[_POSIX_PATH_MAX] = {0, };
+static char g_backup_path[_POSIX_PATH_MAX] = {0, };
 static int g_ref_cnt = 0;
 
 int g_fpid = -1;
@@ -1613,7 +1614,7 @@ static int __vc_db_integrity_check_cb(void *NotUsed, int argc, char **argv, char
                if (0 != remove(g_path)) {
                        SLOG(LOG_ERROR, vc_db_tag(), "[Error] remove file(%s) is failed for daemon", g_path);
                        g_db_cnt = (g_db_cnt + 1) % 1000;
-                       snprintf(g_path, 256, "%s/.vc_info_%d.db", VC_RUNTIME_INFO_ROOT, g_db_cnt);
+                       snprintf(g_path, _POSIX_PATH_MAX, "%s/.vc_info_%d.db", VC_RUNTIME_INFO_ROOT, g_db_cnt);
                }
                bool is_connect = __vc_db_connect_db_for_daemon(g_path, &g_db_handle);
                if (true == is_connect) {
@@ -1654,10 +1655,10 @@ int vc_db_initialize_for_daemon(void)
 
        /* For voice control DB */
        /* This should be changed to general DB space - TZ_USER_DB */
-       snprintf(g_path, 256, "%s/.vc_info.db", VC_RUNTIME_INFO_ROOT);
+       snprintf(g_path, _POSIX_PATH_MAX, "%s/.vc_info.db", VC_RUNTIME_INFO_ROOT);
 
        /* For Backup DB */
-       snprintf(g_backup_path, 256, "%s/.vc_backup.db", VC_RUNTIME_INFO_ROOT);
+       snprintf(g_backup_path, _POSIX_PATH_MAX, "%s/.vc_backup.db", VC_RUNTIME_INFO_ROOT);
 
        bool is_connect = __vc_db_connect_db_for_daemon(g_path, &g_db_handle);
        if (false == is_connect) {
@@ -1665,7 +1666,7 @@ int vc_db_initialize_for_daemon(void)
                if (0 != remove(g_path)) {
                        SLOG(LOG_ERROR, vc_db_tag(), "[Error] remove file(%s) is failed for daemon", g_path);
                        g_db_cnt = (g_db_cnt + 1) % 1000;
-                       snprintf(g_path, 256, "%s/.vc_info_%d.db", VC_RUNTIME_INFO_ROOT, g_db_cnt);
+                       snprintf(g_path, _POSIX_PATH_MAX, "%s/.vc_info_%d.db", VC_RUNTIME_INFO_ROOT, g_db_cnt);
                }
                is_connect = __vc_db_connect_db_for_daemon(g_path, &g_db_handle);
                if (true == is_connect) {
@@ -1696,7 +1697,7 @@ int vc_db_initialize_for_daemon(void)
                if (0 != remove(g_path)) {
                        SLOG(LOG_ERROR, vc_db_tag(), "[Error] remove file(%s) is failed for daemon", g_path);
                        g_db_cnt = (g_db_cnt + 1) % 1000;
-                       snprintf(g_path, 256, "%s/.vc_info_%d.db", VC_RUNTIME_INFO_ROOT, g_db_cnt);
+                       snprintf(g_path, _POSIX_PATH_MAX, "%s/.vc_info_%d.db", VC_RUNTIME_INFO_ROOT, g_db_cnt);
                }
                is_connect = __vc_db_connect_db_for_daemon(g_path, &g_db_handle);
                if (true == is_connect) {
@@ -1724,7 +1725,7 @@ int vc_db_initialize_for_daemon(void)
                if (0 != remove(g_backup_path)) {
                        g_backup_db_cnt = (g_backup_db_cnt + 1) % 1000;
                        SLOG(LOG_ERROR, vc_db_tag(), "[Error] remove file(%s) is failed", g_backup_path);
-                       snprintf(g_backup_path, 256, "%s/.vc_backup_%d.db", VC_RUNTIME_INFO_ROOT, g_backup_db_cnt);
+                       snprintf(g_backup_path, _POSIX_PATH_MAX, "%s/.vc_backup_%d.db", VC_RUNTIME_INFO_ROOT, g_backup_db_cnt);
                }
                is_connect = __vc_db_connect_db_for_daemon(g_path, &g_db_backup_handle);
                if (true == is_connect) {
@@ -1792,10 +1793,10 @@ int vc_db_initialize(void)
 
        /* For voice control DB */
        /* This should be changed to general DB space - TZ_USER_DB */
-       snprintf(g_path, 256, "%s/.vc_info.db", VC_RUNTIME_INFO_ROOT);
+       snprintf(g_path, _POSIX_PATH_MAX, "%s/.vc_info.db", VC_RUNTIME_INFO_ROOT);
 
        /* For Backup DB */
-       snprintf(g_backup_path, 256, "%s/.vc_backup.db", VC_RUNTIME_INFO_ROOT);
+       snprintf(g_backup_path, _POSIX_PATH_MAX, "%s/.vc_backup.db", VC_RUNTIME_INFO_ROOT);
 
        bool is_connect = __vc_db_connect_db(g_path, &g_db_handle);
        if (false == is_connect) {
@@ -1803,7 +1804,7 @@ int vc_db_initialize(void)
                if (0 != remove(g_path)) {
                        SLOG(LOG_ERROR, vc_db_tag(), "[Error] remove file(%s) is failed", g_path);
                        g_db_cnt = (g_db_cnt + 1) % 1000;
-                       snprintf(g_path, 256, "%s/.vc_info_%d.db", VC_RUNTIME_INFO_ROOT, g_db_cnt);
+                       snprintf(g_path, _POSIX_PATH_MAX, "%s/.vc_info_%d.db", VC_RUNTIME_INFO_ROOT, g_db_cnt);
                }
                is_connect = __vc_db_connect_db(g_path, &g_db_handle);
                if (true == is_connect) {
@@ -1827,7 +1828,7 @@ int vc_db_initialize(void)
                if (0 != remove(g_backup_path)) {
                        g_backup_db_cnt = (g_backup_db_cnt + 1) % 1000;
                        SLOG(LOG_ERROR, vc_db_tag(), "[Error] remove file(%s) is failed", g_backup_path);
-                       snprintf(g_backup_path, 256, "%s/.vc_backup_%d.db", VC_RUNTIME_INFO_ROOT, g_backup_db_cnt);
+                       snprintf(g_backup_path, _POSIX_PATH_MAX, "%s/.vc_backup_%d.db", VC_RUNTIME_INFO_ROOT, g_backup_db_cnt);
                }
                is_connect = __vc_db_connect_db(g_path, &g_db_backup_handle);
                if (true == is_connect) {
@@ -1850,9 +1851,9 @@ int vc_db_finalize(void)
        if (0 != --g_ref_cnt)
                return VC_DB_ERROR_NONE;
 
-       memset(g_path, 0, 256);
+       memset(g_path, 0, _POSIX_PATH_MAX);
 
-       memset(g_backup_path, 0, 256);
+       memset(g_backup_path, 0, _POSIX_PATH_MAX);
 
        if (!g_db_handle)
                return VC_DB_ERROR_NONE;