diff options
author | ed <ed@FreeBSD.org> | 2016-05-29 10:41:27 +0000 |
---|---|---|
committer | ed <ed@FreeBSD.org> | 2016-05-29 10:41:27 +0000 |
commit | c2282cdf4ee0c39f911689e2e07bf659ff576c7c (patch) | |
tree | 447ee0796aaca8e939d1f6b52395f92fa51ff8eb | |
parent | 8cfacdd69c51b54ffaadc2c4fdc8e8a0b21b1791 (diff) | |
download | FreeBSD-src-c2282cdf4ee0c39f911689e2e07bf659ff576c7c.zip FreeBSD-src-c2282cdf4ee0c39f911689e2e07bf659ff576c7c.tar.gz |
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
-rw-r--r-- | usr.sbin/services_mkdb/services_mkdb.c | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/usr.sbin/services_mkdb/services_mkdb.c b/usr.sbin/services_mkdb/services_mkdb.c index fe23355..7a992c3 100644 --- a/usr.sbin/services_mkdb/services_mkdb.c +++ b/usr.sbin/services_mkdb/services_mkdb.c @@ -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) |