Coverity fixes. 77/155477/2
authorINSUN PYO <insun.pyo@samsung.com>
Fri, 13 Oct 2017 08:00:24 +0000 (08:00 +0000)
committerINSUN PYO <insun.pyo@samsung.com>
Fri, 13 Oct 2017 08:04:18 +0000 (08:04 +0000)
Signed-off-by: INSUN PYO <insun.pyo@samsung.com>
Change-Id: I4c97fe67a8d4771b0e0fc8ca56e7b7d235f334aa

src/common/tlm-utils.c
src/plugins/default/tlm-account-plugin-default.c

index 0bea3b6..db4340f 100755 (executable)
@@ -64,9 +64,12 @@ tlm_user_get_name (uid_t user_id)
     struct passwd *pwent = NULL;
     struct passwd buf_pwent;
     gchar *buf = NULL, *tmp = NULL, *pw_name = NULL;
     struct passwd *pwent = NULL;
     struct passwd buf_pwent;
     gchar *buf = NULL, *tmp = NULL, *pw_name = NULL;
-    gsize size = sysconf(_SC_GETPW_R_SIZE_MAX);
-    if (size <= sizeof(struct passwd))
+    gsize size;
+    glong pw_size_max = sysconf(_SC_GETPW_R_SIZE_MAX);
+    if (pw_size_max <= sizeof(struct passwd))
         size = 1024;
         size = 1024;
+    else
+        size = pw_size_max;
 
     for (; NULL != (tmp = realloc(buf, size)); size*=2)
     {
 
     for (; NULL != (tmp = realloc(buf, size)); size*=2)
     {
@@ -101,9 +104,12 @@ tlm_user_get_uid (const gchar *username)
     __uid_t pw_uid = -1;
     int ret = -1;
     gchar *buf = NULL, *tmp = NULL;
     __uid_t pw_uid = -1;
     int ret = -1;
     gchar *buf = NULL, *tmp = NULL;
-    gsize size = sysconf(_SC_GETPW_R_SIZE_MAX);
-    if (size < sizeof(struct passwd))
+    gsize size;
+    glong pw_size_max = sysconf(_SC_GETPW_R_SIZE_MAX);
+    if (pw_size_max <= sizeof(struct passwd))
         size = 1024;
         size = 1024;
+    else
+        size = pw_size_max;
 
     for (; NULL != (tmp = realloc(buf, size)); size*=2)
     {
 
     for (; NULL != (tmp = realloc(buf, size)); size*=2)
     {
@@ -134,9 +140,12 @@ tlm_user_get_gid (const gchar *username)
     __gid_t pw_gid = -1;
     int ret = -1;
     gchar *buf = NULL, *tmp = NULL;
     __gid_t pw_gid = -1;
     int ret = -1;
     gchar *buf = NULL, *tmp = NULL;
-    gsize size = sysconf(_SC_GETPW_R_SIZE_MAX);
-    if (size <= sizeof(struct passwd))
+    gsize size;
+    glong pw_size_max = sysconf(_SC_GETPW_R_SIZE_MAX);
+    if (pw_size_max <= sizeof(struct passwd))
         size = 1024;
         size = 1024;
+    else
+        size = pw_size_max;
 
     for (; NULL != (tmp = realloc(buf, size)); size*=2)
     {
 
     for (; NULL != (tmp = realloc(buf, size)); size*=2)
     {
@@ -165,9 +174,12 @@ tlm_user_get_home_dir (const gchar *username)
     struct passwd *pwent = NULL;
     struct passwd buf_pwent;
     gchar *buf = NULL, *tmp = NULL, *pw_dir = NULL;
     struct passwd *pwent = NULL;
     struct passwd buf_pwent;
     gchar *buf = NULL, *tmp = NULL, *pw_dir = NULL;
-    gsize size = sysconf(_SC_GETPW_R_SIZE_MAX);
-    if (size <= sizeof(struct passwd))
+    gsize size;
+    glong pw_size_max = sysconf(_SC_GETPW_R_SIZE_MAX);
+    if (pw_size_max <= sizeof(struct passwd))
         size = 1024;
         size = 1024;
+    else
+        size = pw_size_max;
 
     for (; NULL != (tmp = realloc(buf, size)); size*=2)
     {
 
     for (; NULL != (tmp = realloc(buf, size)); size*=2)
     {
@@ -200,9 +212,12 @@ tlm_user_get_shell (const gchar *username)
     struct passwd *pwent = NULL;
     struct passwd buf_pwent;
     gchar *buf = NULL, *tmp = NULL, *pw_shell = NULL;
     struct passwd *pwent = NULL;
     struct passwd buf_pwent;
     gchar *buf = NULL, *tmp = NULL, *pw_shell = NULL;
-    gsize size = sysconf(_SC_GETPW_R_SIZE_MAX);
-    if (size <= sizeof(struct passwd))
+    gsize size;
+    glong pw_size_max = sysconf(_SC_GETPW_R_SIZE_MAX);
+    if (pw_size_max <= sizeof(struct passwd))
         size = 1024;
         size = 1024;
+    else
+        size = pw_size_max;
 
     for (; NULL != (tmp = realloc(buf, size)); size*=2)
     {
 
     for (; NULL != (tmp = realloc(buf, size)); size*=2)
     {
index ce54b05..be4c6b2 100755 (executable)
@@ -181,10 +181,12 @@ _cleanup_guest_user (TlmAccountPlugin *plugin,
     struct passwd buf_pwd;
     gboolean res;
     gchar *buf = NULL, *tmp = NULL;
     struct passwd buf_pwd;
     gboolean res;
     gchar *buf = NULL, *tmp = NULL;
-
-    gsize size = sysconf(_SC_GETPW_R_SIZE_MAX);
-    if (size < sizeof(struct passwd))
+    gsize size;
+    glong pw_size_max = sysconf(_SC_GETPW_R_SIZE_MAX);
+    if (pw_size_max <= sizeof(struct passwd))
         size = 1024;
         size = 1024;
+    else
+        size = pw_size_max;
 
     (void) delete;
 
 
     (void) delete;
 
@@ -237,9 +239,12 @@ _is_valid_user (TlmAccountPlugin *plugin, const gchar *user_name)
     struct passwd *pwd_entry = NULL;
     struct passwd pwd_buf;
     gchar *buf = NULL, *tmp = NULL;
     struct passwd *pwd_entry = NULL;
     struct passwd pwd_buf;
     gchar *buf = NULL, *tmp = NULL;
-    gsize size = sysconf(_SC_GETPW_R_SIZE_MAX);
-    if (size < sizeof(struct passwd))
+    gsize size;
+    glong pw_size_max = sysconf(_SC_GETPW_R_SIZE_MAX);
+    if (pw_size_max <= sizeof(struct passwd))
         size = 1024;
         size = 1024;
+    else
+        size = pw_size_max;
 
     g_return_val_if_fail (plugin, FALSE);
     g_return_val_if_fail (TLM_IS_ACCOUNT_PLUGIN_DEFAULT(plugin), FALSE);
 
     g_return_val_if_fail (plugin, FALSE);
     g_return_val_if_fail (TLM_IS_ACCOUNT_PLUGIN_DEFAULT(plugin), FALSE);