]> git.proxmox.com Git - mirror_frr.git/commitdiff
ospfd: strncpy -> strlcpy
authorQuentin Young <qlyoung@cumulusnetworks.com>
Tue, 26 Feb 2019 20:34:39 +0000 (20:34 +0000)
committerQuentin Young <qlyoung@cumulusnetworks.com>
Tue, 26 Feb 2019 20:50:17 +0000 (20:50 +0000)
strncpy is a byte copy function not a string copy function

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
ospfd/ospf_dump.c
ospfd/ospf_vty.c

index 48d210d2790270db639984fc3ec37a9c5c3c3fd8..f74d9733ee7ee07e22b73f85d3cf313189c62c13 100644 (file)
@@ -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:
index c1dc1f0d6fae8441dc94b6e48b7021c46bb0fe87..bb22f211a7c07ca55567b2636b07d2976e803de9 100644 (file)
@@ -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);