diff --git a/scpmisc.c b/scpmisc.c index 33e1891..c2f053e 100644 --- a/scpmisc.c +++ b/scpmisc.c @@ -102,7 +102,7 @@ xstrdup(const char *str) len = strlen(str) + 1; cp = xmalloc(len); - strncpy(cp, str, len); + strlcpy(cp, str, len); return cp; } diff --git a/svr-authpubkey.c b/svr-authpubkey.c index ae1402d..dafa99a 100644 --- a/svr-authpubkey.c +++ b/svr-authpubkey.c @@ -424,8 +424,9 @@ static int checkpubkeyperms() { /* allocate max required pathname storage, * = path + "/.ssh/authorized_keys" + '\0' = pathlen + 22 */ - filename = m_malloc(len + 22); - strncpy(filename, ses.authstate.pw_dir, len+1); + len += 22; + filename = m_malloc(len); + strlcpy(filename, ses.authstate.pw_dir, len); /* check ~ */ if (checkfileperm(filename) != DROPBEAR_SUCCESS) { @@ -433,13 +434,13 @@ static int checkpubkeyperms() { } /* check ~/.ssh */ - strncat(filename, "/.ssh", 5); /* strlen("/.ssh") == 5 */ + strlcat(filename, "/.ssh", len); if (checkfileperm(filename) != DROPBEAR_SUCCESS) { goto out; } /* now check ~/.ssh/authorized_keys */ - strncat(filename, "/authorized_keys", 16); + strlcat(filename, "/authorized_keys", len); if (checkfileperm(filename) != DROPBEAR_SUCCESS) { goto out; }