From: Dongwoo Lee Date: Thu, 25 Aug 2022 05:47:00 +0000 (+0900) Subject: tools: resource-monitor: Check validation of '-n' option argument X-Git-Tag: submit/tizen/20220830.030501^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=e0ddc6052379632e003bfab2b3f685695adcd259;p=platform%2Fcore%2Fsystem%2Fpass.git tools: resource-monitor: Check validation of '-n' option argument Change-Id: I28dc6a85d44455043a56c49bdee824d2590757c0 Signed-off-by: Dongwoo Lee --- diff --git a/tools/resource-monitor/resource-monitor.c b/tools/resource-monitor/resource-monitor.c index 90dfce9..ebb64f4 100644 --- a/tools/resource-monitor/resource-monitor.c +++ b/tools/resource-monitor/resource-monitor.c @@ -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]);