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
3b2278aa
Commit
3b2278aa
authored
Jan 24, 2016
by
Lev Walkin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix overflow bug comparing ranges
parent
8be766aa
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
124 additions
and
9 deletions
+124
-9
.gitignore
.gitignore
+1
-1
libasn1fix/Makefile.am
libasn1fix/Makefile.am
+8
-6
libasn1fix/asn1fix_crange.c
libasn1fix/asn1fix_crange.c
+115
-2
No files found.
.gitignore
View file @
3b2278aa
...
@@ -66,7 +66,7 @@ doc/docsrc/*.xdv
...
@@ -66,7 +66,7 @@ doc/docsrc/*.xdv
# /libasn1fix/
# /libasn1fix/
/libasn1fix/Makefile
/libasn1fix/Makefile
/libasn1fix/check_
fixer
/libasn1fix/check_
*
# /libasn1parser/
# /libasn1parser/
/libasn1parser/Makefile
/libasn1parser/Makefile
...
...
libasn1fix/Makefile.am
View file @
3b2278aa
...
@@ -28,14 +28,16 @@ libasn1fix_la_SOURCES = \
...
@@ -28,14 +28,16 @@ libasn1fix_la_SOURCES = \
asn1fix_cws.c asn1fix_cws.h
\
asn1fix_cws.c asn1fix_cws.h
\
asn1fix_constraint_compat.c
asn1fix_constraint_compat.c
check_PROGRAMS
=
check_fixer
check_fixer_LDADD
=
$(noinst_LTLIBRARIES)
\
check_fixer_LDADD
=
$(noinst_LTLIBRARIES)
\
$(top_builddir)
/libasn1parser/libasn1parser.la
$(top_builddir)
/libasn1parser/libasn1parser.la
check_fixer_CPPFLAGS
=
-DTOP_SRCDIR
=
${top_srcdir}
$(AM_CPPFLAGS)
check_fixer_CPPFLAGS
=
-DTOP_SRCDIR
=
${top_srcdir}
$(AM_CPPFLAGS)
check_fixer_DEPENDENCIES
=
$(check_fixer_LDADD)
TESTS_ENVIRONMENT
=
./check_fixer
check_crange_SOURCES
=
asn1fix_crange.c asn1fix_constraint_compat.c
TESTS
=
${top_srcdir}
/tests/
*
.asn1
check_crange_CPPFLAGS
=
-DUNIT_TEST
$(AM_CPPFLAGS)
## TESTS = ${check_PROGRAMS} # This is an alternate form of testing
check_crange_LDADD
=
$(noinst_LTLIBRARIES)
\
$(top_builddir)
/libasn1parser/libasn1parser.la
check_PROGRAMS
=
check_crange check_fixer
TESTS
=
${check_PROGRAMS}
libasn1fix/asn1fix_crange.c
View file @
3b2278aa
...
@@ -158,6 +158,9 @@ _edge_value(const asn1cnst_edge_t *edge) {
...
@@ -158,6 +158,9 @@ _edge_value(const asn1cnst_edge_t *edge) {
case
ARE_MAX
:
strcpy
(
buf
,
"MAX"
);
break
;
case
ARE_MAX
:
strcpy
(
buf
,
"MAX"
);
break
;
case
ARE_VALUE
:
case
ARE_VALUE
:
snprintf
(
buf
,
sizeof
(
buf
),
"%"
PRIdASN
,
edge
->
value
);
snprintf
(
buf
,
sizeof
(
buf
),
"%"
PRIdASN
,
edge
->
value
);
break
;
default:
assert
(
!
"edge->type"
);
}
}
return
buf
;
return
buf
;
}
}
...
@@ -385,6 +388,19 @@ _range_overlap(const asn1cnst_range_t *ra, const asn1cnst_range_t *rb) {
...
@@ -385,6 +388,19 @@ _range_overlap(const asn1cnst_range_t *ra, const asn1cnst_range_t *rb) {
return
1
;
return
1
;
}
}
static
int
_range_partial_compare
(
const
void
*
pa
,
const
void
*
pb
)
{
const
asn1cnst_range_t
*
ra
=
*
(
const
void
*
const
*
)
pa
;
const
asn1cnst_range_t
*
rb
=
*
(
const
void
*
const
*
)
pb
;
return
_edge_compare
(
&
ra
->
left
,
&
rb
->
left
);
}
static
void
_range_partial_sort_elements
(
asn1cnst_range_t
*
r
)
{
qsort
(
r
->
elements
,
r
->
el_count
,
sizeof
(
r
->
elements
[
0
]),
_range_partial_compare
);
}
/*
/*
* (MIN..20) x (10..15) = (MIN..9,10..15,16..20)
* (MIN..20) x (10..15) = (MIN..9,10..15,16..20)
*/
*/
...
@@ -429,7 +445,7 @@ _range_split(asn1cnst_range_t *ra, const asn1cnst_range_t *rb) {
...
@@ -429,7 +445,7 @@ _range_split(asn1cnst_range_t *ra, const asn1cnst_range_t *rb) {
nr
->
left
=
ra
->
left
;
nr
->
left
=
ra
->
left
;
nr
->
right
=
rb
->
left
;
nr
->
right
=
rb
->
left
;
if
(
nr
->
right
.
type
==
ARE_VALUE
)
{
if
(
nr
->
right
.
type
==
ARE_VALUE
)
{
if
(
nr
->
right
.
value
-
1
>=
nr
->
right
.
value
)
{
if
(
nr
->
right
.
value
==
INTMAX_MIN
)
{
/* We've hit the limit here. */
/* We've hit the limit here. */
break
;
break
;
}
}
...
@@ -449,7 +465,7 @@ _range_split(asn1cnst_range_t *ra, const asn1cnst_range_t *rb) {
...
@@ -449,7 +465,7 @@ _range_split(asn1cnst_range_t *ra, const asn1cnst_range_t *rb) {
nr
->
left
=
rb
->
right
;
nr
->
left
=
rb
->
right
;
nr
->
right
=
ra
->
right
;
nr
->
right
=
ra
->
right
;
if
(
nr
->
left
.
type
==
ARE_VALUE
)
{
if
(
nr
->
left
.
type
==
ARE_VALUE
)
{
if
(
nr
->
left
.
value
+
1
<=
nr
->
left
.
value
)
{
if
(
nr
->
left
.
value
==
INTMAX_MAX
)
{
/* We've hit the limit here. */
/* We've hit the limit here. */
break
;
break
;
}
}
...
@@ -474,6 +490,8 @@ _range_split(asn1cnst_range_t *ra, const asn1cnst_range_t *rb) {
...
@@ -474,6 +490,8 @@ _range_split(asn1cnst_range_t *ra, const asn1cnst_range_t *rb) {
_range_insert
(
range
,
nr
);
_range_insert
(
range
,
nr
);
_range_partial_sort_elements
(
range
);
return
range
;
return
range
;
}
}
...
@@ -1017,3 +1035,98 @@ asn1constraint_compute_PER_range(asn1p_expr_type_e expr_type, const asn1p_constr
...
@@ -1017,3 +1035,98 @@ asn1constraint_compute_PER_range(asn1p_expr_type_e expr_type, const asn1p_constr
return
range
;
return
range
;
}
}
#ifdef UNIT_TEST
int
main
()
{
asn1cnst_range_t
*
ra
=
_range_new
();
asn1cnst_range_t
*
rb
=
_range_new
();
fprintf
(
stderr
,
"Testing (MIN..20) x (10..15) => (MIN..9,10..15,16..20)
\n
"
);
/* (MIN..20) */
ra
->
left
.
type
=
ARE_MIN
;
ra
->
right
.
type
=
ARE_VALUE
;
ra
->
right
.
value
=
20
;
/* (10..15) */
rb
->
left
.
type
=
ARE_VALUE
;
rb
->
left
.
value
=
10
;
rb
->
right
.
type
=
ARE_VALUE
;
rb
->
right
.
value
=
15
;
/*
* (MIN..20) x (10..15) = (MIN..9,10..15,16..20)
*/
asn1cnst_range_t
*
r
=
_range_split
(
ra
,
rb
);
assert
(
r
);
assert
(
r
->
left
.
type
==
ARE_MIN
);
assert
(
r
->
right
.
type
==
ARE_MAX
);
assert
(
r
->
el_count
==
3
);
assert
(
r
->
elements
[
0
]
->
elements
==
NULL
);
assert
(
r
->
elements
[
1
]
->
elements
==
NULL
);
assert
(
r
->
elements
[
2
]
->
elements
==
NULL
);
/* (MIN..9) */
fprintf
(
stderr
,
"[0].left = %s
\n
"
,
_edge_value
(
&
r
->
elements
[
0
]
->
left
));
fprintf
(
stderr
,
"[0].right = %s
\n
"
,
_edge_value
(
&
r
->
elements
[
0
]
->
right
));
assert
(
r
->
elements
[
0
]
->
left
.
type
==
ARE_MIN
);
assert
(
r
->
elements
[
0
]
->
right
.
type
==
ARE_VALUE
);
assert
(
r
->
elements
[
0
]
->
right
.
value
==
9
);
/* (10..15) */
fprintf
(
stderr
,
"[1].left = %s
\n
"
,
_edge_value
(
&
r
->
elements
[
1
]
->
left
));
fprintf
(
stderr
,
"[1].right = %s
\n
"
,
_edge_value
(
&
r
->
elements
[
1
]
->
right
));
assert
(
r
->
elements
[
1
]
->
left
.
type
==
ARE_VALUE
);
assert
(
r
->
elements
[
1
]
->
left
.
value
==
10
);
assert
(
r
->
elements
[
1
]
->
right
.
type
==
ARE_VALUE
);
assert
(
r
->
elements
[
1
]
->
right
.
value
==
15
);
/* (16..20) */
fprintf
(
stderr
,
"[2].left = %s
\n
"
,
_edge_value
(
&
r
->
elements
[
2
]
->
left
));
fprintf
(
stderr
,
"[2].right = %s
\n
"
,
_edge_value
(
&
r
->
elements
[
2
]
->
right
));
assert
(
r
->
elements
[
2
]
->
left
.
type
==
ARE_VALUE
);
assert
(
r
->
elements
[
2
]
->
left
.
value
==
16
);
assert
(
r
->
elements
[
2
]
->
right
.
type
==
ARE_VALUE
);
assert
(
r
->
elements
[
2
]
->
right
.
value
==
20
);
_range_free
(
r
);
fprintf
(
stderr
,
"Testing (MIN..20) x (<min>..15) => (<min>..15,16..20)
\n
"
);
/* (MIN..20) */
ra
->
left
.
type
=
ARE_MIN
;
ra
->
right
.
type
=
ARE_VALUE
;
ra
->
right
.
value
=
20
;
/* (<INTMAX_MIN>..15) */
rb
->
left
.
type
=
ARE_VALUE
;
rb
->
left
.
value
=
INTMAX_MIN
;
rb
->
right
.
type
=
ARE_VALUE
;
rb
->
right
.
value
=
15
;
r
=
_range_split
(
ra
,
rb
);
assert
(
r
);
assert
(
r
->
left
.
type
==
ARE_MIN
);
assert
(
r
->
right
.
type
==
ARE_MAX
);
assert
(
r
->
el_count
==
2
);
assert
(
r
->
elements
[
0
]
->
elements
==
NULL
);
assert
(
r
->
elements
[
1
]
->
elements
==
NULL
);
/* (<min>..16) */
fprintf
(
stderr
,
"[0].left = %s
\n
"
,
_edge_value
(
&
r
->
elements
[
0
]
->
left
));
fprintf
(
stderr
,
"[0].right = %s
\n
"
,
_edge_value
(
&
r
->
elements
[
0
]
->
right
));
assert
(
r
->
elements
[
0
]
->
left
.
type
==
ARE_VALUE
);
assert
(
r
->
elements
[
0
]
->
left
.
value
==
INTMAX_MIN
);
assert
(
r
->
elements
[
0
]
->
right
.
type
==
ARE_VALUE
);
assert
(
r
->
elements
[
0
]
->
right
.
value
==
15
);
/* (16..20) */
fprintf
(
stderr
,
"[1].left = %s
\n
"
,
_edge_value
(
&
r
->
elements
[
1
]
->
left
));
fprintf
(
stderr
,
"[1].right = %s
\n
"
,
_edge_value
(
&
r
->
elements
[
1
]
->
right
));
assert
(
r
->
elements
[
1
]
->
left
.
type
==
ARE_VALUE
);
assert
(
r
->
elements
[
1
]
->
left
.
value
==
16
);
assert
(
r
->
elements
[
1
]
->
right
.
type
==
ARE_VALUE
);
assert
(
r
->
elements
[
1
]
->
right
.
value
==
20
);
_range_free
(
r
);
return
0
;
}
#endif
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