From de397ab94c0ae9b023ad4c6e02e762c52aaa9dc0 Mon Sep 17 00:00:00 2001 From: asomers Date: Tue, 30 May 2017 15:18:22 +0000 Subject: MFC r318141, r318143-r318144 r318141: strcpy => strlcpy Reported by: Coverity CID: 1352771 Sponsored by: Spectra Logic Corp r318143: strcpy => strlcpy Reported by: Coverity CID: 1006715 Sponsored by: Spectra Logic Corp r318144: Don't depend on assert(3) getting evaluated Reported by: imp X-MFC-With: 318141, 318143 Sponsored by: Spectra Logic Corp --- usr.bin/mkuzip/mkuzip.c | 5 +++-- usr.sbin/pw/pw_user.c | 6 +++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/usr.bin/mkuzip/mkuzip.c b/usr.bin/mkuzip/mkuzip.c index 6288f4e..1a78ae2 100644 --- a/usr.bin/mkuzip/mkuzip.c +++ b/usr.bin/mkuzip/mkuzip.c @@ -108,7 +108,7 @@ int main(int argc, char **argv) struct mkuz_conveyor *cvp; void *c_ctx; struct mkuz_blk_info *chit; - size_t ncpusz, ncpu; + size_t ncpusz, ncpu, magiclen; double st, et; st = getdtime(); @@ -192,7 +192,8 @@ int main(int argc, char **argv) /* Not reached */ } - strcpy(hdr.magic, cfs.handler->magic); + magiclen = strlcpy(hdr.magic, cfs.handler->magic, sizeof(hdr.magic)); + assert(magiclen < sizeof(hdr.magic)); if (cfs.en_dedup != 0) { hdr.magic[CLOOP_OFS_VERSN] = CLOOP_MAJVER_3; diff --git a/usr.sbin/pw/pw_user.c b/usr.sbin/pw/pw_user.c index 5466bec..76849ba 100644 --- a/usr.sbin/pw/pw_user.c +++ b/usr.sbin/pw/pw_user.c @@ -33,6 +33,7 @@ static const char rcsid[] = #include #include +#include #include #include #include @@ -490,6 +491,7 @@ pw_pwcrypt(char *password) char salt[SALTSIZE + 1]; char *cryptpw; static char buf[256]; + size_t pwlen; /* * Calculate a salt value @@ -501,7 +503,9 @@ pw_pwcrypt(char *password) cryptpw = crypt(password, salt); if (cryptpw == NULL) errx(EX_CONFIG, "crypt(3) failure"); - return strcpy(buf, cryptpw); + pwlen = strlcpy(buf, cryptpw, sizeof(buf)); + assert(pwlen < sizeof(buf)); + return (buf); } static char * -- cgit v1.1