[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20211111093323.5129-1-15720603159@163.com>
Date: Thu, 11 Nov 2021 17:33:23 +0800
From: 15720603159@....com
To: netdev@...r.kernel.org
Cc: jinag <jinag12138@...il.com>
Subject: [PATCH iproute2] bridge: use strtoi instead of atoi for checking value of cost/priority
From: jinag <jinag12138@...il.com>
Signed-off-by: jinag <jinag12138@...il.com>
---
bridge/link.c | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)
diff --git a/bridge/link.c b/bridge/link.c
index 205a2fe7..d60e1106 100644
--- a/bridge/link.c
+++ b/bridge/link.c
@@ -308,13 +308,14 @@ static int brlink_modify(int argc, char **argv)
__s8 bpdu_guard = -1;
__s8 fast_leave = -1;
__s8 root_block = -1;
- __u32 cost = 0;
+ __s32 cost = 0;
__s16 priority = -1;
__s8 state = -1;
__s16 mode = -1;
__u16 flags = 0;
struct rtattr *nest;
int ret;
+ char *end = NULL;
while (argc > 0) {
if (strcmp(*argv, "dev") == 0) {
@@ -367,10 +368,19 @@ static int brlink_modify(int argc, char **argv)
return ret;
} else if (strcmp(*argv, "cost") == 0) {
NEXT_ARG();
- cost = atoi(*argv);
+ cost = strtoul(*argv, &end, 10);
+ if ((cost <= 0) || (end == NULL) || (*end != '\0')) {
+ fprintf(stderr, "Error: invalid cost value\n");
+ return -1;
+ }
} else if (strcmp(*argv, "priority") == 0) {
NEXT_ARG();
priority = atoi(*argv);
+ priority = strtol(*argv, &end, 10);
+ if ((priority < 0) || (end == NULL) || (*end != '\0')) {
+ fprintf(stderr, "Error: invalid priority\n");
+ return -1;
+ }
} else if (strcmp(*argv, "state") == 0) {
NEXT_ARG();
char *endptr;
--
2.30.0
Powered by blists - more mailing lists