diff options
author | 2020-04-04 18:34:41 -0400 | |
---|---|---|
committer | 2020-08-13 17:20:47 +0000 | |
commit | 3d57cfdfb529c61fa5ec6e8a04db4ef042e7eb45 (patch) | |
tree | 147a67aa183dd1f961c2dd56b926c447e43f198b /src/plugins | |
parent | d13034a6d1a239af07948ebe6a399c6aec5ddbbc (diff) |
misc: strcpy be gone
Causes static analysis "vulnerability" warnings
Type: fix
Ticket: VPP-1837
Signed-off-by: Dave Barach <dave@barachs.net>
Change-Id: I272fa69251d70f62178e6dff0423c16f99937af1
(cherry picked from commit 0250090fc0c24214cb1fa969f6e2f585099ee36b)
Diffstat (limited to 'src/plugins')
-rw-r--r-- | src/plugins/hs_apps/vcl/sock_test_client.c | 7 | ||||
-rw-r--r-- | src/plugins/hs_apps/vcl/sock_test_server.c | 3 | ||||
-rw-r--r-- | src/plugins/hs_apps/vcl/vcl_test_client.c | 2 | ||||
-rw-r--r-- | src/plugins/unittest/string_test.c | 2 |
4 files changed, 8 insertions, 6 deletions
diff --git a/src/plugins/hs_apps/vcl/sock_test_client.c b/src/plugins/hs_apps/vcl/sock_test_client.c index 6f5fb074503..fb59378e008 100644 --- a/src/plugins/hs_apps/vcl/sock_test_client.c +++ b/src/plugins/hs_apps/vcl/sock_test_client.c @@ -252,7 +252,8 @@ echo_test_client () } memset (&serveraddr, 0, sizeof (serveraddr)); serveraddr.sun_family = AF_UNIX; - strcpy (serveraddr.sun_path, SOCK_TEST_AF_UNIX_FILENAME); + strncpy (serveraddr.sun_path, SOCK_TEST_AF_UNIX_FILENAME, + sizeof (serveraddr.sun_path)); rv = connect (fd, (struct sockaddr *) &serveraddr, SUN_LEN (&serveraddr)); if (rv < 0) { @@ -265,7 +266,7 @@ echo_test_client () } scm->af_unix_echo_tx++; - strcpy ((char *) buffer, SOCK_TEST_MIXED_EPOLL_DATA); + strncpy ((char *) buffer, SOCK_TEST_MIXED_EPOLL_DATA, sizeof (buffer)); timeout.tv_sec = 0; timeout.tv_usec = 250000; select (0, NULL, NULL, NULL, &timeout); /* delay .25 secs */ @@ -946,7 +947,7 @@ main (int argc, char **argv) optopt, ctrl->txbuf_size); print_usage_and_exit (); } - strcpy (ctrl->txbuf, optarg); + strncpy (ctrl->txbuf, optarg, ctrl->txbuf_size); ctrl->cfg.test = VCL_TEST_TYPE_ECHO; break; diff --git a/src/plugins/hs_apps/vcl/sock_test_server.c b/src/plugins/hs_apps/vcl/sock_test_server.c index bd777ccb917..801cd83cc83 100644 --- a/src/plugins/hs_apps/vcl/sock_test_server.c +++ b/src/plugins/hs_apps/vcl/sock_test_server.c @@ -559,7 +559,8 @@ main (int argc, char **argv) memset (&ssm->serveraddr, 0, sizeof (ssm->serveraddr)); ssm->serveraddr.sun_family = AF_UNIX; - strcpy (ssm->serveraddr.sun_path, SOCK_TEST_AF_UNIX_FILENAME); + strncpy (ssm->serveraddr.sun_path, SOCK_TEST_AF_UNIX_FILENAME, + sizeof (ssm->serveraddr.sun_path)); rv = bind (ssm->af_unix_listen_fd, (struct sockaddr *) &ssm->serveraddr, SUN_LEN (&ssm->serveraddr)); diff --git a/src/plugins/hs_apps/vcl/vcl_test_client.c b/src/plugins/hs_apps/vcl/vcl_test_client.c index 30b48d8d145..236cbfff913 100644 --- a/src/plugins/hs_apps/vcl/vcl_test_client.c +++ b/src/plugins/hs_apps/vcl/vcl_test_client.c @@ -912,7 +912,7 @@ vtc_process_opts (vcl_test_client_main_t * vcm, int argc, char **argv) optopt, ctrl->txbuf_size); print_usage_and_exit (); } - strcpy (ctrl->txbuf, optarg); + strncpy (ctrl->txbuf, optarg, ctrl->txbuf_size); ctrl->cfg.test = VCL_TEST_TYPE_ECHO; break; diff --git a/src/plugins/unittest/string_test.c b/src/plugins/unittest/string_test.c index 95a95d78c1d..fb33edb2f43 100644 --- a/src/plugins/unittest/string_test.c +++ b/src/plugins/unittest/string_test.c @@ -594,7 +594,7 @@ test_clib_strcpy (vlib_main_t * vm, unformat_input_t * input) return -1; /* verify it against strcpy */ - strcpy (dst, src); + strcpy (dst, src); //NOSONAR /* This better not fail but check anyhow */ if (strcmp_s (dst, clib_strnlen (dst, sizeof (dst)), src, &indicator) != |