Xen Test Framework
main.c
Go to the documentation of this file.
1
23#include <xtf.h>
24
25const char test_title[] = "XSA-122 PoC";
26
27/*
28 * Check a buffer of a specified size for non-NUL bytes following the string
29 * NUL terminator.
30 */
31static void check_buffer(const char *ref, const char *buf, size_t buf_sz)
32{
33 unsigned int i;
34 size_t str_len = strnlen(buf, buf_sz);
35
36 if ( str_len == buf_sz )
37 return xtf_warning(" %s string not NUL terminated\n", ref);
38
39 else if ( str_len == buf_sz - 1 )
40 return; /* No trailing space after data. */
41
42 for ( i = str_len + 1; i < buf_sz && buf[i] == '\0'; ++i )
43 ; /* No action. */
44
45 if ( i != buf_sz )
46 xtf_failure(" '%s' has leaked stack at index %u\n", ref, i);
47}
48
49void test_main(void)
50{
51 long rc;
52
53 printk("XENVER_extraversion:\n");
54 {
56
57 memset(&extra, 0, sizeof(extra));
58
60 if ( rc < 0 )
61 return xtf_failure("XENVER_extraversion error %ld\n", rc);
62
63 printk(" Got '%s'\n", extra);
64 check_buffer("extraversion", extra, sizeof(extra));
65 }
66
67 printk("XENVER_compile_info:\n");
68 {
70
71 memset(&ci, 0, sizeof(ci));
72
74 if ( rc < 0 )
75 return xtf_failure("XENVER_compile_info error %ld\n", rc);
76
77 printk(" Got '%s'\n"
78 " '%s'\n"
79 " '%s'\n"
80 " '%s'\n",
82
83 check_buffer("compiler", ci.compiler, sizeof(ci.compiler));
84 check_buffer("compile_by", ci.compile_by, sizeof(ci.compile_by));
85 check_buffer("compile_domain", ci.compile_domain, sizeof(ci.compile_domain));
86 check_buffer("compile_date", ci.compile_date, sizeof(ci.compile_date));
87 }
88
89 printk("XENVER_changeset:\n");
90 {
92
93 memset(&ci, 0, sizeof(ci));
94
96 if ( rc < 0 )
97 return xtf_failure("XENVER_changeset error %ld\n", rc);
98
99 printk(" Got '%s'\n", ci);
100 check_buffer("changeset_info", ci, sizeof(ci));
101 }
102
104}
105
106/*
107 * Local variables:
108 * mode: C
109 * c-file-style: "BSD"
110 * c-basic-offset: 4
111 * tab-width: 4
112 * indent-tabs-mode: nil
113 * End:
114 */
void printk(const char *fmt,...)
Definition: console.c:134
void test_main(void)
To be implemented by each test, as its entry point.
Definition: main.c:110
const char test_title[]
The title of the test.
Definition: main.c:24
static long hypercall_xen_version(unsigned int cmd, void *arg)
Definition: hypercall.h:126
#define memset(d, c, n)
Definition: libc.h:33
void xtf_failure(const char *fmt,...)
Report a test failure.
Definition: report.c:94
void xtf_warning(const char *fmt,...)
Report a test warning.
Definition: report.c:52
void xtf_success(const char *fmt,...)
Report test success.
Definition: report.c:38
#define NULL
Definition: stddef.h:12
size_t strnlen(const char *str, size_t max)
Definition: string.c:13
char compiler[64]
Definition: version.h:17
char compile_date[32]
Definition: version.h:20
char compile_domain[32]
Definition: version.h:19
char compile_by[16]
Definition: version.h:18
#define XENVER_compile_info
Definition: version.h:15
char xen_extraversion_t[16]
Definition: version.h:12
#define XENVER_extraversion
Definition: version.h:11
char xen_changeset_info_t[64]
Definition: version.h:25
#define XENVER_changeset
Definition: version.h:24
static void check_buffer(const char *ref, const char *buf, size_t buf_sz)
Definition: main.c:31