svn commit: r360619 - head/sbin/swapon
Xin LI
delphij at FreeBSD.org
Mon May 4 05:49:12 UTC 2020
Author: delphij
Date: Mon May 4 05:49:11 2020
New Revision: 360619
URL: https://svnweb.freebsd.org/changeset/base/360619
Log:
- Fix logic error in swapoff case: follow same handling of p and
linelen in the swapon case.
- Use strlcpy instead of strncpy.
MFC after: 1 week
Modified:
head/sbin/swapon/swapon.c
Modified: head/sbin/swapon/swapon.c
==============================================================================
--- head/sbin/swapon/swapon.c Sun May 3 23:40:16 2020 (r360618)
+++ head/sbin/swapon/swapon.c Mon May 4 05:49:11 2020 (r360619)
@@ -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';
More information about the svn-src-all
mailing list