summaryrefslogtreecommitdiffstats
path: root/sbin/swapon
diff options
context:
space:
mode:
authored <ed@FreeBSD.org>2016-05-31 06:45:19 +0000
committered <ed@FreeBSD.org>2016-05-31 06:45:19 +0000
commit12cc424125e73bc7b3a2e8a26a233291ff2a6b8a (patch)
tree13d7cc1c3d73a5c83582a0ef5d5524808cd31e10 /sbin/swapon
parentb504edd9ef4d37f1250c07842a56d539829bae0d (diff)
downloadFreeBSD-src-12cc424125e73bc7b3a2e8a26a233291ff2a6b8a.zip
FreeBSD-src-12cc424125e73bc7b3a2e8a26a233291ff2a6b8a.tar.gz
Stop using the non-standard basename_r() function.
This change makes the code use the POSIX basename() function. It has the advantage that (if implemented correctly), it also imposes no restrict on the pathname length. Notice that I haven't added any error handling to the strdup() call. It looks like none of the other calls to strdup() and malloc() performed by this utility do it either. Reviewed by: hrs Differential Revision: https://reviews.freebsd.org/D6626
Diffstat (limited to 'sbin/swapon')
-rw-r--r--sbin/swapon/swapon.c14
1 files changed, 10 insertions, 4 deletions
diff --git a/sbin/swapon/swapon.c b/sbin/swapon/swapon.c
index 0c534ad..e34cfcf 100644
--- a/sbin/swapon/swapon.c
+++ b/sbin/swapon/swapon.c
@@ -216,7 +216,7 @@ main(int argc, char **argv)
static const char *
swap_on_off(const char *name, int doingall, char *mntops)
{
- char base[PATH_MAX];
+ char *base, *basebuf;
/* Swap on vnode-backed md(4) device. */
if (mntops != NULL &&
@@ -227,17 +227,23 @@ swap_on_off(const char *name, int doingall, char *mntops)
strncmp(MD_NAME, name, sizeof(MD_NAME)) == 0))
return (swap_on_off_md(name, mntops, doingall));
- basename_r(name, base);
+ basebuf = strdup(name);
+ base = basename(basebuf);
/* Swap on encrypted device by GEOM_BDE. */
- if (fnmatch("*.bde", base, 0) == 0)
+ if (fnmatch("*.bde", base, 0) == 0) {
+ free(basebuf);
return (swap_on_off_gbde(name, doingall));
+ }
/* Swap on encrypted device by GEOM_ELI. */
- if (fnmatch("*.eli", base, 0) == 0)
+ if (fnmatch("*.eli", base, 0) == 0) {
+ free(basebuf);
return (swap_on_off_geli(name, mntops, doingall));
+ }
/* Swap on special file. */
+ free(basebuf);
return (swap_on_off_sfile(name, doingall));
}
OpenPOWER on IntegriCloud