git: fd340a122259 - main - sbin/camcontrol: use calloc/strlcpy where appropriate.
Xin LI
delphij at FreeBSD.org
Mon Jan 4 06:54:06 UTC 2021
The branch main has been updated by delphij:
URL: https://cgit.FreeBSD.org/src/commit/?id=fd340a122259d44a7d01a72890ff40411f87d79c
commit fd340a122259d44a7d01a72890ff40411f87d79c
Author: Xin LI <delphij at FreeBSD.org>
AuthorDate: 2021-01-04 06:52:28 +0000
Commit: Xin LI <delphij at FreeBSD.org>
CommitDate: 2021-01-04 06:52:28 +0000
sbin/camcontrol: use calloc/strlcpy where appropriate.
MFC after: 2 weeks
---
sbin/camcontrol/camcontrol.c | 5 ++---
sbin/camcontrol/modeedit.c | 5 ++---
sbin/camcontrol/util.c | 5 ++---
3 files changed, 6 insertions(+), 9 deletions(-)
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;
More information about the dev-commits-src-all
mailing list