Apache HTTPD
testxml.c
Go to the documentation of this file.
1/* Licensed to the Apache Software Foundation (ASF) under one or more
2 * contributor license agreements. See the NOTICE file distributed with
3 * this work for additional information regarding copyright ownership.
4 * The ASF licenses this file to You under the Apache License, Version 2.0
5 * (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "apr.h"
18#include "apr_general.h"
19#include "apr_xml.h"
20#include "abts.h"
21#include "testutil.h"
22
24 apr_file_t **fd)
25{
26 int i;
27 apr_status_t rv;
28 apr_off_t off = 0L;
29 char template[] = "data/testxmldummyerrorXXXXXX";
30
34
35 if (rv != APR_SUCCESS)
36 return rv;
37
38 rv = apr_file_puts("<?xml version=\"1.0\" ?>\n<maryx>"
39 "<had a=\"little\"/><lamb/>\n", *fd);
41
42 for (i = 0; i < 5000; i++) {
43 rv = apr_file_puts("<hmm roast=\"lamb\" "
44 "for=\"dinner\">yummy</hmm>\n", *fd);
46 }
47
48 rv = apr_file_puts("</mary>\n", *fd);
50
51 rv = apr_file_seek(*fd, APR_SET, &off);
53
54 return rv;
55}
56
58 apr_file_t **fd)
59{
60 int i;
61 apr_status_t rv;
62 apr_off_t off = 0L;
63 char template[] = "data/testxmldummyXXXXXX";
64
68
69 if (rv != APR_SUCCESS)
70 return rv;
71
72 rv = apr_file_puts("<?xml version=\"1.0\" ?>\n<mary>\n", *fd);
74
75 for (i = 0; i < 5000; i++) {
76 rv = apr_file_puts("<hmm roast=\"lamb\" "
77 "for=\"dinner &lt;&gt;&#x3D;\">yummy</hmm>\n", *fd);
79 }
80
81 rv = apr_file_puts("</mary>\n", *fd);
83
84 rv = apr_file_seek(*fd, APR_SET, &off);
86
87 return rv;
88}
89
90static void dump_xml(abts_case *tc, apr_xml_elem *e, int level)
91{
93 apr_xml_elem *ec;
94
95 if (level == 0) {
96 ABTS_STR_EQUAL(tc, "mary", e->name);
97 } else {
98 ABTS_STR_EQUAL(tc, "hmm", e->name);
99 }
100
101 if (e->attr) {
102 a = e->attr;
103 ABTS_PTR_NOTNULL(tc, a);
104 ABTS_STR_EQUAL(tc, "for", a->name);
105 ABTS_STR_EQUAL(tc, "dinner <>=", a->value);
106 a = a->next;
107 ABTS_PTR_NOTNULL(tc, a);
108 ABTS_STR_EQUAL(tc, "roast", a->name);
109 ABTS_STR_EQUAL(tc, "lamb", a->value);
110 }
111 if (e->first_child) {
112 ec = e->first_child;
113 while (ec) {
114 dump_xml(tc, ec, level + 1);
115 ec = ec->next;
116 }
117 }
118}
119
120static void test_xml_parser(abts_case *tc, void *data)
121{
122 apr_file_t *fd;
124 apr_xml_doc *doc;
125 apr_status_t rv;
126
127 rv = create_dummy_file(tc, p, &fd);
129
130 if (rv != APR_SUCCESS)
131 return;
132
133 rv = apr_xml_parse_file(p, &parser, &doc, fd, 2000);
135
136 dump_xml(tc, doc->root, 0);
137
138 rv = apr_file_close(fd);
140
141 rv = create_dummy_file_error(tc, p, &fd);
143
144 if (rv != APR_SUCCESS)
145 return;
146
147 rv = apr_xml_parse_file(p, &parser, &doc, fd, 2000);
148 ABTS_TRUE(tc, rv != APR_SUCCESS);
149}
150
151static void test_billion_laughs(abts_case *tc, void *data)
152{
153 apr_file_t *fd;
155 apr_xml_doc *doc;
156 apr_status_t rv;
157
158 rv = apr_file_open(&fd, "data/billion-laughs.xml",
159 APR_FOPEN_READ, 0, p);
160 apr_assert_success(tc, "open billion-laughs.xml", rv);
161
162 /* Don't test for return value; if it returns, chances are the bug
163 * is fixed or the machine has insane amounts of RAM. */
164 apr_xml_parse_file(p, &parser, &doc, fd, 2000);
165
167}
168
170{
171 apr_xml_parser *xp;
172 apr_xml_doc *doc;
173 apr_status_t rv;
174
176
177 rv = apr_xml_parser_feed(xp, "\0\r\n", 3);
178 if (rv == APR_SUCCESS)
179 apr_xml_parser_done(xp, &doc);
180}
181
183{
184 apr_xml_parser *xp;
185 apr_xml_doc *doc;
186 apr_status_t rv;
187
189
190 rv = apr_xml_parser_feed(xp, "<?xml version\xc2\x85='1.0'?>\r\n", 25);
191 if (rv == APR_SUCCESS)
192 apr_xml_parser_done(xp, &doc);
193}
194
196{
197 suite = ADD_SUITE(suite);
198
203
204 return suite;
205}
void abts_run_test(abts_suite *ts, test_func f, void *value)
Definition abts.c:175
#define ABTS_TRUE(a, b)
Definition abts.h:127
#define ADD_SUITE(suite)
Definition abts.h:67
#define ABTS_PTR_NOTNULL(a, b)
Definition abts.h:125
#define ABTS_STR_EQUAL(a, b, c)
Definition abts.h:123
#define ABTS_INT_EQUAL(a, b, c)
Definition abts.h:109
void apr_assert_success(abts_case *tc, const char *context, apr_status_t rv, int lineno)
Definition testutil.c:29
APR Miscellaneous library routines.
APR-UTIL XML Library.
apr_bucket * e
apr_bucket apr_bucket_brigade * a
apr_file_t * fd
apr_xml_parser ** parser
Definition apr_xml.h:228
apr_size_t size
#define APR_SUCCESS
Definition apr_errno.h:225
int apr_status_t
Definition apr_errno.h:44
void * data
#define APR_FOPEN_TRUNCATE
Definition apr_file_io.h:58
#define APR_FOPEN_DELONCLOSE
Definition apr_file_io.h:66
#define APR_FOPEN_EXCL
Definition apr_file_io.h:63
#define APR_FOPEN_WRITE
Definition apr_file_io.h:55
#define APR_FOPEN_READ
Definition apr_file_io.h:54
#define APR_FOPEN_CREATE
Definition apr_file_io.h:56
#define APR_SET
apr_pool_t * p
Definition md_event.c:32
return NULL
Definition mod_so.c:359
int i
Definition mod_so.c:347
struct apr_bucket *volatile next
apr_xml_elem * root
Definition apr_xml.h:202
struct apr_xml_elem * next
Definition apr_xml.h:178
static apr_status_t create_dummy_file_error(abts_case *tc, apr_pool_t *p, apr_file_t **fd)
Definition testxml.c:23
static void dump_xml(abts_case *tc, apr_xml_elem *e, int level)
Definition testxml.c:90
static void test_CVE_2009_3720_beta(abts_case *tc, void *data)
Definition testxml.c:182
abts_suite * testxml(abts_suite *suite)
Definition testxml.c:195
static void test_xml_parser(abts_case *tc, void *data)
Definition testxml.c:120
static apr_status_t create_dummy_file(abts_case *tc, apr_pool_t *p, apr_file_t **fd)
Definition testxml.c:57
static void test_CVE_2009_3720_alpha(abts_case *tc, void *data)
Definition testxml.c:169
static void test_billion_laughs(abts_case *tc, void *data)
Definition testxml.c:151