summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorQuentin Young <qlyoung@cumulusnetworks.com>2019-02-26 20:34:39 +0000
committerQuentin Young <qlyoung@cumulusnetworks.com>2019-02-26 20:50:17 +0000
commit4d65d9278ef0a1cee1a396cf3bb658157f21960c (patch)
tree6347966c33e5c2df4e0c2159ccd6521f1078fc54
parenteb266ecb847b70bcf9901da5ed59a39d3e07fd8f (diff)
ospfd: strncpy -> strlcpy
strncpy is a byte copy function not a string copy function Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
-rw-r--r--ospfd/ospf_dump.c3
-rw-r--r--ospfd/ospf_vty.c23
2 files changed, 11 insertions, 15 deletions
diff --git a/ospfd/ospf_dump.c b/ospfd/ospf_dump.c
index 48d210d279..f74d9733ee 100644
--- a/ospfd/ospf_dump.c
+++ b/ospfd/ospf_dump.c
@@ -538,8 +538,7 @@ static void ospf_header_dump(struct ospf_header *ospfh)
case OSPF_AUTH_NULL:
break;
case OSPF_AUTH_SIMPLE:
- memset(buf, 0, 9);
- strncpy(buf, (char *)ospfh->u.auth_data, 8);
+ strlcpy(buf, (char *)ospfh->u.auth_data, sizeof(buf));
zlog_debug(" Simple Password %s", buf);
break;
case OSPF_AUTH_CRYPTOGRAPHIC:
diff --git a/ospfd/ospf_vty.c b/ospfd/ospf_vty.c
index c1dc1f0d6f..bb22f211a7 100644
--- a/ospfd/ospf_vty.c
+++ b/ospfd/ospf_vty.c
@@ -954,8 +954,9 @@ static int ospf_vl_set_security(struct ospf_vl_data *vl_data,
if (vl_config->auth_key) {
memset(IF_DEF_PARAMS(ifp)->auth_simple, 0,
OSPF_AUTH_SIMPLE_SIZE + 1);
- strncpy((char *)IF_DEF_PARAMS(ifp)->auth_simple,
- vl_config->auth_key, OSPF_AUTH_SIMPLE_SIZE);
+ strlcpy((char *)IF_DEF_PARAMS(ifp)->auth_simple,
+ vl_config->auth_key,
+ sizeof(IF_DEF_PARAMS(ifp)->auth_simple));
} else if (vl_config->md5_key) {
if (ospf_crypt_key_lookup(IF_DEF_PARAMS(ifp)->auth_crypt,
vl_config->crypto_key_id)
@@ -967,8 +968,8 @@ static int ospf_vl_set_security(struct ospf_vl_data *vl_data,
ck = ospf_crypt_key_new();
ck->key_id = vl_config->crypto_key_id;
memset(ck->auth_key, 0, OSPF_AUTH_MD5_SIZE + 1);
- strncpy((char *)ck->auth_key, vl_config->md5_key,
- OSPF_AUTH_MD5_SIZE);
+ strlcpy((char *)ck->auth_key, vl_config->md5_key,
+ sizeof(ck->auth_key));
ospf_crypt_key_add(IF_DEF_PARAMS(ifp)->auth_crypt, ck);
} else if (vl_config->crypto_key_id != 0) {
@@ -1147,14 +1148,12 @@ DEFUN (ospf_area_vlink,
if (vl_config.crypto_key_id < 0)
return CMD_WARNING_CONFIG_FAILED;
- memset(md5_key, 0, OSPF_AUTH_MD5_SIZE + 1);
- strncpy(md5_key, argv[idx + 3]->arg, OSPF_AUTH_MD5_SIZE);
+ strlcpy(md5_key, argv[idx + 3]->arg, sizeof(md5_key));
vl_config.md5_key = md5_key;
}
if (argv_find(argv, argc, "authentication-key", &idx)) {
- memset(auth_key, 0, OSPF_AUTH_SIMPLE_SIZE + 1);
- strncpy(auth_key, argv[idx + 1]->arg, OSPF_AUTH_SIMPLE_SIZE);
+ strlcpy(auth_key, argv[idx + 1]->arg, sizeof(auth_key));
vl_config.auth_key = auth_key;
}
@@ -6895,9 +6894,8 @@ DEFUN (ip_ospf_authentication_key,
ospf_if_update_params(ifp, addr);
}
- memset(params->auth_simple, 0, OSPF_AUTH_SIMPLE_SIZE + 1);
- strncpy((char *)params->auth_simple, argv[3]->arg,
- OSPF_AUTH_SIMPLE_SIZE);
+ strlcpy((char *)params->auth_simple, argv[3]->arg,
+ sizeof(params->auth_simple));
SET_IF_PARAM(params, auth_simple);
return CMD_SUCCESS;
@@ -7006,8 +7004,7 @@ DEFUN (ip_ospf_message_digest_key,
ck = ospf_crypt_key_new();
ck->key_id = (uint8_t)key_id;
- memset(ck->auth_key, 0, OSPF_AUTH_MD5_SIZE + 1);
- strncpy((char *)ck->auth_key, cryptkey, OSPF_AUTH_MD5_SIZE);
+ strlcpy((char *)ck->auth_key, cryptkey, sizeof(ck->auth_key));
ospf_crypt_key_add(params->auth_crypt, ck);
SET_IF_PARAM(params, auth_crypt);