Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
asn1c
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
asn1c
Commits
beedbdeb
Commit
beedbdeb
authored
Sep 17, 2017
by
Lev Walkin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
get rid of undefined behavior and narrow supported entity reference range
parent
38306e10
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
7 deletions
+18
-7
skeletons/OCTET_STRING.c
skeletons/OCTET_STRING.c
+6
-4
tests/tests-skeletons/check-OCTET_STRING.c
tests/tests-skeletons/check-OCTET_STRING.c
+12
-3
No files found.
skeletons/OCTET_STRING.c
View file @
beedbdeb
...
...
@@ -936,16 +936,13 @@ static ssize_t OCTET_STRING__convert_binary(void *sptr, const void *chunk_buf, s
*/
static
int
OS__strtoent
(
int
base
,
const
char
*
buf
,
const
char
*
end
,
int32_t
*
ret_value
)
{
const
int32_t
last_unicode_codepoint
=
0x10ffff
;
int32_t
val
=
0
;
const
char
*
p
;
for
(
p
=
buf
;
p
<
end
;
p
++
)
{
int
ch
=
*
p
;
/* Strange huge value */
if
((
val
*
base
+
base
)
<
0
)
return
-
1
;
switch
(
ch
)
{
case
0x30
:
case
0x31
:
case
0x32
:
case
0x33
:
case
0x34
:
/*01234*/
case
0x35
:
case
0x36
:
case
0x37
:
case
0x38
:
case
0x39
:
/*56789*/
...
...
@@ -965,6 +962,11 @@ OS__strtoent(int base, const char *buf, const char *end, int32_t *ret_value) {
default:
return
-
1
;
/* Character set error */
}
/* Value exceeds the Unicode range. */
if
(
val
>
last_unicode_codepoint
)
{
return
-
1
;
}
}
*
ret_value
=
-
1
;
...
...
tests/tests-skeletons/check-OCTET_STRING.c
View file @
beedbdeb
...
...
@@ -8,8 +8,10 @@
enum
encoding_type
{
HEX
,
BINARY
,
UTF8
};
#define check(t, tag, buf, verify) check_impl(__LINE__, t, tag, buf, verify)
static
void
check
(
enum
encoding_type
type
,
char
*
tagname
,
char
*
xmlbuf
,
char
*
verify
)
{
check
_impl
(
int
lineno
,
enum
encoding_type
type
,
char
*
tagname
,
char
*
xmlbuf
,
char
*
verify
)
{
size_t
xmllen
=
strlen
(
xmlbuf
);
size_t
verlen
=
verify
?
strlen
(
verify
)
:
0
;
asn_TYPE_descriptor_t
*
td
=
&
asn_DEF_OCTET_STRING
;
...
...
@@ -32,8 +34,8 @@ check(enum encoding_type type, char *tagname, char *xmlbuf, char *verify) {
}
rc
=
decoder
(
0
,
td
,
(
void
**
)
stp
,
tagname
,
xmlbuf
,
xmllen
);
printf
(
"[%s] => [%s]:%zu vs [%s]:%zu, code %d
\n
"
,
xmlbuf
,
printf
(
"
%03d:
[%s] => [%s]:%zu vs [%s]:%zu, code %d
\n
"
,
lineno
,
xmlbuf
,
st
?
(
const
char
*
)
st
->
buf
:
""
,
st
?
st
->
size
:
0
,
verify
?
verify
:
""
,
verlen
,
rc
.
code
);
...
...
@@ -123,6 +125,13 @@ main() {
check
(
UTF8
,
"z"
,
"<z z z>a b</z z z>"
,
"a b"
);
check
(
UTF8
,
"z"
,
"<z z z>a b</z z z>"
,
"a b"
);
check
(
UTF8
,
"z"
,
"<z>a繃b</z>"
,
"a
\347\271\203
b"
);
check
(
UTF8
,
"z"
,
"<z>a俄|</z>"
,
"a
\xe4\xbf\x84
|"
);
/* Last unicode point */
check
(
UTF8
,
"z"
,
"<z>a|</z>"
,
"a
\xf4\x8f\xbf\xbf
|"
);
check
(
UTF8
,
"z"
,
"<z>a|</z>"
,
"a
\xf4\x8f\xbf\xbf
|"
);
/* One past the last unicode point */
check
(
UTF8
,
"z"
,
"<z>a�|</z>"
,
"a�|"
);
check
(
UTF8
,
"z"
,
"<z>a�|</z>"
,
"a�|"
);
check
(
UTF8
,
"z"
,
"<z>a�b</z>"
,
"a�b"
);
check
(
UTF8
,
"z"
,
"<z>a�b</z>"
,
"a�b"
);
check
(
UTF8
,
"z"
,
"<z>aĬ</z>"
,
"aĬ"
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment