From 0d1c6716a698093b1c257742f121dcdb1381c0f6 Mon Sep 17 00:00:00 2001 From: "Huawei Technologies Co., Ltd" Date: Sat, 27 Feb 2021 14:23:13 +0800 Subject: [PATCH 1/5] input: add invalid opt check in input Add invalid opt check while vmtop start with opts. Signed-off-by: nocjj <1250062498@qq.com> --- input-add-invalid-opt-check-in-input.patch | 97 ++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 input-add-invalid-opt-check-in-input.patch diff --git a/input-add-invalid-opt-check-in-input.patch b/input-add-invalid-opt-check-in-input.patch new file mode 100644 index 0000000..61c465f --- /dev/null +++ b/input-add-invalid-opt-check-in-input.patch @@ -0,0 +1,97 @@ +From 4cddb3a35907a5d8bdc5af3d92c2dae1e02eafa8 Mon Sep 17 00:00:00 2001 +From: nocjj <1250062498@qq.com> +Date: Sat, 27 Feb 2021 14:23:13 +0800 +Subject: [PATCH] input: add invalid opt check in input + +Add invalid opt check while vmtop start with opts. + +Signed-off-by: nocjj <1250062498@qq.com> +--- + src/utils.c | 19 +++++++++++++++++++ + src/utils.h | 1 + + src/vmtop.c | 17 ++++++++++------- + 3 files changed, 30 insertions(+), 7 deletions(-) + +diff --git a/src/utils.c b/src/utils.c +index 3cb1146..4b6983a 100644 +--- a/src/utils.c ++++ b/src/utils.c +@@ -56,3 +56,22 @@ int get_time_str(char *buf, int bufsize) + } + return 1; + } ++ ++int str_to_int(const char *str) ++{ ++ long int sl; ++ char *end = NULL; ++ int ret = -1; ++ ++ sl = strtol(str, &end, 10); ++ /* if str starts or ends with non numeric char */ ++ if ((end == str) || (*end != '\0')) { ++ printf("Invalid data!\n"); ++ } else if ((sl > INT_MAX) || (sl < INT_MIN)) { ++ printf("Out of range!\n"); ++ } else { ++ ret = (int)sl; ++ } ++ ++ return ret; ++} +diff --git a/src/utils.h b/src/utils.h +index 11d3001..c8d0d01 100644 +--- a/src/utils.h ++++ b/src/utils.h +@@ -15,5 +15,6 @@ + + int read_file(char *buf, int bufsize, const char *path); + int get_time_str(char *buf, int bufsize); ++int str_to_int(const char *str); + + #endif +diff --git a/src/vmtop.c b/src/vmtop.c +index f5fd4bd..4f45bef 100644 +--- a/src/vmtop.c ++++ b/src/vmtop.c +@@ -76,9 +76,9 @@ static void parse_args(int argc, char *argv[]) + while ((opt = getopt(argc, argv, arg_ops)) != -1) { + switch (opt) { + case 'd': { +- delay_time = atoi(optarg); +- if (delay_time < 1) { +- delay_time = 1; ++ delay_time = str_to_int(optarg); ++ if (delay_time < 0) { ++ exit(1); + } + break; + } +@@ -95,9 +95,9 @@ static void parse_args(int argc, char *argv[]) + exit(0); + } + case 'n': { +- display_loop = atoi(optarg); +- if (display_loop == 0) { +- display_loop = -1; ++ display_loop = str_to_int(optarg); ++ if (display_loop < 0) { ++ exit(1); + } + break; + } +@@ -106,7 +106,10 @@ static void parse_args(int argc, char *argv[]) + break; + } + case 'p': { +- monitor_id = atoi(optarg); ++ monitor_id = str_to_int(optarg); ++ if (monitor_id < 0) { ++ exit(1); ++ } + break; + } + default: +-- +2.27.0 + -- Gitee From a9aa9bb3a294d7e6a8d09c98a3cada72a65f7e74 Mon Sep 17 00:00:00 2001 From: Euler Robot Date: Tue, 2 Mar 2021 16:57:22 +0800 Subject: [PATCH 2/5] spec: Update patch and changelog with !21 input: add invalid opt check in input Signed-off-by: nocjj <1250062498@qq.com> --- vmtop.spec | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/vmtop.spec b/vmtop.spec index e557e19..5b08afa 100644 --- a/vmtop.spec +++ b/vmtop.spec @@ -28,6 +28,7 @@ Patch0017: display-del-screen-clear-after-key-response.patch Patch0018: arch-add-x86-kvm-exits-items.patch Patch0019: codestyle-del-unused-var.patch Patch0020: bugfix-add-check-to-avoid-invalid-ptr-for-strcmp.patch +Patch0021: input-add-invalid-opt-check-in-input.patch Requires: libvirt, ncurses @@ -68,6 +69,9 @@ install -m 550 vmtop ${RPM_BUILD_ROOT}/usr/bin/%{name} %{_bindir}/vmtop %changelog +* Sat Feb 27 2021 Huawei Technologies Co., Ltd +- input: add invalid opt check in input + * Thu Jan 21 2021 Huawei Technologies Co., Ltd - bugfix: add check to avoid invalid ptr for strcmp -- Gitee From 228dea6049425792e7e4d4629776398709a12c77 Mon Sep 17 00:00:00 2001 From: "Huawei Technologies Co., Ltd" Date: Sat, 27 Feb 2021 14:27:31 +0800 Subject: [PATCH 3/5] version: unified with release version Currently, vmtop release version has been update to 1.1, but version in configure.ac is still 1.0. So, update release version to configure.ac. Signed-off-by: nocjj <1250062498@qq.com> --- version-unified-with-release-version.patch | 30 ++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 version-unified-with-release-version.patch diff --git a/version-unified-with-release-version.patch b/version-unified-with-release-version.patch new file mode 100644 index 0000000..8f6fadb --- /dev/null +++ b/version-unified-with-release-version.patch @@ -0,0 +1,30 @@ +From 76f5626a69007a2f3509bb29548e7cd305699fb0 Mon Sep 17 00:00:00 2001 +From: nocjj <1250062498@qq.com> +Date: Sat, 27 Feb 2021 14:27:31 +0800 +Subject: [PATCH] version: unified with release version + +Currently, vmtop release version has been update to 1.1, but +version in configure.ac is still 1.0. So, update release +version to configure.ac. + +Signed-off-by: nocjj <1250062498@qq.com> +--- + configure.ac | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/configure.ac b/configure.ac +index a968ae8..0acb1b7 100644 +--- a/configure.ac ++++ b/configure.ac +@@ -2,7 +2,7 @@ + # Process this file with autoconf to produce a configure script. + + AC_PREREQ([2.69]) +-AC_INIT([vmtop], [1.0], [virt@openeuler.org]) ++AC_INIT([vmtop], [1.1], [virt@openeuler.org]) + AC_CONFIG_SRCDIR([src/vmtop.c]) + AC_CONFIG_HEADERS([config.h]) + +-- +2.27.0 + -- Gitee From 4a64e95873fd108f5d9f24867111c4e98a935f90 Mon Sep 17 00:00:00 2001 From: Euler Robot Date: Tue, 2 Mar 2021 16:57:22 +0800 Subject: [PATCH 4/5] spec: Update patch and changelog with !22 version: unified with release version Signed-off-by: nocjj <1250062498@qq.com> --- vmtop.spec | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/vmtop.spec b/vmtop.spec index 5b08afa..f9d425d 100644 --- a/vmtop.spec +++ b/vmtop.spec @@ -29,6 +29,7 @@ Patch0018: arch-add-x86-kvm-exits-items.patch Patch0019: codestyle-del-unused-var.patch Patch0020: bugfix-add-check-to-avoid-invalid-ptr-for-strcmp.patch Patch0021: input-add-invalid-opt-check-in-input.patch +Patch0022: version-unified-with-release-version.patch Requires: libvirt, ncurses @@ -69,6 +70,9 @@ install -m 550 vmtop ${RPM_BUILD_ROOT}/usr/bin/%{name} %{_bindir}/vmtop %changelog +* Sat Feb 27 2021 Huawei Technologies Co., Ltd +- version: unified with release version + * Sat Feb 27 2021 Huawei Technologies Co., Ltd - input: add invalid opt check in input -- Gitee From c8657ee99d8683db83591dd5b03a66729082e1e5 Mon Sep 17 00:00:00 2001 From: Euler Robot Date: Tue, 2 Mar 2021 16:57:22 +0800 Subject: [PATCH 5/5] spec: Update release version with !21 !22 increase release verison by one Signed-off-by: Euler Robot --- vmtop.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vmtop.spec b/vmtop.spec index f9d425d..620e22f 100644 --- a/vmtop.spec +++ b/vmtop.spec @@ -1,6 +1,6 @@ Name: vmtop Version: 1.1 -Release: 3 +Release: 4 Summary: A tool for collecting and analyzing data of virtual machine License: Mulan PSL V2 Group: Application/System -- Gitee