isisd: strncpy -> strlcpy

strncpy is a byte copy function not a string copy function

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
This commit is contained in:
Quentin Young 2019-02-26 19:48:12 +00:00
parent cacbdfb14d
commit e28544ed99
4 changed files with 11 additions and 7 deletions

View File

@ -1305,7 +1305,7 @@ ferr_r isis_circuit_passwd_unset(struct isis_circuit *circuit)
return ferr_ok(); return ferr_ok();
} }
static int isis_circuit_passwd_set(struct isis_circuit *circuit, ferr_r isis_circuit_passwd_set(struct isis_circuit *circuit,
uint8_t passwd_type, const char *passwd) uint8_t passwd_type, const char *passwd)
{ {
int len; int len;
@ -1319,7 +1319,8 @@ static int isis_circuit_passwd_set(struct isis_circuit *circuit,
"circuit password too long (max 254 chars)"); "circuit password too long (max 254 chars)");
circuit->passwd.len = len; circuit->passwd.len = len;
strncpy((char *)circuit->passwd.passwd, passwd, 255); strlcpy((char *)circuit->passwd.passwd, passwd,
sizeof(circuit->passwd.passwd));
circuit->passwd.type = passwd_type; circuit->passwd.type = passwd_type;
return ferr_ok(); return ferr_ok();
} }

View File

@ -190,6 +190,8 @@ ferr_r isis_circuit_metric_set(struct isis_circuit *circuit, int level,
int metric); int metric);
ferr_r isis_circuit_passwd_unset(struct isis_circuit *circuit); ferr_r isis_circuit_passwd_unset(struct isis_circuit *circuit);
ferr_r isis_circuit_passwd_set(struct isis_circuit *circuit,
uint8_t passwd_type, const char *passwd);
ferr_r isis_circuit_passwd_cleartext_set(struct isis_circuit *circuit, ferr_r isis_circuit_passwd_cleartext_set(struct isis_circuit *circuit,
const char *passwd); const char *passwd);
ferr_r isis_circuit_passwd_hmac_md5_set(struct isis_circuit *circuit, ferr_r isis_circuit_passwd_hmac_md5_set(struct isis_circuit *circuit,

View File

@ -2092,8 +2092,8 @@ lib_interface_isis_password_password_modify(enum nb_event event,
password = yang_dnode_get_string(dnode, NULL); password = yang_dnode_get_string(dnode, NULL);
circuit = yang_dnode_get_entry(dnode, true); circuit = yang_dnode_get_entry(dnode, true);
circuit->passwd.len = strlen(password);
strncpy((char *)circuit->passwd.passwd, password, 255); isis_circuit_passwd_set(circuit, circuit->passwd.type, password);
return NB_OK; return NB_OK;
} }

View File

@ -1363,7 +1363,7 @@ struct isis_lsp *lsp_for_arg(const char *argv, dict_t *lspdb)
* xxxx.xxxx.xxxx * xxxx.xxxx.xxxx
*/ */
if (argv) if (argv)
strncpy(sysid, argv, 254); strlcpy(sysid, argv, sizeof(sysid));
if (argv && strlen(argv) > 3) { if (argv && strlen(argv) > 3) {
pos = argv + strlen(argv) - 3; pos = argv + strlen(argv) - 3;
if (strncmp(pos, "-", 1) == 0) { if (strncmp(pos, "-", 1) == 0) {
@ -1639,7 +1639,8 @@ static int isis_area_passwd_set(struct isis_area *area, int level,
return -1; return -1;
modified.len = len; modified.len = len;
strncpy((char *)modified.passwd, passwd, 255); strlcpy((char *)modified.passwd, passwd,
sizeof(modified.passwd));
modified.type = passwd_type; modified.type = passwd_type;
modified.snp_auth = snp_auth; modified.snp_auth = snp_auth;
} }