Check the boundaries of PID before getting PGID 77/178677/3
authorKichan Kwon <k_c.kwon@samsung.com>
Fri, 11 May 2018 07:29:15 +0000 (16:29 +0900)
committerKichan Kwon <k_c.kwon@samsung.com>
Mon, 14 May 2018 05:48:10 +0000 (14:48 +0900)
Change-Id: I6793ad4cc04c09e98d98287a9357d21738d50b4c
Signed-off-by: Kichan Kwon <k_c.kwon@samsung.com>
src/memory/memory-killer.c
src/proc-usage/proc-usage-application.c

index 1cc9870fd449a8f1c892f2a701c04d8d7bc63354..8e4c28748d1a25f1d606b7f560b3f519450f4bae 100644 (file)
@@ -74,13 +74,19 @@ static gint memory_killer_compare_func(gconstpointer a, gconstpointer b)
 static int memory_killer_get_candidates(enum memory_killer_range range, GSList **candidates)
 {
        int ret;
-       pid_t pid;
+       pid_t pid, pid_max;
        DIR *dp;
        struct dirent *de;
        struct memory_killer_candidate *candidate;
        struct procfs_pid_stat pps;
        char label[64];
 
+       ret = procfs_get_pid_max(&pid_max);
+       if (ret < 0) {
+               _E("Failed to get the maximum value of PID");
+               return ret;
+       }
+
        dp = opendir("/proc");
        if (!dp) {
                _E("Failed to open /proc : %m");
@@ -92,7 +98,15 @@ static int memory_killer_get_candidates(enum memory_killer_range range, GSList *
                        continue;
 
                pid = (pid_t)atoi(de->d_name);
-               if (pid < 1 || !getpgid(pid))
+               if (pid < 1)
+                       continue;
+
+               if (pid > pid_max) {
+                       _W("PID %u is bigger than PID_MAX(%u). Ignore it", pid, pid_max);
+                       continue;
+               }
+
+               if (getpgid(pid) == 0)
                        continue;
 
                candidate = g_new(struct memory_killer_candidate, 1);
index 77e520a8d6fcc8af529596cce7bce256bfaae090..303d65796f15e818b112cb0dec8031613195e553 100644 (file)
 GSList *proc_usage_application_get_list(void)
 {
        int ret;
-       pid_t pid;
+       pid_t pid, pid_max;
        DIR *dp;
        struct dirent *de;
        char label[64];
        GSList *applist = NULL;
        struct proc_usage_application *pua;
 
+       ret = procfs_get_pid_max(&pid_max);
+       if (ret < 0) {
+               _E("Failed to get the maximum value of PID");
+               return NULL;
+       }
+
        dp = opendir("/proc");
        if (!dp) {
                _E("Failed to open /proc : %m");
@@ -50,7 +56,15 @@ GSList *proc_usage_application_get_list(void)
                        continue;
 
                pid = (pid_t)atoi(de->d_name);
-               if (pid < 1 || !getpgid(pid))
+               if (pid < 1)
+                       continue;
+
+               if (pid > pid_max) {
+                       _W("PID %u is bigger than PID_MAX(%u). Ignore it", pid, pid_max);
+                       continue;
+               }
+
+               if (getpgid(pid) == 0)
                        continue;
 
                /* Distinguish Tizen application with checking SMACK label */