Author: delphij
Date: Mon May 11 07:20:37 2020
New Revision: 360892
URL: https://svnweb.freebsd.org/changeset/base/360892

Log:
  MFC r360619:
   - Fix logic error in swapoff case: follow same handling of p and
     linelen in the swapon case.
   - Use strlcpy instead of strncpy.

Modified:
  stable/12/sbin/swapon/swapon.c
Directory Properties:
  stable/12/   (props changed)

Modified: stable/12/sbin/swapon/swapon.c
==============================================================================
--- stable/12/sbin/swapon/swapon.c      Mon May 11 07:01:10 2020        
(r360891)
+++ stable/12/sbin/swapon/swapon.c      Mon May 11 07:20:37 2020        
(r360892)
@@ -548,8 +548,7 @@ swap_on_off_md(const char *name, char *mntops, int doi
                                ret = NULL;
                                goto err;
                        }
-                       strncpy(linebuf, p, linelen);
-                       linebuf[linelen - 1] = '\0';
+                       strlcpy(linebuf, p, linelen);
                        errno = 0;
                        ul = strtoul(linebuf, &p, 10);
                        if (errno == 0) {
@@ -604,14 +603,13 @@ swap_on_off_md(const char *name, char *mntops, int doi
                                goto err;
                        }
                        p = fgetln(sfd, &linelen);
-                       if (p == NULL &&
-                           (linelen < 2 || linelen > sizeof(linebuf) - 1)) {
+                       if (p == NULL ||
+                           (linelen < 2 || linelen > sizeof(linebuf))) {
                                warn("mdconfig (list) unexpected output");
                                ret = NULL;
                                goto err;
                        }
-                       strncpy(linebuf, p, linelen);
-                       linebuf[linelen - 1] = '\0';
+                       strlcpy(linebuf, p, linelen);
                        p = strchr(linebuf, ' ');
                        if (p != NULL)
                                *p = '\0';
_______________________________________________
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to