aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKlement Sekera <ksekera@cisco.com>2021-11-16 12:14:40 +0100
committerAndrew Yourtchenko <ayourtch@gmail.com>2022-01-28 15:14:45 +0000
commit15d0215b9ca91f4964ba3a5528b1f38f84aaf158 (patch)
treeda11e2920c90afcab172c71556062656f4eb3b55
parentaa9903cabfd44ed9c88d1f624a39096ff7fee37f (diff)
misc: vppctl - fix coverity warning
Calculate space left to silence coverity. Type: fix Fixes: 31f192434660 Signed-off-by: Klement Sekera <ksekera@cisco.com> Change-Id: I9cd2e91ce74444e2625bf86721a8d3e44bf6afdd
-rw-r--r--src/vpp/app/vppctl.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/src/vpp/app/vppctl.c b/src/vpp/app/vppctl.c
index de5572d6bfa..7166ce13689 100644
--- a/src/vpp/app/vppctl.c
+++ b/src/vpp/app/vppctl.c
@@ -169,7 +169,7 @@ main (int argc, char *argv[])
struct termios tio;
int efd = -1;
char *cmd = 0;
- int cmd_len = 0;
+ unsigned long cmd_len = 0;
int do_quit = 0;
int is_interactive = 0;
int acked = 1; /* counts messages from VPP; starts at 1 */
@@ -220,7 +220,7 @@ main (int argc, char *argv[])
}
if (cmd_len > 0)
{
- cmd_len++; // account for \n in the end
+ cmd_len++; // account for 0 at end
cmd = malloc (cmd_len);
if (!cmd)
{
@@ -229,10 +229,14 @@ main (int argc, char *argv[])
goto done;
}
memset (cmd, 0, cmd_len);
+ unsigned long space_left = cmd_len - 1; // reserve space for 0 at end
while (argc--)
{
- strncat (cmd, *argv++, cmd_len);
- strncat (cmd, " ", cmd_len);
+ strncat (cmd, *argv, space_left);
+ space_left -= strlen (*argv);
+ ++argv;
+ strncat (cmd, " ", space_left);
+ --space_left;
}
cmd[cmd_len - 2] = '\n';
cmd[cmd_len - 1] = 0;