[Ltrace-devel] [PATCH] Add tests for %p format specifier crash and zero(EXPR) leaks
Peter Wu
lekensteyn at gmail.com
Thu Sep 26 14:44:18 UTC 2013
Notes for these regression tests:
- The %p test should run when ltrace is built with -fsanitize=address or
some other form of protection that makes the program abort when trying
to free() static memory.
- The zero(EXPR) test needs valgrind to test for the previous memleak
bug, but as it stands now, it can also test whether the zero
functionality works or not.
Signed-off-by: Peter Wu <lekensteyn at gmail.com>
---
Hi,
I have never used dejagnu or expect before and these tests were created by
looking at the above tests. Hopefully they fit well, it looks sane to me.
With commit cae76962c7e0ec6119952addb36d1cf8d19f5228 ("Prevent freeing
static-alloc'd memory for %p and %n in printf") and
594ef6824f4b08adff9b67f1481030a81dbf3bf7 ("Fix memory leak for zero(EXPR)")
reverted, the tests fail. With the current master, it passes all tests.
Regards,
Peter
---
testsuite/ltrace.main/parameters2.exp | 30 ++++++++++++++++++++++++++++++
1 file changed, 30 insertions(+)
diff --git a/testsuite/ltrace.main/parameters2.exp b/testsuite/ltrace.main/parameters2.exp
index 30a0cc1..a563d31 100644
--- a/testsuite/ltrace.main/parameters2.exp
+++ b/testsuite/ltrace.main/parameters2.exp
@@ -215,4 +215,34 @@ ltraceMatch1 [ltraceLibTest {
-L -x fun
}] {fun at .*\(\)} == 1
+
+# Test that %p format specifier does not crash
+
+ltraceMatch1 [ltraceLibTest {
+ void print_ptr(format);
+} {
+ void print_ptr(const char *format, ...);
+} {
+ void print_ptr(const char *format, ...) { }
+} {
+ void *addr = (void *)0x42;
+ print_ptr("%p\n", addr);
+}] {print_ptr\("%p\\n", 0x42\) *= <void>} == 1
+
+
+# Test that zero(EXPR) does not leak memory (needs valgrind)
+
+ltraceMatch1 [ltraceLibTest {
+ typedef String = string(array(char, zero(256)));
+ String *get_string();
+} {
+ char *get_string();
+} {
+ char *get_string() {
+ return "FOO";
+ }
+} {
+ get_string();
+}] {get_string\(\) *= "FOO"} == 1
+
ltraceDone
--
1.8.4
More information about the Ltrace-devel
mailing list