leptris 1.9.324.0-arm-linux → 1.9.331.0-arm-linux
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +42 -0
- data/Rakefile +1 -1
- data/lib/leptris/version.rb +1 -1
- data/lib/leptris/xml/ffi.rb +5 -0
- data/lib/leptris/xml/xsd.rb +18 -0
- data/lib/libleptris.so +0 -0
- data/vendor-src/README.md +1 -1
- data/vendor-src/libleptris/CHANGELOG.md +145 -0
- data/vendor-src/libleptris/CMakeLists.txt +1 -1
- data/vendor-src/libleptris/cli/commands/validate.c +5 -7
- data/vendor-src/libleptris/src/include/leptris.h +8 -0
- data/vendor-src/libleptris/src/leptris/dom/node_public.c +1 -1
- data/vendor-src/libleptris/src/leptris/dom/text.c +4 -2
- data/vendor-src/libleptris/src/leptris/dom/text.h +7 -2
- data/vendor-src/libleptris/src/leptris/flat/direct_parse.c +32 -4
- data/vendor-src/libleptris/src/leptris/html/html_parse.c +2 -1
- data/vendor-src/libleptris/src/leptris/leptris.c +7 -2
- data/vendor-src/libleptris/src/leptris/xsd/compile.c +793 -78
- data/vendor-src/libleptris/src/leptris/xsd/content_model.c +20 -2
- data/vendor-src/libleptris/src/leptris/xsd/validate.c +57 -19
- data/vendor-src/libleptris/src/leptris/xsd/xsd_internal.h +62 -3
- data/vendor-src/libleptris/src/leptris/xslt/xslt_exec.c +1 -1
- data/vendor-src/libleptris/test/CMakeLists.txt +5 -0
- data/vendor-src/libleptris/test/parser/test_parser.cpp +116 -0
- data/vendor-src/libleptris/test/xsd/test_xsd_compile.cpp +399 -4
- data/vendor-src/libleptris/vcpkg.json +1 -1
- metadata +1 -1
|
@@ -27,6 +27,8 @@ typedef struct {
|
|
|
27
27
|
size_t count, cap;
|
|
28
28
|
int state_count; /* explicit: state ids are NOT transition ids */
|
|
29
29
|
int start, accept;
|
|
30
|
+
struct leptris_xsd_schema* s; /* group-ref resolution */
|
|
31
|
+
int depth; /* cyclic-group guard */
|
|
30
32
|
} CmNfa;
|
|
31
33
|
|
|
32
34
|
static int nfa_state(CmNfa* n) { return n->state_count++; }
|
|
@@ -80,6 +82,19 @@ static void cm_build(CmNfa* n, XsdCm* node, int from, int to) {
|
|
|
80
82
|
case XSD_CM_ALL:
|
|
81
83
|
cm_build_children(n, node, from, to);
|
|
82
84
|
return;
|
|
85
|
+
case XSD_CM_GROUP_REF: {
|
|
86
|
+
XsdGroupDef* g =
|
|
87
|
+
n->s ? xsd_find_group(n->s, node->name) : NULL;
|
|
88
|
+
if (!g || !g->model || n->depth > 64) {
|
|
89
|
+
/* unresolved (or cyclic) ref: splice nothing */
|
|
90
|
+
nfa_trans(n, from, -1, NULL, to);
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
n->depth++;
|
|
94
|
+
cm_build(n, g->model, from, to);
|
|
95
|
+
n->depth--;
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
83
98
|
case XSD_CM_CHOICE: {
|
|
84
99
|
XsdCm* c = node->first_child;
|
|
85
100
|
if (!c) {
|
|
@@ -181,10 +196,10 @@ static void ss_close(StateSet* ss, CmNfa* n) {
|
|
|
181
196
|
int xsd_content_valid(struct leptris_xsd_schema* s, XsdCm* model,
|
|
182
197
|
const char* target_ns, const char* const* names,
|
|
183
198
|
const char* const* ns_uris, size_t count) {
|
|
184
|
-
(void)s;
|
|
185
199
|
if (!model) return -1;
|
|
186
200
|
CmNfa n;
|
|
187
201
|
memset(&n, 0, sizeof(n));
|
|
202
|
+
n.s = s;
|
|
188
203
|
n.start = nfa_state(&n);
|
|
189
204
|
n.accept = nfa_state(&n);
|
|
190
205
|
cm_build_occurrence(&n, model, n.start, n.accept);
|
|
@@ -205,7 +220,10 @@ int xsd_content_valid(struct leptris_xsd_schema* s, XsdCm* model,
|
|
|
205
220
|
continue;
|
|
206
221
|
XsdCm* p = tr->particle;
|
|
207
222
|
if (p->kind == XSD_CM_ELEMENT) {
|
|
208
|
-
|
|
223
|
+
int named = (strcmp(p->name, names[c]) == 0) ||
|
|
224
|
+
(n.s && xsd_is_substitute(
|
|
225
|
+
n.s, names[c], p->name));
|
|
226
|
+
if (named &&
|
|
209
227
|
(!p->ns || (uri && strcmp(uri, p->ns) == 0)))
|
|
210
228
|
ss_add(&next, tr->to);
|
|
211
229
|
} else if (p->kind == XSD_CM_ANY) {
|
|
@@ -20,7 +20,8 @@ extern int xsd_content_valid(struct leptris_xsd_schema* s, XsdCm* model,
|
|
|
20
20
|
const char* const* names,
|
|
21
21
|
const char* const* ns_uris, size_t count);
|
|
22
22
|
extern int xsd_builtin_valid(const char* type, const char* v);
|
|
23
|
-
extern int
|
|
23
|
+
extern int xsd_simple_valid_chain(struct leptris_xsd_schema* s,
|
|
24
|
+
const XsdSimple* t, const char* v);
|
|
24
25
|
|
|
25
26
|
struct xsd_error {
|
|
26
27
|
char* text;
|
|
@@ -96,7 +97,7 @@ static int text_valid(struct xsd_validator* v,
|
|
|
96
97
|
else {
|
|
97
98
|
const XsdSimple* st = xsd_find_simple_pub(s, type);
|
|
98
99
|
if (!st) return 1; /* unresolved: accept */
|
|
99
|
-
r =
|
|
100
|
+
r = xsd_simple_valid_chain(s, st, lexical);
|
|
100
101
|
}
|
|
101
102
|
if (r == 0) {
|
|
102
103
|
verrf(v, what, name, "lexical value does not match its type");
|
|
@@ -109,6 +110,10 @@ static int text_valid(struct xsd_validator* v,
|
|
|
109
110
|
static void validate_element(struct xsd_validator* v,
|
|
110
111
|
struct leptris_xsd_schema* s,
|
|
111
112
|
LeptrisElement elem, int depth);
|
|
113
|
+
static void validate_local(struct xsd_validator* v,
|
|
114
|
+
struct leptris_xsd_schema* s,
|
|
115
|
+
LeptrisElement elem, const char* local,
|
|
116
|
+
const char* type);
|
|
112
117
|
|
|
113
118
|
static void validate_children(struct xsd_validator* v,
|
|
114
119
|
struct leptris_xsd_schema* s,
|
|
@@ -151,16 +156,25 @@ static void validate_children(struct xsd_validator* v,
|
|
|
151
156
|
leptris_element_expanded_name(elem, &local, NULL, NULL);
|
|
152
157
|
verrf(v, "element", local, "children do not match the content model");
|
|
153
158
|
}
|
|
154
|
-
/* recurse
|
|
155
|
-
*
|
|
159
|
+
/* recurse: a global declaration governs the child when one
|
|
160
|
+
* exists; otherwise the parent's particle declaration does
|
|
161
|
+
* (first-name-match DFS — position-exact particle typing
|
|
162
|
+
* arrives with the NFA trace). */
|
|
156
163
|
for (LeptrisNodeRef c =
|
|
157
164
|
leptris_node_first_child(leptris_element_as_node(elem));
|
|
158
165
|
c; c = leptris_node_next_sibling(c)) {
|
|
166
|
+
if (leptris_node_get_type(c) != LEPTRIS_NODE_TYPE_ELEMENT)
|
|
167
|
+
continue;
|
|
159
168
|
LeptrisElement ce = (LeptrisElement)c;
|
|
160
169
|
const char* cl = NULL, *cp = NULL, *cu = NULL;
|
|
161
170
|
leptris_element_expanded_name(ce, &cl, &cp, &cu);
|
|
162
|
-
if (
|
|
163
|
-
|
|
171
|
+
if (!cl) continue;
|
|
172
|
+
if (xsd_find_element(s, cl)) {
|
|
173
|
+
validate_element(v, s, ce, 0);
|
|
174
|
+
continue;
|
|
175
|
+
}
|
|
176
|
+
const char* ptype = NULL;
|
|
177
|
+
if (model) {
|
|
164
178
|
XsdCm* stack[64];
|
|
165
179
|
int sp = 0;
|
|
166
180
|
stack[sp++] = model;
|
|
@@ -172,19 +186,18 @@ static void validate_children(struct xsd_validator* v,
|
|
|
172
186
|
ptype = p->type;
|
|
173
187
|
break;
|
|
174
188
|
}
|
|
189
|
+
if (p->kind == XSD_CM_GROUP_REF) {
|
|
190
|
+
XsdGroupDef* g = xsd_find_group(s, p->name);
|
|
191
|
+
if (g && g->model && sp < 64)
|
|
192
|
+
stack[sp++] = g->model;
|
|
193
|
+
}
|
|
175
194
|
if (sp < 64 && p->first_child)
|
|
176
195
|
stack[sp++] = p->first_child;
|
|
177
196
|
}
|
|
178
197
|
}
|
|
179
|
-
if (ptype) {
|
|
180
|
-
const char* text = leptris_element_text(ce);
|
|
181
|
-
if (text && *text)
|
|
182
|
-
text_valid(v, s, ptype, text, "element", cl);
|
|
183
|
-
}
|
|
184
198
|
}
|
|
185
|
-
if (
|
|
186
|
-
|
|
187
|
-
validate_element(v, s, ce, 0);
|
|
199
|
+
if (ptype)
|
|
200
|
+
validate_local(v, s, ce, cl, ptype);
|
|
188
201
|
}
|
|
189
202
|
}
|
|
190
203
|
|
|
@@ -219,6 +232,9 @@ static void validate_attributes(struct xsd_validator* v,
|
|
|
219
232
|
continue;
|
|
220
233
|
}
|
|
221
234
|
text_valid(v, s, a->type, val, "attribute", a->name);
|
|
235
|
+
if (a->fixed && strcmp(val, a->fixed) != 0)
|
|
236
|
+
verrf(v, "attribute", a->name,
|
|
237
|
+
"value does not match the fixed value");
|
|
222
238
|
}
|
|
223
239
|
}
|
|
224
240
|
|
|
@@ -233,20 +249,42 @@ static void validate_element(struct xsd_validator* v,
|
|
|
233
249
|
if (!d) return; /* undeclared: lax at this depth (strict later) */
|
|
234
250
|
|
|
235
251
|
if (!d->type) return; /* anyType */
|
|
252
|
+
if (d->fixed) {
|
|
253
|
+
const char* text = leptris_element_text(elem);
|
|
254
|
+
if (text && *text && strcmp(text, d->fixed) != 0)
|
|
255
|
+
verrf(v, "element", local,
|
|
256
|
+
"content does not match the fixed value");
|
|
257
|
+
}
|
|
258
|
+
validate_local(v, s, elem, local, d->type);
|
|
259
|
+
}
|
|
236
260
|
|
|
237
|
-
|
|
261
|
+
/* Validate one element against a type name that comes from a
|
|
262
|
+
* global declaration or a local particle: attributes and content
|
|
263
|
+
* model for complex types, lexical text otherwise. */
|
|
264
|
+
static void validate_local(struct xsd_validator* v,
|
|
265
|
+
struct leptris_xsd_schema* s,
|
|
266
|
+
LeptrisElement elem, const char* local,
|
|
267
|
+
const char* type) {
|
|
268
|
+
if (!type) return;
|
|
269
|
+
XsdCm* ct = xsd_find_complex(s, type);
|
|
238
270
|
if (ct) {
|
|
239
|
-
validate_attributes(v, s, elem, xsd_find_type_attrs(s,
|
|
271
|
+
validate_attributes(v, s, elem, xsd_find_type_attrs(s, type));
|
|
240
272
|
validate_children(v, s, elem, ct);
|
|
273
|
+
if (ct->text_type) {
|
|
274
|
+
const char* text = leptris_element_text(elem);
|
|
275
|
+
if (text && *text)
|
|
276
|
+
text_valid(v, s, ct->text_type, text, "element",
|
|
277
|
+
local);
|
|
278
|
+
}
|
|
241
279
|
return;
|
|
242
280
|
}
|
|
243
281
|
|
|
244
282
|
/* simple-typed element: text must be lexically valid */
|
|
245
|
-
if (strncmp(
|
|
246
|
-
xsd_find_simple_pub(s,
|
|
283
|
+
if (strncmp(type, "xs:", 3) == 0 ||
|
|
284
|
+
xsd_find_simple_pub(s, type)) {
|
|
247
285
|
const char* text = leptris_element_text(elem);
|
|
248
286
|
if (text && *text)
|
|
249
|
-
text_valid(v, s,
|
|
287
|
+
text_valid(v, s, type, text, "element", local);
|
|
250
288
|
}
|
|
251
289
|
}
|
|
252
290
|
|
|
@@ -9,18 +9,41 @@
|
|
|
9
9
|
extern "C" {
|
|
10
10
|
#endif
|
|
11
11
|
|
|
12
|
+
/* Opaque here: compile.c owns the definition; prototypes below
|
|
13
|
+
* take it by pointer only. */
|
|
14
|
+
struct leptris_xsd_schema;
|
|
15
|
+
|
|
12
16
|
/* One xs:enumeration / facet value, schema-owned. */
|
|
13
17
|
typedef struct xsd_facet_value {
|
|
14
18
|
char* text;
|
|
15
19
|
struct xsd_facet_value* next;
|
|
16
20
|
} XsdFacetValue;
|
|
17
21
|
|
|
22
|
+
/* How a user simpleType is derived: restriction of a base (with
|
|
23
|
+
* facets), a whitespace-separated list of an item type, or a
|
|
24
|
+
* union of member types. */
|
|
25
|
+
typedef enum {
|
|
26
|
+
XSD_SIMPLE_RESTRICT = 0,
|
|
27
|
+
XSD_SIMPLE_LIST,
|
|
28
|
+
XSD_SIMPLE_UNION
|
|
29
|
+
} XsdSimpleDeriv;
|
|
30
|
+
|
|
18
31
|
/* A user simpleType captured at compile time: name, restriction
|
|
19
32
|
* base (a built-in reference like "xs:integer" or another local
|
|
20
|
-
* simpleType name), and the facets the restriction carries.
|
|
33
|
+
* simpleType name), and the facets the restriction carries.
|
|
34
|
+
* List item types and union members arrive either as NAMES
|
|
35
|
+
* (resolved through the schema at validation) or as inline
|
|
36
|
+
* anonymous captures riding this type (freed with it). */
|
|
21
37
|
typedef struct xsd_simple {
|
|
22
38
|
char* name;
|
|
23
39
|
char* base;
|
|
40
|
+
XsdSimpleDeriv deriv;
|
|
41
|
+
char* item_type; /* LIST: builtin or local type name */
|
|
42
|
+
struct xsd_simple* item_def; /* LIST: inline anonymous item type */
|
|
43
|
+
char** members; /* UNION: named member type names */
|
|
44
|
+
size_t member_count;
|
|
45
|
+
struct xsd_simple** member_defs; /* UNION: inline members */
|
|
46
|
+
size_t member_def_count;
|
|
24
47
|
char* pattern;
|
|
25
48
|
XsdFacetValue* enum_values;
|
|
26
49
|
size_t enum_count;
|
|
@@ -37,6 +60,11 @@ typedef struct xsd_simple {
|
|
|
37
60
|
struct xsd_simple* next;
|
|
38
61
|
} XsdSimple;
|
|
39
62
|
|
|
63
|
+
/* Instance-path entry to the chain walker: resolves list item
|
|
64
|
+
* types and union member names through the schema. */
|
|
65
|
+
int xsd_simple_valid_chain(struct leptris_xsd_schema* s,
|
|
66
|
+
const XsdSimple* t, const char* v);
|
|
67
|
+
|
|
40
68
|
/* Content-model node: a particle (element ref / wildcard) or a
|
|
41
69
|
* group (sequence | choice | all). Owned by the schema; freed
|
|
42
70
|
* with the schema. */
|
|
@@ -45,7 +73,8 @@ typedef enum {
|
|
|
45
73
|
XSD_CM_ANY,
|
|
46
74
|
XSD_CM_SEQ,
|
|
47
75
|
XSD_CM_CHOICE,
|
|
48
|
-
XSD_CM_ALL
|
|
76
|
+
XSD_CM_ALL,
|
|
77
|
+
XSD_CM_GROUP_REF /* name holds the ref; expanded at NFA build */
|
|
49
78
|
} XsdCmKind;
|
|
50
79
|
|
|
51
80
|
typedef struct xsd_cm {
|
|
@@ -58,18 +87,40 @@ typedef struct xsd_cm {
|
|
|
58
87
|
int min, max; /* occurrence bounds; max < 0 = unbounded */
|
|
59
88
|
struct xsd_cm* first_child; /* group children list */
|
|
60
89
|
struct xsd_cm* next; /* sibling link within the parent group */
|
|
90
|
+
char* text_type; /* simpleContent wrapper: the text's type ref */
|
|
61
91
|
} XsdCm;
|
|
62
92
|
|
|
93
|
+
/* A top-level xs:group definition: name + the model its refs
|
|
94
|
+
* splice in (the definition's single sequence/choice/all). */
|
|
95
|
+
typedef struct xsd_group_def {
|
|
96
|
+
char* name;
|
|
97
|
+
XsdCm* model;
|
|
98
|
+
struct xsd_group_def* next;
|
|
99
|
+
} XsdGroupDef;
|
|
100
|
+
|
|
101
|
+
/* Group refs resolve through the schema at NFA-build time —
|
|
102
|
+
* forward references need no capture order. */
|
|
103
|
+
XsdGroupDef* xsd_find_group(struct leptris_xsd_schema* s,
|
|
104
|
+
const char* name);
|
|
105
|
+
|
|
63
106
|
/* A top-level xs:element declaration (slice 3: name + type ref). */
|
|
64
107
|
typedef struct xsd_element_decl {
|
|
65
108
|
char* name;
|
|
66
|
-
char* type;
|
|
109
|
+
char* type; /* "xs:string"-style builtin or a local type name */
|
|
110
|
+
char* fixed; /* fixed element content: text must string-equal it */
|
|
111
|
+
char* sub_head; /* substitutionGroup head (local name after ':') */
|
|
67
112
|
struct xsd_element_decl* next;
|
|
68
113
|
} XsdElementDecl;
|
|
69
114
|
|
|
115
|
+
/* Instance element `name` may bind a particle written for `head`
|
|
116
|
+
* when its substitutionGroup chain (depth-capped) reaches head. */
|
|
117
|
+
int xsd_is_substitute(struct leptris_xsd_schema* s,
|
|
118
|
+
const char* name, const char* head);
|
|
119
|
+
|
|
70
120
|
typedef struct xsd_attr_decl {
|
|
71
121
|
char* name; /* attribute local name */
|
|
72
122
|
char* type; /* builtin ref or local simpleType name (NULL=anySimple) */
|
|
123
|
+
char* fixed; /* #FIXED value: present values must string-equal it */
|
|
73
124
|
int required;
|
|
74
125
|
struct xsd_attr_decl* next;
|
|
75
126
|
} XsdAttrDecl;
|
|
@@ -96,6 +147,14 @@ typedef struct xsd_element_ics {
|
|
|
96
147
|
struct xsd_element_ics* next;
|
|
97
148
|
} XsdElementIcs;
|
|
98
149
|
|
|
150
|
+
/* A top-level xs:attributeGroup definition: name + its attribute
|
|
151
|
+
* rows (deep-copied into each referencing type at capture). */
|
|
152
|
+
typedef struct xsd_attrgroup_def {
|
|
153
|
+
char* name;
|
|
154
|
+
XsdAttrDecl* attrs;
|
|
155
|
+
struct xsd_attrgroup_def* next;
|
|
156
|
+
} XsdAttrGroupDef;
|
|
157
|
+
|
|
99
158
|
typedef struct xsd_type_attrs {
|
|
100
159
|
char* type_name;
|
|
101
160
|
XsdAttrDecl* attrs;
|
|
@@ -3066,7 +3066,7 @@ static void strip_source_whitespace(XsltExec* ex) {
|
|
|
3066
3066
|
* content decodes to a NUL-terminated "" (#1285 slice
|
|
3067
3067
|
* 4b — no overflow-table entry per stripped node). */
|
|
3068
3068
|
LeptrisTextNode* tn = (LeptrisTextNode*)c;
|
|
3069
|
-
leptris_textnode_set_content_ptr_doc(tn, "", ex->result);
|
|
3069
|
+
leptris_textnode_set_content_ptr_doc(tn, "", 0, ex->result);
|
|
3070
3070
|
tn->content_len = 0;
|
|
3071
3071
|
}
|
|
3072
3072
|
}
|
|
@@ -265,4 +265,9 @@ if(LEPTRIS_ENABLE_FUZZING)
|
|
|
265
265
|
target_link_libraries(fuzz_parse PRIVATE leptris)
|
|
266
266
|
target_include_directories(fuzz_parse PRIVATE
|
|
267
267
|
${PROJECT_SOURCE_DIR}/src/include)
|
|
268
|
+
# The harness doc and the nightly workflow invoke the binary at
|
|
269
|
+
# the build root, not under build/test/ where subdirectory
|
|
270
|
+
# targets land by default.
|
|
271
|
+
set_target_properties(fuzz_parse PROPERTIES
|
|
272
|
+
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
|
|
268
273
|
endif()
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
#include "leptris/error.h"
|
|
7
7
|
|
|
8
8
|
#include <cstring>
|
|
9
|
+
#include <cstdlib>
|
|
9
10
|
#include <string>
|
|
10
11
|
|
|
11
12
|
namespace {
|
|
@@ -630,3 +631,118 @@ TEST(ParseDoctype, SubsetBracketInsideQuotesAndComments) {
|
|
|
630
631
|
leptris_document_free(d);
|
|
631
632
|
}
|
|
632
633
|
}
|
|
634
|
+
|
|
635
|
+
/* Nightly-fuzz find (2026-10-09, artifact crash-0a24082b): a text
|
|
636
|
+
* run beginning with NUL bytes collapsed to the EMPTY sentinel —
|
|
637
|
+
* the content pointer read as "" while content_len kept the run's
|
|
638
|
+
* length, so serialize_text_internal walked past the 1-byte global
|
|
639
|
+
* (ASAN global-buffer-overflow). The setter is length-aware now:
|
|
640
|
+
* NUL-leading runs keep a real pointer and serialize verbatim. */
|
|
641
|
+
TEST(ParseNulTextRun, NulLeadingRunSerializesVerbatim) {
|
|
642
|
+
/* between </item> and <item>: eight NULs, newline, two spaces */
|
|
643
|
+
const char xml[] =
|
|
644
|
+
"<?xml version=\"1.0\"?>\n<r>\n <item id=\"1\">Hello</item>"
|
|
645
|
+
"\0\0\0\0\0\0\0\0\n <item id=\"2\">World</item>\n</r>\n";
|
|
646
|
+
size_t len = sizeof(xml) - 1;
|
|
647
|
+
LeptrisStatus st = LEPTRIS_OK;
|
|
648
|
+
LeptrisDocument d = leptris_parse_string(xml, len, &st);
|
|
649
|
+
ASSERT_NE(d, nullptr);
|
|
650
|
+
|
|
651
|
+
char* out = leptris_document_serialize(d, NULL);
|
|
652
|
+
ASSERT_NE(out, nullptr);
|
|
653
|
+
/* "Hello</item>" precedes every NUL, so strstr anchors safely;
|
|
654
|
+
* the run that follows must be the verbatim eight NULs + "\n ". */
|
|
655
|
+
const char* hello = strstr(out, "Hello</item>");
|
|
656
|
+
ASSERT_NE(hello, nullptr);
|
|
657
|
+
static const char needle[] =
|
|
658
|
+
"\0\0\0\0\0\0\0\0\n <item id=\"2\"";
|
|
659
|
+
EXPECT_EQ(memcmp(hello + strlen("Hello</item>"), needle,
|
|
660
|
+
sizeof(needle) - 1),
|
|
661
|
+
0)
|
|
662
|
+
<< "NUL-leading run not serialized verbatim";
|
|
663
|
+
leptris_free_string(out);
|
|
664
|
+
leptris_document_free(d);
|
|
665
|
+
}
|
|
666
|
+
|
|
667
|
+
/* Nightly-fuzz leak-75e0ee81: a duplicate-attribute RECOVER diag
|
|
668
|
+
* (heap-realloc'd by leptris_diag_emit) emitted before an eventual
|
|
669
|
+
* parse failure leaked — the dp fail path freed the line-break
|
|
670
|
+
* table but not the diag array. Leak visibility is the Linux CI
|
|
671
|
+
* ASAN job's (macOS cannot run LSan); this spec pins both paths:
|
|
672
|
+
* the failing parse (fail-path teardown) and the recovered parse
|
|
673
|
+
* (document_free owns the diags). */
|
|
674
|
+
TEST(ParseDiagTeardown, DuplicateAttrDiagBeforeFailureAndRecovery) {
|
|
675
|
+
LeptrisStatus st = LEPTRIS_OK;
|
|
676
|
+
/* duplicate attribute (RECOVER diag) then malformed tail */
|
|
677
|
+
const char bad[] = "<r a=\"1\" a=\"2\"<<<<";
|
|
678
|
+
EXPECT_EQ(leptris_parse_string(bad, strlen(bad), &st), nullptr);
|
|
679
|
+
EXPECT_NE(st, LEPTRIS_OK);
|
|
680
|
+
|
|
681
|
+
/* duplicate attribute, well-formed rest: the doc owns the diag */
|
|
682
|
+
const char ok[] = "<r a=\"1\" a=\"2\"/>";
|
|
683
|
+
LeptrisDocument d = leptris_parse_string(ok, strlen(ok), &st);
|
|
684
|
+
ASSERT_NE(d, nullptr);
|
|
685
|
+
leptris_document_free(d);
|
|
686
|
+
}
|
|
687
|
+
|
|
688
|
+
/* Nightly-fuzz crash-aac3c9bb: the fast-path "<?xml" probe bounded
|
|
689
|
+
* against the ABSOLUTE length while indexing from the first
|
|
690
|
+
* non-whitespace offset — " <?xm" (9 bytes, i=5) read d[i+4]
|
|
691
|
+
* one byte past the caller's buffer. The probe must bound against
|
|
692
|
+
* the remaining span. */
|
|
693
|
+
TEST(ParseFastPath, XmlDeclProbeStaysInBoundsAfterLeadingWhitespace) {
|
|
694
|
+
/* exact 9-byte heap buffer, fuzzer-shaped: a string literal's
|
|
695
|
+
* terminator would land the probe's read in bounds, and stack
|
|
696
|
+
* slots pad to 32 bytes (ASAN cannot see intra-object reads) */
|
|
697
|
+
const char shape[] = {' ', ' ', ' ', ' ', ' ', '<', '?', 'x', 'm'};
|
|
698
|
+
char* xml = (char*)malloc(sizeof(shape));
|
|
699
|
+
ASSERT_NE(xml, nullptr);
|
|
700
|
+
memcpy(xml, shape, sizeof(shape));
|
|
701
|
+
LeptrisStatus st = LEPTRIS_OK;
|
|
702
|
+
EXPECT_EQ(leptris_parse_string(xml, sizeof(shape), &st), nullptr);
|
|
703
|
+
EXPECT_NE(st, LEPTRIS_OK);
|
|
704
|
+
free(xml);
|
|
705
|
+
}
|
|
706
|
+
|
|
707
|
+
/* Nightly-fuzz leak-e3246602: a DOCTYPE internal subset with a
|
|
708
|
+
* DEFAULT attribute declaration grows the DTD model's heap
|
|
709
|
+
* default_decls array — and a subsequent parse failure never
|
|
710
|
+
* transferred p.dtd to the document, so the fail teardown missed
|
|
711
|
+
* it. Pins both paths; leak visibility is the Linux CI ASAN job. */
|
|
712
|
+
TEST(ParseFailTeardown, DtdModelBeforeFailureAndRecovery) {
|
|
713
|
+
LeptrisStatus st = LEPTRIS_OK;
|
|
714
|
+
const char bad[] =
|
|
715
|
+
"<!DOCTYPE r [<!ATTLIST r a CDATA \"x\">]><r><";
|
|
716
|
+
EXPECT_EQ(leptris_parse_string(bad, strlen(bad), &st), nullptr);
|
|
717
|
+
EXPECT_NE(st, LEPTRIS_OK);
|
|
718
|
+
|
|
719
|
+
const char ok[] =
|
|
720
|
+
"<!DOCTYPE r [<!ATTLIST r a CDATA \"x\">]><r/>";
|
|
721
|
+
LeptrisDocument d = leptris_parse_string(ok, strlen(ok), &st);
|
|
722
|
+
ASSERT_NE(d, nullptr);
|
|
723
|
+
leptris_document_free(d);
|
|
724
|
+
}
|
|
725
|
+
|
|
726
|
+
/* Nightly-fuzz leak-168da36a: a second <!DOCTYPE re-entered
|
|
727
|
+
* dp_parse_doctype with the first model still in hand —
|
|
728
|
+
* "dtd = parsed" orphaned it (its realloc'd default_decls array
|
|
729
|
+
* leaked). The lane is lenient about the duplicate, so the FIRST
|
|
730
|
+
* model wins, matching the duplicate-attribute keep-first rule;
|
|
731
|
+
* the replacement is freed. Observable: the first subset's
|
|
732
|
+
* entities keep expanding. */
|
|
733
|
+
TEST(ParseDoctype, SecondDoctypeKeepsFirstModel) {
|
|
734
|
+
const char xml[] =
|
|
735
|
+
"<!DOCTYPE a [<!ENTITY e \"first\">"
|
|
736
|
+
"<!ATTLIST a x CDATA \"d1\">]>"
|
|
737
|
+
"<!DOCTYPE a [<!ENTITY e \"second\">]>"
|
|
738
|
+
"<a>&e;</a>";
|
|
739
|
+
LeptrisStatus st = LEPTRIS_OK;
|
|
740
|
+
LeptrisDocument d = leptris_parse_string(xml, strlen(xml), &st);
|
|
741
|
+
ASSERT_NE(d, nullptr);
|
|
742
|
+
LeptrisElement root = leptris_document_root(d);
|
|
743
|
+
ASSERT_NE(root, nullptr);
|
|
744
|
+
const char* text = leptris_element_text(root);
|
|
745
|
+
ASSERT_NE(text, nullptr);
|
|
746
|
+
EXPECT_STREQ(text, "first");
|
|
747
|
+
leptris_document_free(d);
|
|
748
|
+
}
|