Date: Sun, 29 May 2016 10:48:18 -0600 From: Alan Somers <asomers@freebsd.org> To: Ed Schouten <ed@freebsd.org> Cc: "src-committers@freebsd.org" <src-committers@freebsd.org>, "svn-src-all@freebsd.org" <svn-src-all@freebsd.org>, "svn-src-head@freebsd.org" <svn-src-head@freebsd.org> Subject: Re: svn commit: r300952 - head/usr.sbin/services_mkdb Message-ID: <CAOtMX2i%2Bbw4Xq3wbrJ5j5LURMP=5JZzu6FQWpYPf9brj7-_a-A@mail.gmail.com> In-Reply-To: <201605291041.u4TAfRO3097741@repo.freebsd.org> References: <201605291041.u4TAfRO3097741@repo.freebsd.org>
next in thread | previous in thread | raw e-mail | index | archive | help
On Sun, May 29, 2016 at 4:41 AM, Ed Schouten <ed@freebsd.org> wrote: > Author: ed > Date: Sun May 29 10:41:27 2016 > New Revision: 300952 > URL: https://svnweb.freebsd.org/changeset/base/300952 > > Log: > Invoke the dirname() function in a POSIX compliant way. > > POSIX requires that the argument of dirname() is of type "char *". In > other words, the input buffer can be modified by the function to store > the directory name. > > Pull a copy of the string before calling dirname(). We don't care about > freeing up the memory afterwards, as this is done at the very bottom of > main(), right before the program terminates. > > Reviewed by: bapt > Differential Revision: https://reviews.freebsd.org/D6628 > > Modified: > head/usr.sbin/services_mkdb/services_mkdb.c > > Modified: head/usr.sbin/services_mkdb/services_mkdb.c > ============================================================================== > --- head/usr.sbin/services_mkdb/services_mkdb.c Sun May 29 07:39:56 2016 (r300951) > +++ head/usr.sbin/services_mkdb/services_mkdb.c Sun May 29 10:41:27 2016 (r300952) > @@ -92,7 +92,7 @@ main(int argc, char *argv[]) > size_t cnt = 0; > StringList *sl, ***svc; > size_t port, proto; > - char *dbname_dir; > + char *dbname_dir, *dbname_dirbuf; > int dbname_dir_fd = -1; > > setprogname(argv[0]); > @@ -172,7 +172,8 @@ main(int argc, char *argv[]) > * fsync() to the directory where file lies > */ > if (rename(tname, dbname) == -1 || > - (dbname_dir = dirname(dbname)) == NULL || > + (dbname_dirbuf = strdup(dbname)) == NULL || > + (dbname_dir = dirname(dbname_dirbuf)) == NULL || > (dbname_dir_fd = open(dbname_dir, O_RDONLY|O_DIRECTORY)) == -1 || > fsync(dbname_dir_fd) != 0) { > if (dbname_dir_fd != -1) > Even though the program is about to exit, it's worth freeing the memory just to make Coverity shut up. -Alan
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CAOtMX2i%2Bbw4Xq3wbrJ5j5LURMP=5JZzu6FQWpYPf9brj7-_a-A>