diff --git a/sbin/camcontrol/camcontrol.c b/sbin/camcontrol/camcontrol.c index 079aefb12269..cc21a109343c 100644 --- a/sbin/camcontrol/camcontrol.c +++ b/sbin/camcontrol/camcontrol.c @@ -2458,11 +2458,10 @@ atasecurity_notify(u_int8_t command, struct ata_security_password *pwd) printf("Issuing %s", ata_op_string(&cmd)); if (pwd != NULL) { + /* pwd->password may not be null terminated */ char pass[sizeof(pwd->password)+1]; - /* pwd->password may not be null terminated */ - pass[sizeof(pwd->password)] = '\0'; - strncpy(pass, pwd->password, sizeof(pwd->password)); + strlcpy(pass, pwd->password, sizeof(pass)); printf(" password='%s', user='%s'", pass, (pwd->ctrl & ATA_SECURITY_PASSWORD_MASTER) ? diff --git a/sbin/camcontrol/modeedit.c b/sbin/camcontrol/modeedit.c index c35ad143e1da..15e5c6608f47 100644 --- a/sbin/camcontrol/modeedit.c +++ b/sbin/camcontrol/modeedit.c @@ -329,10 +329,9 @@ editentry_set(char *name, char *newvalue, int editonly) case 'c': /* Character array. */ case 'z': /* Null-padded string. */ - if ((cval = malloc(dest->size + 1)) == NULL) + if ((cval = calloc(1, dest->size + 1)) == NULL) err(EX_OSERR, NULL); - bzero(cval, dest->size + 1); - strncpy(cval, newvalue, dest->size); + strlcpy(cval, newvalue, dest->size + 1); if (dest->type == 'z') { /* Convert trailing spaces to nulls. */ char *convertend2; diff --git a/sbin/camcontrol/util.c b/sbin/camcontrol/util.c index c22f3a05e746..58fc93746fc7 100644 --- a/sbin/camcontrol/util.c +++ b/sbin/camcontrol/util.c @@ -126,14 +126,13 @@ arg_put(void *hook __unused, int letter, void *arg, int count, char *name) { char *p; - p = malloc(count + 1); + p = calloc(1, count + 1); if (p == NULL) { fprintf(stderr, "can't malloc memory for p\n"); exit(1); } - bzero(p, count +1); - strncpy(p, (char *)arg, count); + strlcpy(p, (char *)arg, count + 1); if (letter == 'z') { int i;