Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 18 Jan 2021 01:38:59 GMT
From:      Xin LI <delphij@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
Subject:   git: 42ca6b642f45 - stable/12 - sbin/camcontrol: use calloc/strlcpy where appropriate.
Message-ID:  <202101180138.10I1cxYh037279@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch stable/12 has been updated by delphij:

URL: https://cgit.FreeBSD.org/src/commit/?id=42ca6b642f455c9fa3d2b08033e983550741412d

commit 42ca6b642f455c9fa3d2b08033e983550741412d
Author:     Xin LI <delphij@FreeBSD.org>
AuthorDate: 2021-01-04 06:52:28 +0000
Commit:     Xin LI <delphij@FreeBSD.org>
CommitDate: 2021-01-18 01:38:46 +0000

    sbin/camcontrol: use calloc/strlcpy where appropriate.
    
    MFC after:      2 weeks
    
    (cherry picked from commit fd340a122259d44a7d01a72890ff40411f87d79c)
---
 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 20cae4154cef..0b8b9e57fb43 100644
--- a/sbin/camcontrol/camcontrol.c
+++ b/sbin/camcontrol/camcontrol.c
@@ -2479,11 +2479,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;



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202101180138.10I1cxYh037279>