From owner-svn-src-all@freebsd.org Tue May 31 06:45:20 2016 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id BA11FB55C8E; Tue, 31 May 2016 06:45:20 +0000 (UTC) (envelope-from ed@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 7D9501A59; Tue, 31 May 2016 06:45:20 +0000 (UTC) (envelope-from ed@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id u4V6jJQ8078505; Tue, 31 May 2016 06:45:19 GMT (envelope-from ed@FreeBSD.org) Received: (from ed@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u4V6jJdF078504; Tue, 31 May 2016 06:45:19 GMT (envelope-from ed@FreeBSD.org) Message-Id: <201605310645.u4V6jJdF078504@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: ed set sender to ed@FreeBSD.org using -f From: Ed Schouten Date: Tue, 31 May 2016 06:45:19 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r301024 - head/sbin/swapon X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 31 May 2016 06:45:20 -0000 Author: ed Date: Tue May 31 06:45:19 2016 New Revision: 301024 URL: https://svnweb.freebsd.org/changeset/base/301024 Log: 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 Modified: head/sbin/swapon/swapon.c Modified: head/sbin/swapon/swapon.c ============================================================================== --- head/sbin/swapon/swapon.c Tue May 31 06:24:09 2016 (r301023) +++ head/sbin/swapon/swapon.c Tue May 31 06:45:19 2016 (r301024) @@ -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 doinga 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)); }