tools: resource-monitor: Check validation of '-n' option argument 32/280232/3 submit/tizen/20220830.030501
authorDongwoo Lee <dwoo08.lee@samsung.com>
Thu, 25 Aug 2022 05:47:00 +0000 (14:47 +0900)
committerChanwoo Choi <cw00.choi@samsung.com>
Tue, 30 Aug 2022 02:30:32 +0000 (11:30 +0900)
Change-Id: I28dc6a85d44455043a56c49bdee824d2590757c0
Signed-off-by: Dongwoo Lee <dwoo08.lee@samsung.com>
tools/resource-monitor/resource-monitor.c

index 90dfce9..ebb64f4 100644 (file)
@@ -177,8 +177,8 @@ struct resource_data {
 struct resource_monitor_data {
        unsigned int pid;
        unsigned int ppid;
-       unsigned int secs;
-       unsigned int max;
+       int secs;
+       int max;
 
        int mon_id;
        int num_res;
@@ -562,12 +562,20 @@ int main(int argc, char *argv[])
                        g_data.ppid = atoi(argv[opt + 1]);
                } else if (!strncmp(argv[opt], "-", 1)) {
                        for (i = 1; *(argv[opt] + i); i++) {
+                               int input;
+
                                switch (*(argv[opt] + i)) {
                                case 'd':
-                                       g_data.secs = atoi(argv[opt + 1]);
+                                       input = atoi(argv[opt + 1]);
+                                       if (input < 0 || input >= INT_MAX)
+                                               break;
+                                       g_data.secs = input;
                                        break;
                                case 'n':
-                                       g_data.max = atoi(argv[opt + 1]);
+                                       input = atoi(argv[opt + 1]);
+                                       if (input < 0 || input >= INT_MAX)
+                                               break;
+                                       g_data.max = input;
                                        break;
                                case 'p':
                                        g_data.pid = atoi(argv[opt + 1]);