]> granicus.if.org Git - strace/commitdiff
tests: check escaping in string printing
authorEugene Syromyatnikov <evgsyr@gmail.com>
Fri, 2 Feb 2018 16:29:36 +0000 (17:29 +0100)
committerDmitry V. Levin <ldv@altlinux.org>
Thu, 1 Mar 2018 01:00:24 +0000 (01:00 +0000)
* tests/test_printstrn.c (test_print_memory): New function.
(test_printstrn): Use it.

tests/test_printstrn.c

index bc9c7752e954cbf614d50ec5ce11434131cbee1f..609a43b274af9186cb959168c4eb1e5a096c5b59 100644 (file)
@@ -75,6 +75,15 @@ test_efault(const unsigned int test_max)
        }
 }
 
+static void
+test_print_memory(char *const p, const unsigned int test_max)
+{
+       add_key(p, test_max);
+       printf("add_key(NULL, NULL, ");
+       print_quoted_memory(p, test_max);
+       printf(", %u, KEY_SPEC_THREAD_KEYRING) = %s\n", test_max, errstr);
+}
+
 void
 test_printstrn(const unsigned int test_max)
 {
@@ -99,4 +108,11 @@ test_printstrn(const unsigned int test_max)
        for (i = 0; i < sizeof(long); ++i)
                test_printstrn_at(p + page_size - i, test_max);
        test_efault(test_max);
+
+       fill_memory_ex(p, test_max + page_size, 0x00, 0xFF);
+       /* Test corner cases when octal quoting goes before digit */
+       for (int i = 0; i < 11; i++)
+               p[2 + 3 * i] = '0' + i - 1;
+
+       test_print_memory(p, test_max);
 }