fix svace issue 99/111599/1
authorintae, jeon <intae.jeon@samsung.com>
Wed, 18 Jan 2017 05:58:10 +0000 (14:58 +0900)
committerintae jeon <intae.jeon@samsung.com>
Mon, 23 Jan 2017 03:47:05 +0000 (19:47 -0800)
Change-Id: Id427f1e70c9f9c1f82884b36e4fc27662e2b1e7e
Signed-off-by: intae, jeon <intae.jeon@samsung.com>
(cherry picked from commit a5c7294fc8074a9c97961e63f3c87cad250ac19c)

email-core/email-storage/email-storage.c

index a4d2293..0de3a0b 100755 (executable)
 #define UID_DEFAULT                                    0               /* UID = root */
 #define GID                                            "priv_email"    /* GID = priv_email */
 #define GID_DEFAULT                                    10901           /* GID = priv_email */
+#define MAX_GRP_BUF_SIZE (1024 * 4)
 
 /*  this define is used for query to change data (delete, insert, update) */
 #define EMSTORAGE_START_WRITE_TRANSACTION(multi_user_name, transaction_flag, error_code) \
@@ -1748,7 +1749,12 @@ INTERNAL_FUNC int emstorage_init_db(char *multi_user_name)
        gid_t email_gid = -1;
        uid_t email_uid = -1;
        struct group *gr;
+       struct group buf_group;
        struct passwd *pw;
+       struct passwd buf_passwd;
+       char buf_gr[MAX_GRP_BUF_SIZE];
+       char buf_pw[MAX_GRP_BUF_SIZE];
+       int result = 0;
 
        if (EM_SAFE_STRLEN(multi_user_name) > 0) {
                err = emcore_get_container_path(multi_user_name, &prefix_path);
@@ -1784,20 +1790,22 @@ INTERNAL_FUNC int emstorage_init_db(char *multi_user_name)
                if (ret == -1) {
                        EM_DEBUG_EXCEPTION("_xsystem failed");
                        err = EMAIL_ERROR_SYSTEM_FAILURE;
-
                }
 
-               if ((gr = getgrnam(GID)) != NULL)
+               result = getgrnam_r(GID, &buf_group, buf_gr, sizeof(buf_gr), &gr);
+               if (result == 0 && NULL != gr)
                        email_gid = gr->gr_gid;
                else
                        email_gid = GID_DEFAULT;
 
 
-               if ((pw = getpwnam(UID)) != NULL)
+               result = getpwnam_r(UID, &buf_passwd, buf_pw, sizeof(buf_pw), &pw);
+               if (result == 0 && NULL != pw)
                        email_uid = pw->pw_uid;
                else
                        email_uid = UID_DEFAULT;
 
+
                chmod(EMAIL_SERVICE_DB_FILE_PATH, 0660);
                chmod(EMAIL_SERVICE_DB_JOURNAL_FILE_PATH, 0660);
                chmod(EMAIL_SQL_PATH, 0660);