Fix coverity issue 38/294938/1
authorYoungjae Cho <y0.cho@samsung.com>
Thu, 29 Jun 2023 04:17:27 +0000 (13:17 +0900)
committerYoungjae Cho <y0.cho@samsung.com>
Thu, 29 Jun 2023 04:33:04 +0000 (13:33 +0900)
When comparing operands that containing sizeof operator, both are taken
as unsigned. Therefore if an operand was -1, which might be a value of
error return, it is interpreted as unsigned value such as 4294967295
when it is compared with another operand, sizeof value. Make both
operands be signed by casting sizeof value into glong.

Change-Id: I116c507f50ad93f7b699c2524868e3c72979c376
Signed-off-by: Youngjae Cho <y0.cho@samsung.com>
src/common/tlm-utils.c
src/plugins/default/tlm-account-plugin-default.c

index b496882..96fc0f3 100755 (executable)
@@ -58,7 +58,7 @@ tlm_user_get_name (uid_t user_id)
     gchar *buf = NULL, *tmp = NULL, *pw_name = NULL;
     gsize size;
     glong pw_size_max = sysconf(_SC_GETPW_R_SIZE_MAX);
-    if (pw_size_max <= sizeof(struct passwd))
+    if (pw_size_max <= (glong) sizeof(struct passwd))
         size = 1024;
     else
         size = pw_size_max;
@@ -98,7 +98,7 @@ tlm_user_get_uid (const gchar *username)
     gchar *buf = NULL, *tmp = NULL;
     gsize size;
     glong pw_size_max = sysconf(_SC_GETPW_R_SIZE_MAX);
-    if (pw_size_max <= sizeof(struct passwd))
+    if (pw_size_max <= (glong) sizeof(struct passwd))
         size = 1024;
     else
         size = pw_size_max;
@@ -134,7 +134,7 @@ tlm_user_get_gid (const gchar *username)
     gchar *buf = NULL, *tmp = NULL;
     gsize size;
     glong pw_size_max = sysconf(_SC_GETPW_R_SIZE_MAX);
-    if (pw_size_max <= sizeof(struct passwd))
+    if (pw_size_max <= (glong) sizeof(struct passwd))
         size = 1024;
     else
         size = pw_size_max;
@@ -168,7 +168,7 @@ tlm_user_get_home_dir (const gchar *username)
     gchar *buf = NULL, *tmp = NULL, *pw_dir = NULL;
     gsize size;
     glong pw_size_max = sysconf(_SC_GETPW_R_SIZE_MAX);
-    if (pw_size_max <= sizeof(struct passwd))
+    if (pw_size_max <= (glong) sizeof(struct passwd))
         size = 1024;
     else
         size = pw_size_max;
@@ -206,7 +206,7 @@ tlm_user_get_shell (const gchar *username)
     gchar *buf = NULL, *tmp = NULL, *pw_shell = NULL;
     gsize size;
     glong pw_size_max = sysconf(_SC_GETPW_R_SIZE_MAX);
-    if (pw_size_max <= sizeof(struct passwd))
+    if (pw_size_max <= (glong) sizeof(struct passwd))
         size = 1024;
     else
         size = pw_size_max;
index 6207d2a..672c63b 100755 (executable)
@@ -187,7 +187,7 @@ _cleanup_guest_user (TlmAccountPlugin *plugin,
     gchar *buf = NULL, *tmp = NULL;
     gsize size;
     glong pw_size_max = sysconf(_SC_GETPW_R_SIZE_MAX);
-    if (pw_size_max <= sizeof(struct passwd))
+    if (pw_size_max <= (glong) sizeof(struct passwd))
         size = 1024;
     else
         size = pw_size_max;
@@ -245,7 +245,7 @@ _is_valid_user (TlmAccountPlugin *plugin, const gchar *user_name)
     gchar *buf = NULL, *tmp = NULL;
     gsize size;
     glong pw_size_max = sysconf(_SC_GETPW_R_SIZE_MAX);
-    if (pw_size_max <= sizeof(struct passwd))
+    if (pw_size_max <= (glong) sizeof(struct passwd))
         size = 1024;
     else
         size = pw_size_max;