The results are undefined if source and destination buffers overlap when calling s[n]printf(). Such as, sprintf(buf, "%s some further text", buf); The above will not produce the expected results.
This patch enssures that produce output as expected. Signed-off-by: Wei,Jiangang <weijg.f...@cn.fujitsu.com> --- testcases/kernel/syscalls/chroot/chroot03.c | 4 +++- testcases/kernel/syscalls/creat/creat04.c | 9 +++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/testcases/kernel/syscalls/chroot/chroot03.c b/testcases/kernel/syscalls/chroot/chroot03.c index 9376892..69fead4 100644 --- a/testcases/kernel/syscalls/chroot/chroot03.c +++ b/testcases/kernel/syscalls/chroot/chroot03.c @@ -151,7 +151,9 @@ static void setup(void) * set up good_dir to test whether chroot() is setting ENOENT if the * directory does not exist. */ - (void)sprintf(good_dir, "%s.%d", good_dir, getpid()); + good_dir_dup = strdup(good_dir); + (void)sprintf(good_dir, "%s.%d", good_dir_dup, getpid()); + free(good_dir_dup); #if !defined(UCLINUX) bad_addr = mmap(0, 1, PROT_NONE, diff --git a/testcases/kernel/syscalls/creat/creat04.c b/testcases/kernel/syscalls/creat/creat04.c index 0268e77..44c249f 100644 --- a/testcases/kernel/syscalls/creat/creat04.c +++ b/testcases/kernel/syscalls/creat/creat04.c @@ -192,10 +192,11 @@ void setup(void) /* make a temporary directory and cd to it */ tst_tmpdir(); - - sprintf(good_dir, "%s.%d", good_dir, getpid()); - sprintf(fname1, "%s/file1.%d", good_dir, getpid()); - sprintf(fname, "%s/file.%d", good_dir, getpid()); + good_dir_dup = strdup(good_dir); + sprintf(good_dir, "%s.%d", good_dir_dup, getpid()); + sprintf(fname1, "%s/file1.%d", good_dir_dup, getpid()); + sprintf(fname, "%s/file.%d", good_dir_dup, getpid()); + free(good_dir_dup); } /* -- 1.9.3 ------------------------------------------------------------------------------ _______________________________________________ Ltp-list mailing list Ltp-list@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/ltp-list