sbin/camcontrol: use calloc/strlcpy where appropriate.

MFC after:	2 weeks
This commit is contained in:
Xin LI 2021-01-03 22:52:28 -08:00
parent d03fd8ede2
commit fd340a1222
3 changed files with 6 additions and 9 deletions

View File

@ -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) ?

View File

@ -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;

View File

@ -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;