public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
* [LTP] [PATCH 1/4] syscalls/chroot&creat: fix undefined behavior
@ 2015-06-10  6:54 Wei,Jiangang
  2015-06-10  6:54 ` [LTP] [PATCH 2/4] cpuset/cpuset_lib/cpuinfo.c: fix FILE pointer leak Wei,Jiangang
                   ` (3 more replies)
  0 siblings, 4 replies; 10+ messages in thread
From: Wei,Jiangang @ 2015-06-10  6:54 UTC (permalink / raw)
  To: ltp-list

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.fnst@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

^ permalink raw reply related	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2015-06-11 14:57 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-06-10  6:54 [LTP] [PATCH 1/4] syscalls/chroot&creat: fix undefined behavior Wei,Jiangang
2015-06-10  6:54 ` [LTP] [PATCH 2/4] cpuset/cpuset_lib/cpuinfo.c: fix FILE pointer leak Wei,Jiangang
2015-06-11 14:56   ` Cyril Hrubis
2015-06-10  6:55 ` [LTP] [PATCH 3/4] pan/symbol.c: fix memory leak for failure case Wei,Jiangang
2015-06-11 14:56   ` Cyril Hrubis
2015-06-10  6:55 ` [LTP] [PATCH 4/4] pan/splitstr.c: free memory allocated by strdup() Wei,Jiangang
2015-06-11 14:55   ` Cyril Hrubis
2015-06-10 14:16 ` [LTP] [PATCH 1/4] syscalls/chroot&creat: fix undefined behavior Cyril Hrubis
2015-06-11 10:40   ` [LTP] [PATCH v2] " Wei,Jiangang
2015-06-11 14:56     ` Cyril Hrubis

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox