The branch stable/12 has been updated by delphij:

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

commit 42ca6b642f455c9fa3d2b08033e983550741412d
Author:     Xin LI <delp...@freebsd.org>
AuthorDate: 2021-01-04 06:52:28 +0000
Commit:     Xin LI <delp...@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;
_______________________________________________
dev-commits-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/dev-commits-src-all
To unsubscribe, send any mail to "dev-commits-src-all-unsubscr...@freebsd.org"

Reply via email to