Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
A
asn1c
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
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
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
qwebaby3
asn1c
Commits
22b81a8f
Commit
22b81a8f
authored
20 years ago
by
Lev Walkin
Browse files
Options
Downloads
Patches
Plain Diff
indefinite length check
parent
edefed0d
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
asn1c/tests/check-30.c
+113
-6
113 additions, 6 deletions
asn1c/tests/check-30.c
with
113 additions
and
6 deletions
asn1c/tests/check-30.c
+
113
−
6
View file @
22b81a8f
...
@@ -7,6 +7,10 @@
...
@@ -7,6 +7,10 @@
#include
<T.h>
#include
<T.h>
/*
* Test that the optional member (c) is really optional.
*/
uint8_t
buf1
[]
=
{
uint8_t
buf1
[]
=
{
32
|
17
,
/* [UNIVERSAL 17], constructed */
32
|
17
,
/* [UNIVERSAL 17], constructed */
8
,
/* L */
8
,
/* L */
...
@@ -42,17 +46,114 @@ uint8_t buf2[] = {
...
@@ -42,17 +46,114 @@ uint8_t buf2[] = {
97
,
97
,
};
};
/*
* This buffer checks that an unexpected member may be properly ignored.
*/
uint8_t
buf3
[]
=
{
32
|
17
,
/* [UNIVERSAL 17], constructed */
14
,
/* L */
/* a INTEGER */
64
|
3
,
/* [APPLICATION 3] */
1
,
/* L */
96
,
/* b IA5String */
22
,
/* [UNIVERSAL 22] */
3
,
/* L */
'x'
,
'y'
,
'z'
,
/* unexpected INTEGER */
64
|
4
,
/* [APPLICATION 4] */
1
,
/* L */
96
,
/* c [2] BOOLEAN */
((
2
<<
6
)
+
2
),
/* [2] */
1
,
/* L */
0xff
};
/*
* This buffer checks that an unexpected member may be properly ignored.
* This time, with indefinite length encoding.
*/
uint8_t
buf4
[]
=
{
32
|
17
,
/* [UNIVERSAL 17], constructed */
16
,
/* L */
/* a INTEGER */
64
|
3
,
/* [APPLICATION 3] */
1
,
/* L */
96
,
/* b IA5String */
22
,
/* [UNIVERSAL 22] */
3
,
/* L */
'x'
,
'y'
,
'z'
,
/* unexpected data structure */
32
|
64
|
4
,
/* [APPLICATION 4] */
0x80
,
/* indefinite L */
64
|
1
,
/* [APPLICATION 1] */
2
,
/* L */
'a'
,
'b'
,
0x00
,
0x00
};
/*
* This buffer checks that an unexpected member may be properly ignored.
* This time, with indefinite length encoding at the outer level too.
*/
uint8_t
buf5
[]
=
{
32
|
17
,
/* [UNIVERSAL 17], constructed */
0x80
,
/* indefinite L */
/* a INTEGER */
64
|
3
,
/* [APPLICATION 3] */
1
,
/* L */
96
,
/* b IA5String */
22
,
/* [UNIVERSAL 22] */
3
,
/* L */
'x'
,
'y'
,
'z'
,
/* unexpected data structure */
32
|
64
|
4
,
/* [APPLICATION 4] */
0x80
,
/* indefinite L */
64
|
1
,
/* [APPLICATION 1] */
2
,
/* L */
'a'
,
'b'
,
0x00
,
0x00
,
0x00
,
0x00
};
static
void
static
void
check
(
int
is_ok
,
uint8_t
*
buf
,
int
size
,
size_t
consumed
)
{
check
(
int
is_ok
,
uint8_t
*
buf
,
int
size
,
size_t
consumed
)
{
T_t
t
,
*
tp
;
T_t
t
,
*
tp
;
ber_dec_rval_t
rval
;
ber_dec_rval_t
rval
;
fprintf
(
stderr
,
"
\n
Must %s:
\n
"
,
is_ok
?
"suceed"
:
"fail"
);
tp
=
memset
(
&
t
,
0
,
sizeof
(
t
));
tp
=
memset
(
&
t
,
0
,
sizeof
(
t
));
fprintf
(
stderr
,
"Buf %p
\n
"
,
buf
);
fprintf
(
stderr
,
"Buf %p
\n
"
,
buf
);
rval
=
ber_decode
(
&
asn1_DEF_T
,
(
void
**
)
&
tp
,
buf
,
size
);
rval
=
ber_decode
(
&
asn1_DEF_T
,
(
void
**
)
&
tp
,
buf
,
size
);
fprintf
(
stderr
,
"Returned code %d, consumed %d
\n
"
,
fprintf
(
stderr
,
"Returned code %d, consumed %d
(out of %d)
\n
"
,
(
int
)
rval
.
code
,
(
int
)
rval
.
consumed
);
(
int
)
rval
.
code
,
(
int
)
rval
.
consumed
,
size
);
if
(
is_ok
)
{
if
(
is_ok
)
{
assert
(
rval
.
code
==
RC_OK
);
assert
(
rval
.
code
==
RC_OK
);
...
@@ -61,8 +162,12 @@ check(int is_ok, uint8_t *buf, int size, size_t consumed) {
...
@@ -61,8 +162,12 @@ check(int is_ok, uint8_t *buf, int size, size_t consumed) {
assert
(
t
.
a
.
size
==
1
);
assert
(
t
.
a
.
size
==
1
);
assert
(
t
.
a
.
buf
[
0
]
==
96
);
assert
(
t
.
a
.
buf
[
0
]
==
96
);
assert
(
t
.
b
.
size
==
3
);
assert
(
t
.
b
.
size
==
3
);
assert
(
t
.
c
==
0
);
assert
(
strcmp
(
t
.
b
.
buf
,
"xyz"
)
==
0
);
assert
(
strcmp
(
t
.
b
.
buf
,
"xyz"
)
==
0
);
if
(
buf
==
buf3
)
{
assert
(
t
.
c
->
value
);
}
else
{
assert
(
t
.
c
==
0
);
}
}
else
{
}
else
{
if
(
rval
.
code
==
RC_OK
)
{
if
(
rval
.
code
==
RC_OK
)
{
assert
(
t
.
a
.
size
!=
1
assert
(
t
.
a
.
size
!=
1
...
@@ -106,11 +211,13 @@ main(int ac, char **av) {
...
@@ -106,11 +211,13 @@ main(int ac, char **av) {
(
void
)
ac
;
/* Unused argument */
(
void
)
ac
;
/* Unused argument */
(
void
)
av
;
/* Unused argument */
(
void
)
av
;
/* Unused argument */
fprintf
(
stderr
,
"Must succeed:
\n
"
);
check
(
1
,
buf1
,
sizeof
(
buf1
)
+
20
,
sizeof
(
buf1
));
check
(
1
,
buf1
,
sizeof
(
buf1
)
+
20
,
sizeof
(
buf1
));
fprintf
(
stderr
,
"
\n
Must fail:
\n
"
);
check
(
0
,
buf2
,
sizeof
(
buf2
)
+
1
,
5
);
check
(
0
,
buf2
,
sizeof
(
buf2
)
+
1
,
5
);
check
(
1
,
buf3
,
sizeof
(
buf3
)
+
1
,
sizeof
(
buf3
));
check
(
1
,
buf4
,
sizeof
(
buf4
),
sizeof
(
buf4
));
check
(
1
,
buf5
,
sizeof
(
buf5
),
sizeof
(
buf5
));
check
(
1
,
buf5
,
sizeof
(
buf5
)
+
1
,
sizeof
(
buf5
));
check
(
0
,
buf5
,
sizeof
(
buf5
)
-
1
,
sizeof
(
buf5
));
fprintf
(
stderr
,
"
\n
Pseudo-random buffer corruptions must fail
\n
"
);
fprintf
(
stderr
,
"
\n
Pseudo-random buffer corruptions must fail
\n
"
);
try_corrupt
(
buf1
,
sizeof
(
buf1
));
try_corrupt
(
buf1
,
sizeof
(
buf1
));
...
...
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