Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
L
libxml2
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
OpenVMS
libraries
libxml2
Commits
59ae531015b2
Commit
59ae531015b2
authored
3 years ago
by
Tony Tascioglu
Browse files
Options
Downloads
Patches
Plain Diff
Make testchar return an error on failure
parent
25cd3480f0d8
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
testchar.c
+111
-46
111 additions, 46 deletions
testchar.c
with
111 additions
and
46 deletions
testchar.c
+
111
−
46
View file @
59ae5310
...
...
@@ -23,7 +23,7 @@
char
document1
[
100
]
=
"<doc>XXXX</doc>"
;
char
document2
[
100
]
=
"<doc foo='XXXX'/>"
;
static
void
testDocumentRangeByte1
(
xmlParserCtxtPtr
ctxt
,
char
*
document
,
static
int
testDocumentRangeByte1
(
xmlParserCtxtPtr
ctxt
,
char
*
document
,
int
len
,
char
*
data
,
int
forbid1
,
int
forbid2
)
{
int
i
;
xmlDocPtr
res
;
...
...
@@ -37,7 +37,7 @@
res
=
xmlReadMemory
(
document
,
len
,
"test"
,
NULL
,
0
);
if
((
i
==
forbid1
)
||
(
i
==
forbid2
))
{
if
((
lastError
==
0
)
||
(
res
!=
NULL
))
if
((
lastError
==
0
)
||
(
res
!=
NULL
))
{
fprintf
(
stderr
,
"Failed to detect invalid char for Byte 0x%02X: %c
\n
"
,
i
,
i
);
...
...
@@ -41,6 +41,8 @@
fprintf
(
stderr
,
"Failed to detect invalid char for Byte 0x%02X: %c
\n
"
,
i
,
i
);
return
(
1
);
}
}
else
if
((
i
==
'<'
)
||
(
i
==
'&'
))
{
...
...
@@ -44,6 +46,6 @@
}
else
if
((
i
==
'<'
)
||
(
i
==
'&'
))
{
if
((
lastError
==
0
)
||
(
res
!=
NULL
))
if
((
lastError
==
0
)
||
(
res
!=
NULL
))
{
fprintf
(
stderr
,
"Failed to detect illegal char %c for Byte 0x%02X
\n
"
,
i
,
i
);
...
...
@@ -48,5 +50,7 @@
fprintf
(
stderr
,
"Failed to detect illegal char %c for Byte 0x%02X
\n
"
,
i
,
i
);
return
(
1
);
}
}
else
if
(((
i
<
0x20
)
||
(
i
>=
0x80
))
&&
(
i
!=
0x9
)
&&
(
i
!=
0xA
)
&&
(
i
!=
0xD
))
{
...
...
@@ -50,6 +54,6 @@
}
else
if
(((
i
<
0x20
)
||
(
i
>=
0x80
))
&&
(
i
!=
0x9
)
&&
(
i
!=
0xA
)
&&
(
i
!=
0xD
))
{
if
((
lastError
!=
XML_ERR_INVALID_CHAR
)
&&
(
res
!=
NULL
))
if
((
lastError
!=
XML_ERR_INVALID_CHAR
)
&&
(
res
!=
NULL
))
{
fprintf
(
stderr
,
"Failed to detect invalid char for Byte 0x%02X
\n
"
,
i
);
...
...
@@ -54,6 +58,8 @@
fprintf
(
stderr
,
"Failed to detect invalid char for Byte 0x%02X
\n
"
,
i
);
return
(
1
);
}
}
else
if
(
res
==
NULL
)
{
fprintf
(
stderr
,
"Failed to parse valid char for Byte 0x%02X : %c
\n
"
,
i
,
i
);
...
...
@@ -56,8 +62,9 @@
}
else
if
(
res
==
NULL
)
{
fprintf
(
stderr
,
"Failed to parse valid char for Byte 0x%02X : %c
\n
"
,
i
,
i
);
return
(
1
);
}
if
(
res
!=
NULL
)
xmlFreeDoc
(
res
);
}
...
...
@@ -60,6 +67,7 @@
}
if
(
res
!=
NULL
)
xmlFreeDoc
(
res
);
}
return
(
0
);
}
...
...
@@ -64,6 +72,6 @@
}
static
void
testDocumentRangeByte2
(
xmlParserCtxtPtr
ctxt
,
char
*
document
,
static
int
testDocumentRangeByte2
(
xmlParserCtxtPtr
ctxt
,
char
*
document
,
int
len
,
char
*
data
)
{
int
i
,
j
;
xmlDocPtr
res
;
...
...
@@ -80,7 +88,7 @@
/* if first bit of first char is set, then second bit must too */
if
((
i
&
0x80
)
&&
((
i
&
0x40
)
==
0
))
{
if
((
lastError
==
0
)
||
(
res
!=
NULL
))
if
((
lastError
==
0
)
||
(
res
!=
NULL
))
{
fprintf
(
stderr
,
"Failed to detect invalid char for Bytes 0x%02X 0x%02X
\n
"
,
i
,
j
);
...
...
@@ -84,6 +92,8 @@
fprintf
(
stderr
,
"Failed to detect invalid char for Bytes 0x%02X 0x%02X
\n
"
,
i
,
j
);
return
(
1
);
}
}
/*
...
...
@@ -91,7 +101,7 @@
* bits must be 10
*/
else
if
((
i
&
0x80
)
&&
((
j
&
0xC0
)
!=
0x80
))
{
if
((
lastError
==
0
)
||
(
res
!=
NULL
))
if
((
lastError
==
0
)
||
(
res
!=
NULL
))
{
fprintf
(
stderr
,
"Failed to detect invalid char for Bytes 0x%02X 0x%02X
\n
"
,
i
,
j
);
...
...
@@ -95,6 +105,8 @@
fprintf
(
stderr
,
"Failed to detect invalid char for Bytes 0x%02X 0x%02X
\n
"
,
i
,
j
);
return
(
1
);
}
}
/*
...
...
@@ -102,7 +114,7 @@
* than 0x80, i.e. one of bits 5 to 1 of i must be set
*/
else
if
((
i
&
0x80
)
&&
((
i
&
0x1E
)
==
0
))
{
if
((
lastError
==
0
)
||
(
res
!=
NULL
))
if
((
lastError
==
0
)
||
(
res
!=
NULL
))
{
fprintf
(
stderr
,
"Failed to detect invalid char for Bytes 0x%02X 0x%02X
\n
"
,
i
,
j
);
...
...
@@ -106,6 +118,8 @@
fprintf
(
stderr
,
"Failed to detect invalid char for Bytes 0x%02X 0x%02X
\n
"
,
i
,
j
);
return
(
1
);
}
}
/*
...
...
@@ -113,7 +127,7 @@
* at least 3 bytes, but we give only 2 !
*/
else
if
((
i
&
0xE0
)
==
0xE0
)
{
if
((
lastError
==
0
)
||
(
res
!=
NULL
))
if
((
lastError
==
0
)
||
(
res
!=
NULL
))
{
fprintf
(
stderr
,
"Failed to detect invalid char for Bytes 0x%02X 0x%02X 0x00
\n
"
,
i
,
j
);
...
...
@@ -117,6 +131,8 @@
fprintf
(
stderr
,
"Failed to detect invalid char for Bytes 0x%02X 0x%02X 0x00
\n
"
,
i
,
j
);
return
(
1
);
}
}
/*
...
...
@@ -125,8 +141,9 @@
else
if
((
lastError
!=
0
)
||
(
res
==
NULL
))
{
fprintf
(
stderr
,
"Failed to parse document for Bytes 0x%02X 0x%02X
\n
"
,
i
,
j
);
return
(
1
);
}
if
(
res
!=
NULL
)
xmlFreeDoc
(
res
);
}
}
...
...
@@ -128,8 +145,9 @@
}
if
(
res
!=
NULL
)
xmlFreeDoc
(
res
);
}
}
return
(
0
);
}
/**
...
...
@@ -141,6 +159,6 @@
* CDATA in text or in attribute values.
*/
static
void
testDocumentRanges
(
void
)
{
static
int
testDocumentRanges
(
void
)
{
xmlParserCtxtPtr
ctxt
;
char
*
data
;
...
...
@@ -145,5 +163,6 @@
xmlParserCtxtPtr
ctxt
;
char
*
data
;
int
test_ret
=
0
;
/*
* Set up a parsing context using the first document as
...
...
@@ -152,7 +171,7 @@
ctxt
=
xmlNewParserCtxt
();
if
(
ctxt
==
NULL
)
{
fprintf
(
stderr
,
"Failed to allocate parser context
\n
"
);
return
;
return
(
1
)
;
}
printf
(
"testing 1 byte char in document: 1"
);
...
...
@@ -163,7 +182,7 @@
data
[
2
]
=
' '
;
data
[
3
]
=
' '
;
/* test 1 byte injection at beginning of area */
testDocumentRangeByte1
(
ctxt
,
&
document1
[
0
],
strlen
(
document1
),
test_ret
+=
testDocumentRangeByte1
(
ctxt
,
&
document1
[
0
],
strlen
(
document1
),
data
,
-
1
,
-
1
);
printf
(
" 2"
);
fflush
(
stdout
);
...
...
@@ -172,7 +191,7 @@
data
[
2
]
=
' '
;
data
[
3
]
=
' '
;
/* test 1 byte injection at end of area */
testDocumentRangeByte1
(
ctxt
,
&
document1
[
0
],
strlen
(
document1
),
test_ret
+=
testDocumentRangeByte1
(
ctxt
,
&
document1
[
0
],
strlen
(
document1
),
data
+
3
,
-
1
,
-
1
);
printf
(
" 3"
);
...
...
@@ -183,7 +202,7 @@
data
[
2
]
=
' '
;
data
[
3
]
=
' '
;
/* test 1 byte injection at beginning of area */
testDocumentRangeByte1
(
ctxt
,
&
document2
[
0
],
strlen
(
document2
),
test_ret
+=
testDocumentRangeByte1
(
ctxt
,
&
document2
[
0
],
strlen
(
document2
),
data
,
'\''
,
-
1
);
printf
(
" 4"
);
fflush
(
stdout
);
...
...
@@ -192,7 +211,7 @@
data
[
2
]
=
' '
;
data
[
3
]
=
' '
;
/* test 1 byte injection at end of area */
testDocumentRangeByte1
(
ctxt
,
&
document2
[
0
],
strlen
(
document2
),
test_ret
+=
testDocumentRangeByte1
(
ctxt
,
&
document2
[
0
],
strlen
(
document2
),
data
+
3
,
'\''
,
-
1
);
printf
(
" done
\n
"
);
...
...
@@ -204,7 +223,7 @@
data
[
2
]
=
' '
;
data
[
3
]
=
' '
;
/* test 2 byte injection at beginning of area */
testDocumentRangeByte2
(
ctxt
,
&
document1
[
0
],
strlen
(
document1
),
test_ret
+=
testDocumentRangeByte2
(
ctxt
,
&
document1
[
0
],
strlen
(
document1
),
data
);
printf
(
" 2"
);
fflush
(
stdout
);
...
...
@@ -213,7 +232,7 @@
data
[
2
]
=
' '
;
data
[
3
]
=
' '
;
/* test 2 byte injection at end of area */
testDocumentRangeByte2
(
ctxt
,
&
document1
[
0
],
strlen
(
document1
),
test_ret
+=
testDocumentRangeByte2
(
ctxt
,
&
document1
[
0
],
strlen
(
document1
),
data
+
2
);
printf
(
" 3"
);
...
...
@@ -224,7 +243,7 @@
data
[
2
]
=
' '
;
data
[
3
]
=
' '
;
/* test 2 byte injection at beginning of area */
testDocumentRangeByte2
(
ctxt
,
&
document2
[
0
],
strlen
(
document2
),
test_ret
+=
testDocumentRangeByte2
(
ctxt
,
&
document2
[
0
],
strlen
(
document2
),
data
);
printf
(
" 4"
);
fflush
(
stdout
);
...
...
@@ -233,8 +252,8 @@
data
[
2
]
=
' '
;
data
[
3
]
=
' '
;
/* test 2 byte injection at end of area */
testDocumentRangeByte2
(
ctxt
,
&
document2
[
0
],
strlen
(
document2
),
test_ret
+=
testDocumentRangeByte2
(
ctxt
,
&
document2
[
0
],
strlen
(
document2
),
data
+
2
);
printf
(
" done
\n
"
);
xmlFreeParserCtxt
(
ctxt
);
...
...
@@ -237,6 +256,7 @@
data
+
2
);
printf
(
" done
\n
"
);
xmlFreeParserCtxt
(
ctxt
);
return
(
test_ret
);
}
...
...
@@ -241,6 +261,6 @@
}
static
void
testCharRangeByte1
(
xmlParserCtxtPtr
ctxt
,
char
*
data
)
{
static
int
testCharRangeByte1
(
xmlParserCtxtPtr
ctxt
,
char
*
data
)
{
int
i
=
0
;
int
len
,
c
;
...
...
@@ -255,6 +275,6 @@
c
=
xmlCurrentChar
(
ctxt
,
&
len
);
if
((
i
==
0
)
||
(
i
>=
0x80
))
{
/* we must see an error there */
if
(
lastError
!=
XML_ERR_INVALID_CHAR
)
if
(
lastError
!=
XML_ERR_INVALID_CHAR
)
{
fprintf
(
stderr
,
"Failed to detect invalid char for Byte 0x%02X
\n
"
,
i
);
...
...
@@ -259,3 +279,5 @@
fprintf
(
stderr
,
"Failed to detect invalid char for Byte 0x%02X
\n
"
,
i
);
return
(
1
);
}
}
else
if
(
i
==
0xD
)
{
...
...
@@ -261,3 +283,3 @@
}
else
if
(
i
==
0xD
)
{
if
((
c
!=
0xA
)
||
(
len
!=
1
))
if
((
c
!=
0xA
)
||
(
len
!=
1
))
{
fprintf
(
stderr
,
"Failed to convert char for Byte 0x%02X
\n
"
,
i
);
...
...
@@ -263,3 +285,5 @@
fprintf
(
stderr
,
"Failed to convert char for Byte 0x%02X
\n
"
,
i
);
return
(
1
);
}
}
else
if
((
c
!=
i
)
||
(
len
!=
1
))
{
fprintf
(
stderr
,
"Failed to parse char for Byte 0x%02X
\n
"
,
i
);
...
...
@@ -264,5 +288,5 @@
}
else
if
((
c
!=
i
)
||
(
len
!=
1
))
{
fprintf
(
stderr
,
"Failed to parse char for Byte 0x%02X
\n
"
,
i
);
}
return
(
1
);
}
}
...
...
@@ -267,3 +291,5 @@
}
}
return
(
0
);
}
...
...
@@ -269,5 +295,5 @@
static
void
testCharRangeByte2
(
xmlParserCtxtPtr
ctxt
,
char
*
data
)
{
static
int
testCharRangeByte2
(
xmlParserCtxtPtr
ctxt
,
char
*
data
)
{
int
i
,
j
;
int
len
,
c
;
...
...
@@ -284,7 +310,7 @@
/* if first bit of first char is set, then second bit must too */
if
((
i
&
0x80
)
&&
((
i
&
0x40
)
==
0
))
{
if
(
lastError
!=
XML_ERR_INVALID_CHAR
)
if
(
lastError
!=
XML_ERR_INVALID_CHAR
)
{
fprintf
(
stderr
,
"Failed to detect invalid char for Bytes 0x%02X 0x%02X
\n
"
,
i
,
j
);
...
...
@@ -288,6 +314,8 @@
fprintf
(
stderr
,
"Failed to detect invalid char for Bytes 0x%02X 0x%02X
\n
"
,
i
,
j
);
return
(
1
);
}
}
/*
...
...
@@ -295,7 +323,7 @@
* bits must be 10
*/
else
if
((
i
&
0x80
)
&&
((
j
&
0xC0
)
!=
0x80
))
{
if
(
lastError
!=
XML_ERR_INVALID_CHAR
)
if
(
lastError
!=
XML_ERR_INVALID_CHAR
)
{
fprintf
(
stderr
,
"Failed to detect invalid char for Bytes 0x%02X 0x%02X: %d
\n
"
,
i
,
j
,
c
);
...
...
@@ -299,6 +327,8 @@
fprintf
(
stderr
,
"Failed to detect invalid char for Bytes 0x%02X 0x%02X: %d
\n
"
,
i
,
j
,
c
);
return
(
1
);
}
}
/*
...
...
@@ -306,7 +336,7 @@
* than 0x80, i.e. one of bits 5 to 1 of i must be set
*/
else
if
((
i
&
0x80
)
&&
((
i
&
0x1E
)
==
0
))
{
if
(
lastError
!=
XML_ERR_INVALID_CHAR
)
if
(
lastError
!=
XML_ERR_INVALID_CHAR
)
{
fprintf
(
stderr
,
"Failed to detect invalid char for Bytes 0x%02X 0x%02X: %d
\n
"
,
i
,
j
,
c
);
...
...
@@ -310,6 +340,8 @@
fprintf
(
stderr
,
"Failed to detect invalid char for Bytes 0x%02X 0x%02X: %d
\n
"
,
i
,
j
,
c
);
return
(
1
);
}
}
/*
...
...
@@ -317,7 +349,7 @@
* at least 3 bytes, but we give only 2 !
*/
else
if
((
i
&
0xE0
)
==
0xE0
)
{
if
(
lastError
!=
XML_ERR_INVALID_CHAR
)
if
(
lastError
!=
XML_ERR_INVALID_CHAR
)
{
fprintf
(
stderr
,
"Failed to detect invalid char for Bytes 0x%02X 0x%02X 0x00
\n
"
,
i
,
j
);
...
...
@@ -321,6 +353,8 @@
fprintf
(
stderr
,
"Failed to detect invalid char for Bytes 0x%02X 0x%02X 0x00
\n
"
,
i
,
j
);
return
(
1
);
}
}
/*
...
...
@@ -329,6 +363,7 @@
else
if
((
lastError
!=
0
)
||
(
len
!=
2
))
{
fprintf
(
stderr
,
"Failed to parse char for Bytes 0x%02X 0x%02X
\n
"
,
i
,
j
);
return
(
1
);
}
/*
...
...
@@ -338,6 +373,7 @@
fprintf
(
stderr
,
"Failed to parse char for Bytes 0x%02X 0x%02X: expect %d got %d
\n
"
,
i
,
j
,
((
j
&
0x3F
)
+
((
i
&
0x1F
)
<<
6
)),
c
);
return
(
1
);
}
}
}
...
...
@@ -341,5 +377,6 @@
}
}
}
return
(
0
);
}
...
...
@@ -344,6 +381,6 @@
}
static
void
testCharRangeByte3
(
xmlParserCtxtPtr
ctxt
,
char
*
data
)
{
static
int
testCharRangeByte3
(
xmlParserCtxtPtr
ctxt
,
char
*
data
)
{
int
i
,
j
,
k
,
K
;
int
len
,
c
;
unsigned
char
lows
[
6
]
=
{
0
,
0x80
,
0x81
,
0xC1
,
0xFF
,
0xBF
};
...
...
@@ -368,7 +405,7 @@
* at least 4 bytes, but we give only 3 !
*/
if
((
i
&
0xF0
)
==
0xF0
)
{
if
(
lastError
!=
XML_ERR_INVALID_CHAR
)
if
(
lastError
!=
XML_ERR_INVALID_CHAR
)
{
fprintf
(
stderr
,
"Failed to detect invalid char for Bytes 0x%02X 0x%02X 0x%02X 0x%02X
\n
"
,
i
,
j
,
K
,
data
[
3
]);
...
...
@@ -372,9 +409,11 @@
fprintf
(
stderr
,
"Failed to detect invalid char for Bytes 0x%02X 0x%02X 0x%02X 0x%02X
\n
"
,
i
,
j
,
K
,
data
[
3
]);
return
(
1
);
}
}
/*
* The second and the third bytes must start with 10
*/
else
if
(((
j
&
0xC0
)
!=
0x80
)
||
((
K
&
0xC0
)
!=
0x80
))
{
...
...
@@ -375,10 +414,10 @@
}
/*
* The second and the third bytes must start with 10
*/
else
if
(((
j
&
0xC0
)
!=
0x80
)
||
((
K
&
0xC0
)
!=
0x80
))
{
if
(
lastError
!=
XML_ERR_INVALID_CHAR
)
if
(
lastError
!=
XML_ERR_INVALID_CHAR
)
{
fprintf
(
stderr
,
"Failed to detect invalid char for Bytes 0x%02X 0x%02X 0x%02X
\n
"
,
i
,
j
,
K
);
...
...
@@ -382,6 +421,8 @@
fprintf
(
stderr
,
"Failed to detect invalid char for Bytes 0x%02X 0x%02X 0x%02X
\n
"
,
i
,
j
,
K
);
return
(
1
);
}
}
/*
...
...
@@ -390,7 +431,7 @@
* the 6th byte of data[1] must be set
*/
else
if
(((
i
&
0xF
)
==
0
)
&&
((
j
&
0x20
)
==
0
))
{
if
(
lastError
!=
XML_ERR_INVALID_CHAR
)
if
(
lastError
!=
XML_ERR_INVALID_CHAR
)
{
fprintf
(
stderr
,
"Failed to detect invalid char for Bytes 0x%02X 0x%02X 0x%02X
\n
"
,
i
,
j
,
K
);
...
...
@@ -394,6 +435,8 @@
fprintf
(
stderr
,
"Failed to detect invalid char for Bytes 0x%02X 0x%02X 0x%02X
\n
"
,
i
,
j
,
K
);
return
(
1
);
}
}
/*
...
...
@@ -401,7 +444,7 @@
*/
else
if
(((
value
>
0xD7FF
)
&&
(
value
<
0xE000
))
||
((
value
>
0xFFFD
)
&&
(
value
<
0x10000
)))
{
if
(
lastError
!=
XML_ERR_INVALID_CHAR
)
if
(
lastError
!=
XML_ERR_INVALID_CHAR
)
{
fprintf
(
stderr
,
"Failed to detect invalid char 0x%04X for Bytes 0x%02X 0x%02X 0x%02X
\n
"
,
value
,
i
,
j
,
K
);
...
...
@@ -405,6 +448,8 @@
fprintf
(
stderr
,
"Failed to detect invalid char 0x%04X for Bytes 0x%02X 0x%02X 0x%02X
\n
"
,
value
,
i
,
j
,
K
);
return
(
1
);
}
}
/*
...
...
@@ -414,6 +459,7 @@
fprintf
(
stderr
,
"Failed to parse char for Bytes 0x%02X 0x%02X 0x%02X
\n
"
,
i
,
j
,
K
);
return
(
1
);
}
/*
...
...
@@ -423,7 +469,8 @@
fprintf
(
stderr
,
"Failed to parse char for Bytes 0x%02X 0x%02X 0x%02X: expect %d got %d
\n
"
,
i
,
j
,
data
[
2
],
value
,
c
);
return
(
1
);
}
}
}
}
...
...
@@ -426,6 +473,7 @@
}
}
}
}
return
(
0
);
}
...
...
@@ -430,6 +478,6 @@
}
static
void
testCharRangeByte4
(
xmlParserCtxtPtr
ctxt
,
char
*
data
)
{
static
int
testCharRangeByte4
(
xmlParserCtxtPtr
ctxt
,
char
*
data
)
{
int
i
,
j
,
k
,
K
,
l
,
L
;
int
len
,
c
;
unsigned
char
lows
[
6
]
=
{
0
,
0x80
,
0x81
,
0xC1
,
0xFF
,
0xBF
};
...
...
@@ -458,7 +506,7 @@
* at least 5 bytes, but we give only 4 !
*/
if
((
i
&
0xF8
)
==
0xF8
)
{
if
(
lastError
!=
XML_ERR_INVALID_CHAR
)
if
(
lastError
!=
XML_ERR_INVALID_CHAR
)
{
fprintf
(
stderr
,
"Failed to detect invalid char for Bytes 0x%02X 0x%02X 0x%02X 0x%02X
\n
"
,
i
,
j
,
K
,
data
[
3
]);
...
...
@@ -462,6 +510,8 @@
fprintf
(
stderr
,
"Failed to detect invalid char for Bytes 0x%02X 0x%02X 0x%02X 0x%02X
\n
"
,
i
,
j
,
K
,
data
[
3
]);
return
(
1
);
}
}
/*
...
...
@@ -469,7 +519,7 @@
*/
else
if
(((
j
&
0xC0
)
!=
0x80
)
||
((
K
&
0xC0
)
!=
0x80
)
||
((
L
&
0xC0
)
!=
0x80
))
{
if
(
lastError
!=
XML_ERR_INVALID_CHAR
)
if
(
lastError
!=
XML_ERR_INVALID_CHAR
)
{
fprintf
(
stderr
,
"Failed to detect invalid char for Bytes 0x%02X 0x%02X 0x%02X 0x%02X
\n
"
,
i
,
j
,
K
,
L
);
...
...
@@ -473,6 +523,8 @@
fprintf
(
stderr
,
"Failed to detect invalid char for Bytes 0x%02X 0x%02X 0x%02X 0x%02X
\n
"
,
i
,
j
,
K
,
L
);
return
(
1
);
}
}
/*
...
...
@@ -481,7 +533,7 @@
* the 6 or 5th byte of j must be set
*/
else
if
(((
i
&
0x7
)
==
0
)
&&
((
j
&
0x30
)
==
0
))
{
if
(
lastError
!=
XML_ERR_INVALID_CHAR
)
if
(
lastError
!=
XML_ERR_INVALID_CHAR
)
{
fprintf
(
stderr
,
"Failed to detect invalid char for Bytes 0x%02X 0x%02X 0x%02X 0x%02X
\n
"
,
i
,
j
,
K
,
L
);
...
...
@@ -485,6 +537,8 @@
fprintf
(
stderr
,
"Failed to detect invalid char for Bytes 0x%02X 0x%02X 0x%02X 0x%02X
\n
"
,
i
,
j
,
K
,
L
);
return
(
1
);
}
}
/*
...
...
@@ -493,7 +547,7 @@
else
if
(((
value
>
0xD7FF
)
&&
(
value
<
0xE000
))
||
((
value
>
0xFFFD
)
&&
(
value
<
0x10000
))
||
(
value
>
0x10FFFF
))
{
if
(
lastError
!=
XML_ERR_INVALID_CHAR
)
if
(
lastError
!=
XML_ERR_INVALID_CHAR
)
{
fprintf
(
stderr
,
"Failed to detect invalid char 0x%04X for Bytes 0x%02X 0x%02X 0x%02X 0x%02X
\n
"
,
value
,
i
,
j
,
K
,
L
);
...
...
@@ -497,6 +551,8 @@
fprintf
(
stderr
,
"Failed to detect invalid char 0x%04X for Bytes 0x%02X 0x%02X 0x%02X 0x%02X
\n
"
,
value
,
i
,
j
,
K
,
L
);
return
(
1
);
}
}
/*
...
...
@@ -506,6 +562,7 @@
fprintf
(
stderr
,
"Failed to parse char for Bytes 0x%02X 0x%02X 0x%02X
\n
"
,
i
,
j
,
K
);
return
(
1
);
}
/*
...
...
@@ -515,8 +572,9 @@
fprintf
(
stderr
,
"Failed to parse char for Bytes 0x%02X 0x%02X 0x%02X: expect %d got %d
\n
"
,
i
,
j
,
data
[
2
],
value
,
c
);
return
(
1
);
}
}
}
}
}
...
...
@@ -518,8 +576,9 @@
}
}
}
}
}
return
(
0
);
}
/**
...
...
@@ -530,8 +589,8 @@
* cover the full range of UTF-8 chars accepted by XML-1.0
*/
static
void
testCharRanges
(
void
)
{
static
int
testCharRanges
(
void
)
{
char
data
[
5
];
xmlParserCtxtPtr
ctxt
;
xmlParserInputBufferPtr
buf
;
xmlParserInputPtr
input
;
...
...
@@ -534,7 +593,8 @@
char
data
[
5
];
xmlParserCtxtPtr
ctxt
;
xmlParserInputBufferPtr
buf
;
xmlParserInputPtr
input
;
int
test_ret
=
0
;
memset
(
data
,
0
,
5
);
...
...
@@ -545,9 +605,9 @@
ctxt
=
xmlNewParserCtxt
();
if
(
ctxt
==
NULL
)
{
fprintf
(
stderr
,
"Failed to allocate parser context
\n
"
);
return
;
return
(
1
)
;
}
buf
=
xmlParserInputBufferCreateStatic
(
data
,
sizeof
(
data
),
XML_CHAR_ENCODING_NONE
);
if
(
buf
==
NULL
)
{
fprintf
(
stderr
,
"Failed to allocate input buffer
\n
"
);
...
...
@@ -549,10 +609,11 @@
}
buf
=
xmlParserInputBufferCreateStatic
(
data
,
sizeof
(
data
),
XML_CHAR_ENCODING_NONE
);
if
(
buf
==
NULL
)
{
fprintf
(
stderr
,
"Failed to allocate input buffer
\n
"
);
test_ret
=
1
;
goto
error
;
}
input
=
xmlNewInputStream
(
ctxt
);
if
(
input
==
NULL
)
{
xmlFreeParserInputBuffer
(
buf
);
...
...
@@ -554,8 +615,9 @@
goto
error
;
}
input
=
xmlNewInputStream
(
ctxt
);
if
(
input
==
NULL
)
{
xmlFreeParserInputBuffer
(
buf
);
test_ret
=
1
;
goto
error
;
}
input
->
filename
=
NULL
;
...
...
@@ -567,6 +629,6 @@
printf
(
"testing char range: 1"
);
fflush
(
stdout
);
testCharRangeByte1
(
ctxt
,
data
);
test_ret
+=
testCharRangeByte1
(
ctxt
,
data
);
printf
(
" 2"
);
fflush
(
stdout
);
...
...
@@ -571,5 +633,5 @@
printf
(
" 2"
);
fflush
(
stdout
);
testCharRangeByte2
(
ctxt
,
data
);
test_ret
+=
testCharRangeByte2
(
ctxt
,
data
);
printf
(
" 3"
);
fflush
(
stdout
);
...
...
@@ -574,5 +636,5 @@
printf
(
" 3"
);
fflush
(
stdout
);
testCharRangeByte3
(
ctxt
,
data
);
test_ret
+=
testCharRangeByte3
(
ctxt
,
data
);
printf
(
" 4"
);
fflush
(
stdout
);
...
...
@@ -577,8 +639,8 @@
printf
(
" 4"
);
fflush
(
stdout
);
testCharRangeByte4
(
ctxt
,
data
);
test_ret
+=
testCharRangeByte4
(
ctxt
,
data
);
printf
(
" done
\n
"
);
fflush
(
stdout
);
error:
xmlFreeParserCtxt
(
ctxt
);
...
...
@@ -580,9 +642,10 @@
printf
(
" done
\n
"
);
fflush
(
stdout
);
error:
xmlFreeParserCtxt
(
ctxt
);
return
(
test_ret
);
}
int
main
(
void
)
{
...
...
@@ -585,7 +648,9 @@
}
int
main
(
void
)
{
int
ret
=
0
;
/*
* this initialize the library and check potential ABI mismatches
* between the version it was compiled for and the actual shared
...
...
@@ -602,8 +667,8 @@
/*
* Run the tests
*/
testCharRanges
();
testDocumentRanges
();
ret
+=
testCharRanges
();
ret
+=
testDocumentRanges
();
/*
* Cleanup function for the XML library.
...
...
@@ -613,5 +678,5 @@
* this is to debug memory for regression tests
*/
xmlMemoryDump
();
return
(
0
);
return
(
ret
?
1
:
0
);
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment