Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 11 May 2020 07:21:59 +0000 (UTC)
From:      Xin LI <delphij@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org
Subject:   svn commit: r360893 - stable/11/sbin/swapon
Message-ID:  <202005110721.04B7LxMZ012954@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: delphij
Date: Mon May 11 07:21:59 2020
New Revision: 360893
URL: https://svnweb.freebsd.org/changeset/base/360893

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/11/sbin/swapon/swapon.c
Directory Properties:
  stable/11/   (props changed)

Modified: stable/11/sbin/swapon/swapon.c
==============================================================================
--- stable/11/sbin/swapon/swapon.c	Mon May 11 07:20:37 2020	(r360892)
+++ stable/11/sbin/swapon/swapon.c	Mon May 11 07:21:59 2020	(r360893)
@@ -527,8 +527,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) {
@@ -583,14 +582,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';



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