diff options
author | наб <[email protected]> | 2021-05-22 17:19:14 +0200 |
---|---|---|
committer | Brian Behlendorf <[email protected]> | 2021-06-11 09:10:21 -0700 |
commit | feb04e66802ef96aa77951c43d4b632b376041ef (patch) | |
tree | 0d78f6283f001f8f66828bef33c9ace4185f7802 /tests/zfs-tests | |
parent | 64dfdaba372f07f91a6eab598b3480693b1d14c8 (diff) |
Forbid basename(3) and dirname(3)
There are at least two interpretations of basename(3),
in addition to both functions being allowed to /both/ return a static
buffer (unsuitable in multi-threaded environments) /and/ raze the input
(which encourages overallocations, at best)
Reviewed-by: John Kennedy <[email protected]>
Reviewed-by: Brian Behlendorf <[email protected]>
Reviewed-by: Ryan Moeller <[email protected]>
Signed-off-by: Ahelenia Ziemiańska <[email protected]>
Closes #12105
Diffstat (limited to 'tests/zfs-tests')
-rw-r--r-- | tests/zfs-tests/tests/functional/ctime/Makefile.am | 2 | ||||
-rw-r--r-- | tests/zfs-tests/tests/functional/ctime/ctime.c | 13 |
2 files changed, 7 insertions, 8 deletions
diff --git a/tests/zfs-tests/tests/functional/ctime/Makefile.am b/tests/zfs-tests/tests/functional/ctime/Makefile.am index e7479ae81..3174f78c6 100644 --- a/tests/zfs-tests/tests/functional/ctime/Makefile.am +++ b/tests/zfs-tests/tests/functional/ctime/Makefile.am @@ -11,3 +11,5 @@ pkgexecdir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/ctime pkgexec_PROGRAMS = ctime ctime_SOURCES = ctime.c + +ctime_LDADD = $(abs_top_builddir)/lib/libzfs_core/libzfs_core.la diff --git a/tests/zfs-tests/tests/functional/ctime/ctime.c b/tests/zfs-tests/tests/functional/ctime/ctime.c index d01fa0d4e..2d515d957 100644 --- a/tests/zfs-tests/tests/functional/ctime/ctime.c +++ b/tests/zfs-tests/tests/functional/ctime/ctime.c @@ -37,6 +37,7 @@ #include <utime.h> #include <stdio.h> #include <stdlib.h> +#include <libzutil.h> #include <unistd.h> #include <strings.h> #include <errno.h> @@ -149,22 +150,18 @@ static int do_link(const char *pfile) { int ret = 0; - char link_file[BUFSIZ] = { 0 }; - char pfile_copy[BUFSIZ] = { 0 }; - char *dname; + char link_file[BUFSIZ + 16] = { 0 }; if (pfile == NULL) { return (-1); } - strncpy(pfile_copy, pfile, sizeof (pfile_copy)-1); - pfile_copy[sizeof (pfile_copy) - 1] = '\0'; /* * Figure out source file directory name, and create * the link file in the same directory. */ - dname = dirname((char *)pfile_copy); - (void) snprintf(link_file, BUFSIZ, "%s/%s", dname, "link_file"); + (void) snprintf(link_file, sizeof (link_file), + "%.*s/%s", (int)zfs_dirnamelen(pfile), pfile, "link_file"); if (link(pfile, link_file) == -1) { (void) fprintf(stderr, "link(%s, %s) failed with errno %d\n", @@ -321,7 +318,7 @@ main(int argc, char *argv[]) (void) snprintf(tfile, sizeof (tfile), "%s/%s", penv[0], penv[1]); /* - * If the test file is exists, remove it first. + * If the test file exists, remove it first. */ if (access(tfile, F_OK) == 0) { (void) unlink(tfile); |