aboutsummaryrefslogtreecommitdiff
path: root/sbin/swapon
diff options
context:
space:
mode:
authorXin LI <delphij@FreeBSD.org>2020-05-11 07:20:37 +0000
committerXin LI <delphij@FreeBSD.org>2020-05-11 07:20:37 +0000
commiteafdce5c56eccb93aa3349b82ea9533a1c6ad0d2 (patch)
tree87051cd39ffb0ac003150615046348a662c256ef /sbin/swapon
parenta6d586ef26f77b22b7f20fb5a3439d42387226cf (diff)
downloadsrc-eafdce5c56eccb93aa3349b82ea9533a1c6ad0d2.tar.gz
src-eafdce5c56eccb93aa3349b82ea9533a1c6ad0d2.zip
MFC r360619:
- Fix logic error in swapoff case: follow same handling of p and linelen in the swapon case. - Use strlcpy instead of strncpy.
Notes
Notes: svn path=/stable/12/; revision=360892
Diffstat (limited to 'sbin/swapon')
-rw-r--r--sbin/swapon/swapon.c10
1 files changed, 4 insertions, 6 deletions
diff --git a/sbin/swapon/swapon.c b/sbin/swapon/swapon.c
index 04b3b9f6ac20..5adc870adf59 100644
--- a/sbin/swapon/swapon.c
+++ b/sbin/swapon/swapon.c
@@ -548,8 +548,7 @@ swap_on_off_md(const char *name, char *mntops, int doingall)
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 doingall)
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';