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
6cbed3dd
Commit
6cbed3dd
authored
Oct 07, 2017
by
Lev Walkin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
reconfigured tests to support -m32 32-bit mode testing with sanitizers
parent
cc6a76b2
Changes
16
Hide whitespace changes
Inline
Side-by-side
Showing
16 changed files
with
545 additions
and
380 deletions
+545
-380
skeletons/REAL.c
skeletons/REAL.c
+13
-17
skeletons/asn_internal.h
skeletons/asn_internal.h
+1
-0
skeletons/asn_random_fill.c
skeletons/asn_random_fill.c
+0
-1
skeletons/converter-example.c
skeletons/converter-example.c
+1
-0
tests/tests-skeletons/Makefile.am
tests/tests-skeletons/Makefile.am
+83
-3
tests/tests-skeletons/check-INTEGER.c
tests/tests-skeletons/check-INTEGER.c
+84
-74
tests/tests-skeletons/check-OER-INTEGER.c
tests/tests-skeletons/check-OER-INTEGER.c
+1
-1
tests/tests-skeletons/check-OER-NativeEnumerated.c
tests/tests-skeletons/check-OER-NativeEnumerated.c
+18
-40
tests/tests-skeletons/check-OER-support.c
tests/tests-skeletons/check-OER-support.c
+33
-24
tests/tests-skeletons/check-OIDs.c
tests/tests-skeletons/check-OIDs.c
+44
-175
tests/tests-skeletons/check-PER-INTEGER.c
tests/tests-skeletons/check-PER-INTEGER.c
+17
-2
tests/tests-skeletons/check-PER-support.c
tests/tests-skeletons/check-PER-support.c
+192
-2
tests/tests-skeletons/check-REAL.c
tests/tests-skeletons/check-REAL.c
+1
-1
tests/tests-skeletons/check-ber_tlv_tag.c
tests/tests-skeletons/check-ber_tlv_tag.c
+1
-0
tests/tests-skeletons/check-length.c
tests/tests-skeletons/check-length.c
+44
-40
tests/tests-skeletons/disable-leak-check-m32.sh
tests/tests-skeletons/disable-leak-check-m32.sh
+12
-0
No files found.
skeletons/REAL.c
View file @
6cbed3dd
...
...
@@ -664,12 +664,8 @@ asn_REAL2double(const REAL_t *st, double *dbl_value) {
*/
int
asn_double2REAL
(
REAL_t
*
st
,
double
dbl_value
)
{
#ifdef WORDS_BIGENDIAN
/* Known to be big-endian */
int
littleEndian
=
0
;
#else
/* need to test: have no explicit information */
unsigned
int
LE
=
1
;
int
littleEndian
=
*
(
unsigned
char
*
)
&
LE
;
#endif
double
test
=
-
0
.
0
;
int
float_big_endian
=
*
(
const
char
*
)
&
test
!=
0
;
uint8_t
buf
[
16
];
/* More than enough for 8-byte dbl_value */
uint8_t
dscr
[
sizeof
(
dbl_value
)];
/* double value scratch pad */
/* Assertion guards: won't even compile, if unexpected double size */
...
...
@@ -731,27 +727,27 @@ asn_double2REAL(REAL_t *st, double dbl_value) {
return
0
;
}
if
(
littleE
ndian
)
{
uint8_t
*
s
=
((
uint8_t
*
)
&
dbl_value
)
+
sizeof
(
dbl_value
)
-
2
;
uint8_t
*
start
=
((
uint8_t
*
)
&
dbl_valu
e
);
if
(
float_big_e
ndian
)
{
uint8_t
*
s
=
((
uint8_t
*
)
&
dbl_value
)
+
1
;
uint8_t
*
end
=
((
uint8_t
*
)
&
dbl_value
)
+
sizeof
(
doubl
e
);
uint8_t
*
d
;
bmsign
=
0x80
|
((
s
[
1
]
>>
1
)
&
0x40
);
/* binary mask & - */
for
(
mstop
=
d
=
dscr
;
s
>=
start
;
d
++
,
s
--
)
{
bmsign
=
0x80
|
((
s
[
-
1
]
>>
1
)
&
0x40
);
/* binary mask & - */
for
(
mstop
=
d
=
dscr
;
s
<
end
;
d
++
,
s
++
)
{
*
d
=
*
s
;
if
(
*
d
)
mstop
=
d
;
}
}
else
{
uint8_t
*
s
=
((
uint8_t
*
)
&
dbl_value
)
+
1
;
uint8_t
*
end
=
((
uint8_t
*
)
&
dbl_value
)
+
sizeof
(
doubl
e
);
}
else
{
uint8_t
*
s
=
((
uint8_t
*
)
&
dbl_value
)
+
sizeof
(
dbl_value
)
-
2
;
uint8_t
*
start
=
((
uint8_t
*
)
&
dbl_valu
e
);
uint8_t
*
d
;
bmsign
=
0x80
|
((
s
[
-
1
]
>>
1
)
&
0x40
);
/* binary mask & - */
for
(
mstop
=
d
=
dscr
;
s
<
end
;
d
++
,
s
++
)
{
bmsign
=
0x80
|
((
s
[
1
]
>>
1
)
&
0x40
);
/* binary mask & - */
for
(
mstop
=
d
=
dscr
;
s
>=
start
;
d
++
,
s
--
)
{
*
d
=
*
s
;
if
(
*
d
)
mstop
=
d
;
}
}
}
/* Remove parts of the exponent, leave mantissa and explicit 1. */
dscr
[
0
]
=
0x10
|
(
dscr
[
0
]
&
0x0f
);
...
...
skeletons/asn_internal.h
View file @
6cbed3dd
...
...
@@ -8,6 +8,7 @@
*/
#ifndef ASN_INTERNAL_H
#define ASN_INTERNAL_H
#define __EXTENSIONS__
/* for Sun */
#include "asn_application.h"
/* Application-visible API */
...
...
skeletons/asn_random_fill.c
View file @
6cbed3dd
...
...
@@ -3,7 +3,6 @@
* All rights reserved.
* Redistribution and modifications are permitted subject to BSD license.
*/
#include <asn_internal.h>
#include <asn_random_fill.h>
#include <constr_TYPE.h>
...
...
skeletons/converter-example.c
View file @
6cbed3dd
...
...
@@ -10,6 +10,7 @@
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#define __EXTENSIONS__
#include <stdio.h>
#include <sys/types.h>
#include <stdlib.h>
/* for atoi(3) */
...
...
tests/tests-skeletons/Makefile.am
View file @
6cbed3dd
...
...
@@ -19,12 +19,92 @@ check_PROGRAMS = \
check-PER-UniversalString
\
check-PER-INTEGER
if
EXPLICIT_M32
check_PROGRAMS
+=
\
check-32-ber_tlv_tag
\
check-32-length
\
check-32-bits
\
check-32-OIDs
\
check-32-GeneralizedTime
\
check-32-OCTET_STRING
\
check-32-UTF8String
\
check-32-UTCTime
\
check-32-INTEGER
\
check-32-REAL
\
check-32-XER
\
check-32-OER-support
\
check-32-OER-INTEGER
\
check-32-OER-NativeEnumerated
\
check-32-PER-support
\
check-32-PER-UniversalString
\
check-32-PER-INTEGER
check_32_ber_tlv_tag_CFLAGS
=
$(CFLAGS_M32)
check_32_ber_tlv_tag_LDADD
=
$(LDADD_32)
check_32_ber_tlv_tag_SOURCES
=
check-ber_tlv_tag.c
check_32_length_CFLAGS
=
$(CFLAGS_M32)
check_32_length_LDADD
=
$(LDADD_32)
check_32_length_SOURCES
=
check-length.c
check_32_bits_CFLAGS
=
$(CFLAGS_M32)
check_32_bits_LDADD
=
$(LDADD_32)
check_32_bits_SOURCES
=
check-bits.c
check_32_OIDs_CFLAGS
=
$(CFLAGS_M32)
check_32_OIDs_LDADD
=
$(LDADD_32)
check_32_OIDs_SOURCES
=
check-OIDs.c
check_32_GeneralizedTime_CFLAGS
=
$(CFLAGS_M32)
check_32_GeneralizedTime_LDADD
=
$(LDADD_32)
check_32_GeneralizedTime_SOURCES
=
check-GeneralizedTime.c
check_32_OCTET_STRING_CFLAGS
=
$(CFLAGS_M32)
check_32_OCTET_STRING_LDADD
=
$(LDADD_32)
check_32_OCTET_STRING_SOURCES
=
check-OCTET_STRING.c
check_32_UTF8String_CFLAGS
=
$(CFLAGS_M32)
check_32_UTF8String_LDADD
=
$(LDADD_32)
check_32_UTF8String_SOURCES
=
check-UTF8String.c
check_32_UTCTime_CFLAGS
=
$(CFLAGS_M32)
check_32_UTCTime_LDADD
=
$(LDADD_32)
check_32_UTCTime_SOURCES
=
check-UTCTime.c
check_32_INTEGER_CFLAGS
=
$(CFLAGS_M32)
check_32_INTEGER_LDADD
=
$(LDADD_32)
check_32_INTEGER_SOURCES
=
check-INTEGER.c
check_32_REAL_CFLAGS
=
$(CFLAGS_M32)
check_32_REAL_LDADD
=
$(LDADD_32)
check_32_REAL_SOURCES
=
check-REAL.c
check_32_XER_CFLAGS
=
$(CFLAGS_M32)
check_32_XER_LDADD
=
$(LDADD_32)
check_32_XER_SOURCES
=
check-XER.c
check_32_OER_support_CFLAGS
=
$(CFLAGS_M32)
check_32_OER_support_LDADD
=
$(LDADD_32)
check_32_OER_support_SOURCES
=
check-OER-support.c
check_32_OER_INTEGER_CFLAGS
=
$(CFLAGS_M32)
check_32_OER_INTEGER_LDADD
=
$(LDADD_32)
check_32_OER_INTEGER_SOURCES
=
check-OER-INTEGER.c
check_32_OER_NativeEnumerated_CFLAGS
=
$(CFLAGS_M32)
check_32_OER_NativeEnumerated_LDADD
=
$(LDADD_32)
check_32_OER_NativeEnumerated_SOURCES
=
check-OER-NativeEnumerated.c
check_32_PER_support_CFLAGS
=
$(CFLAGS_M32)
check_32_PER_support_LDADD
=
$(LDADD_32)
check_32_PER_support_SOURCES
=
check-PER-support.c
check_32_PER_UniversalString_CFLAGS
=
$(CFLAGS_M32)
check_32_PER_UniversalString_LDADD
=
$(LDADD_32)
check_32_PER_UniversalString_SOURCES
=
check-PER-UniversalString.c
check_32_PER_INTEGER_CFLAGS
=
$(CFLAGS_M32)
check_32_PER_INTEGER_LDADD
=
$(LDADD_32)
check_32_PER_INTEGER_SOURCES
=
check-PER-INTEGER.c
LDADD_32
=
$(top_builddir)
/skeletons/libasn1cskeletons_32.la
endif
#Filter out the coverage options from CFLAGS as we don't need
#code coverage data for the tests executables
CFLAGS
=
$(
filter-out
$(CODE_COVERAGE_CFLAGS)
, @CFLAGS@
)
AM_CFLAGS
=
-I
$(top_srcdir)
/skeletons
$(TESTSUITE_CFLAGS)
CFLAGS
=
$(
filter-out
$(CODE_COVERAGE_CFLAGS)
, @CFLAGS@
)
\
-I
$(top_srcdir)
/skeletons
$(TESTSUITE_CFLAGS)
AM_LDFLAGS
=
$(top_builddir)
/skeletons/libasn1cskeletons.la
LDADD
=
-lm
TESTS
=
$(check_PROGRAMS)
TESTS_ENVIRONMENT
=
@ASAN_ENV_FLAGS@
UBSAN_OPTIONS
=
print_stacktrace
=
1
TESTS_ENVIRONMENT
=
\
@ASAN_ENV_FLAGS@
\
UBSAN_OPTIONS
=
print_stacktrace
=
1
\
${srcdir}
/disable-leak-check-m32.sh
EXTRA_DIST
=
disable-leak-check-m32.sh
tests/tests-skeletons/check-INTEGER.c
View file @
6cbed3dd
#include <stdio.h>
#include <assert.h>
#include <asn_application.h>
#include <INTEGER.h>
#define CHECK_XER(a,b,c) check_xer(__LINE__, a, b, c)
static
char
*
shared_scratch_start
;
static
int
_print2buf
(
const
void
*
buf
,
size_t
size
,
void
*
key
)
{
...
...
@@ -144,13 +147,13 @@ check_unsigned(uint8_t *buf, int size, unsigned long check_long, int check_ret)
}
static
void
check_xer
(
int
tofail
,
char
*
xmldata
,
long
orig_value
)
{
check_xer
(
int
lineno
,
int
tofail
,
char
*
xmldata
,
long
orig_value
)
{
INTEGER_t
*
st
=
0
;
asn_dec_rval_t
rc
;
long
value
;
int
ret
;
printf
(
"
[%s] vs %ld: "
,
xmldata
,
orig_value
);
printf
(
"
%03d: [%s] vs %ld: "
,
lineno
,
xmldata
,
orig_value
);
rc
=
xer_decode
(
0
,
&
asn_DEF_INTEGER
,
(
void
*
)
&
st
,
xmldata
,
strlen
(
xmldata
));
...
...
@@ -160,7 +163,10 @@ check_xer(int tofail, char *xmldata, long orig_value) {
ASN_STRUCT_FREE
(
asn_DEF_INTEGER
,
st
);
return
;
}
assert
(
!
tofail
);
if
(
tofail
)
{
printf
(
"
\t
not failed, as expected!
\n
"
);
assert
(
!
tofail
);
}
ret
=
asn_INTEGER2long
(
st
,
&
value
);
assert
(
ret
==
0
);
...
...
@@ -213,80 +219,84 @@ main() {
UCHECK
(
buf15
,
0x80000000UL
,
0
);
UCHECK
(
buf16
,
0xffff0000UL
,
0
);
check_xer
(
-
1
,
""
,
0
);
check_xer
(
-
1
,
"<INTEGER></INTEGER>"
,
0
);
check_xer
(
-
1
,
"<INTEGER> </INTEGER>"
,
0
);
check_xer
(
-
1
,
"<INTEGER>-</INTEGER>"
,
0
);
check_xer
(
-
1
,
"<INTEGER>+</INTEGER>"
,
0
);
check_xer
(
-
1
,
"<INTEGER>+-</INTEGER>"
,
0
);
check_xer
(
-
1
,
"<INTEGER> -</INTEGER>"
,
0
);
check_xer
(
-
1
,
"<INTEGER> +</INTEGER>"
,
0
);
check_xer
(
-
1
,
"<INTEGER> +-</INTEGER>"
,
0
);
check_xer
(
-
1
,
"<INTEGER>- </INTEGER>"
,
0
);
check_xer
(
-
1
,
"<INTEGER>+ </INTEGER>"
,
0
);
check_xer
(
-
1
,
"<INTEGER>+- </INTEGER>"
,
0
);
check_xer
(
-
1
,
"<INTEGER> - </INTEGER>"
,
0
);
check_xer
(
-
1
,
"<INTEGER> + </INTEGER>"
,
0
);
check_xer
(
-
1
,
"<INTEGER> +- </INTEGER>"
,
0
);
check_xer
(
0
,
"<INTEGER>+0</INTEGER>"
,
0
);
check_xer
(
0
,
"<INTEGER>-0</INTEGER>"
,
0
);
check_xer
(
0
,
"<INTEGER>+1</INTEGER>"
,
1
);
check_xer
(
0
,
"<INTEGER>-1</INTEGER>"
,
-
1
);
check_xer
(
0
,
"<INTEGER>1</INTEGER>"
,
1
);
check_xer
(
0
,
"<INTEGER>-15</INTEGER>"
,
-
15
);
check_xer
(
0
,
"<INTEGER>+15</INTEGER>"
,
15
);
check_xer
(
0
,
"<INTEGER>15</INTEGER>"
,
15
);
check_xer
(
0
,
"<INTEGER> 15</INTEGER>"
,
15
);
check_xer
(
0
,
"<INTEGER> 15 </INTEGER>"
,
15
);
check_xer
(
0
,
"<INTEGER>15 </INTEGER>"
,
15
);
check_xer
(
0
,
"<INTEGER> +15 </INTEGER>"
,
15
);
check_xer
(
-
1
,
"<INTEGER> +15 -</INTEGER>"
,
0
);
check_xer
(
-
1
,
"<INTEGER> +15 1</INTEGER>"
,
0
);
check_xer
(
-
1
,
"<INTEGER>+ 15</INTEGER>"
,
0
);
check_xer
(
-
1
,
"<INTEGER>12<z>34</INTEGER>"
,
0
);
check_xer
(
-
1
,
"<INTEGER>12 <z>34</INTEGER>"
,
0
);
check_xer
(
-
1
,
"<INTEGER>12 <z></INTEGER>"
,
0
);
check_xer
(
0
,
"<INTEGER>1234</INTEGER>"
,
1234
);
check_xer
(
-
1
,
"<INTEGER>1234 5678</INTEGER>"
,
0
);
check_xer
(
0
,
"<INTEGER>-2147483647</INTEGER>"
,
-
2147483647
);
check_xer
(
0
,
"<INTEGER>-2147483648</INTEGER>"
,
-
2147483647
-
1
);
check_xer
(
0
,
"<INTEGER>+2147483647</INTEGER>"
,
2147483647
);
check_xer
(
0
,
"<INTEGER>2147483647</INTEGER>"
,
2147483647
);
CHECK_XER
(
-
1
,
""
,
0
);
CHECK_XER
(
-
1
,
"<INTEGER></INTEGER>"
,
0
);
CHECK_XER
(
-
1
,
"<INTEGER> </INTEGER>"
,
0
);
CHECK_XER
(
-
1
,
"<INTEGER>-</INTEGER>"
,
0
);
CHECK_XER
(
-
1
,
"<INTEGER>+</INTEGER>"
,
0
);
CHECK_XER
(
-
1
,
"<INTEGER>+-</INTEGER>"
,
0
);
CHECK_XER
(
-
1
,
"<INTEGER> -</INTEGER>"
,
0
);
CHECK_XER
(
-
1
,
"<INTEGER> +</INTEGER>"
,
0
);
CHECK_XER
(
-
1
,
"<INTEGER> +-</INTEGER>"
,
0
);
CHECK_XER
(
-
1
,
"<INTEGER>- </INTEGER>"
,
0
);
CHECK_XER
(
-
1
,
"<INTEGER>+ </INTEGER>"
,
0
);
CHECK_XER
(
-
1
,
"<INTEGER>+- </INTEGER>"
,
0
);
CHECK_XER
(
-
1
,
"<INTEGER> - </INTEGER>"
,
0
);
CHECK_XER
(
-
1
,
"<INTEGER> + </INTEGER>"
,
0
);
CHECK_XER
(
-
1
,
"<INTEGER> +- </INTEGER>"
,
0
);
CHECK_XER
(
0
,
"<INTEGER>+0</INTEGER>"
,
0
);
CHECK_XER
(
0
,
"<INTEGER>-0</INTEGER>"
,
0
);
CHECK_XER
(
0
,
"<INTEGER>+1</INTEGER>"
,
1
);
CHECK_XER
(
0
,
"<INTEGER>-1</INTEGER>"
,
-
1
);
CHECK_XER
(
0
,
"<INTEGER>1</INTEGER>"
,
1
);
CHECK_XER
(
0
,
"<INTEGER>-15</INTEGER>"
,
-
15
);
CHECK_XER
(
0
,
"<INTEGER>+15</INTEGER>"
,
15
);
CHECK_XER
(
0
,
"<INTEGER>15</INTEGER>"
,
15
);
CHECK_XER
(
0
,
"<INTEGER> 15</INTEGER>"
,
15
);
CHECK_XER
(
0
,
"<INTEGER> 15 </INTEGER>"
,
15
);
CHECK_XER
(
0
,
"<INTEGER>15 </INTEGER>"
,
15
);
CHECK_XER
(
0
,
"<INTEGER> +15 </INTEGER>"
,
15
);
CHECK_XER
(
-
1
,
"<INTEGER> +15 -</INTEGER>"
,
0
);
CHECK_XER
(
-
1
,
"<INTEGER> +15 1</INTEGER>"
,
0
);
CHECK_XER
(
-
1
,
"<INTEGER>+ 15</INTEGER>"
,
0
);
CHECK_XER
(
-
1
,
"<INTEGER>12<z>34</INTEGER>"
,
0
);
CHECK_XER
(
-
1
,
"<INTEGER>12 <z>34</INTEGER>"
,
0
);
CHECK_XER
(
-
1
,
"<INTEGER>12 <z></INTEGER>"
,
0
);
CHECK_XER
(
0
,
"<INTEGER>1234</INTEGER>"
,
1234
);
CHECK_XER
(
-
1
,
"<INTEGER>1234 5678</INTEGER>"
,
0
);
CHECK_XER
(
0
,
"<INTEGER>-2147483647</INTEGER>"
,
-
2147483647
);
CHECK_XER
(
0
,
"<INTEGER>-2147483648</INTEGER>"
,
-
2147483647
-
1
);
CHECK_XER
(
0
,
"<INTEGER>+2147483647</INTEGER>"
,
2147483647
);
CHECK_XER
(
0
,
"<INTEGER>2147483647</INTEGER>"
,
2147483647
);
if
(
sizeof
(
long
)
==
4
)
{
check_xer
(
0
,
"<INTEGER>-2147483648</INTEGER>"
,
-
2147483648
);
check_xer
(
-
1
,
"<INTEGER>-2147483649</INTEGER>"
,
0
);
check_xer
(
-
1
,
"<INTEGER>2147483648</INTEGER>"
,
0
);
check_xer
(
-
1
,
"<INTEGER>2147483649</INTEGER>"
,
0
);
check_xer
(
-
1
,
"<INTEGER>3147483649</INTEGER>"
,
0
);
check_xer
(
-
1
,
"<INTEGER>4147483649</INTEGER>"
,
0
);
check_xer
(
-
1
,
"<INTEGER>5147483649</INTEGER>"
,
0
);
/* special */
check_xer
(
-
1
,
"<INTEGER>9147483649</INTEGER>"
,
0
);
check_xer
(
-
1
,
"<INTEGER>9999999999</INTEGER>"
,
0
);
check_xer
(
-
1
,
"<INTEGER>-5147483649</INTEGER>"
,
0
);
/* special */
check_xer
(
-
1
,
"<INTEGER>-9147483649</INTEGER>"
,
0
);
check_xer
(
-
1
,
"<INTEGER>-9999999999</INTEGER>"
,
0
);
CHECK_XER
(
0
,
"<INTEGER>-2147483648</INTEGER>"
,
-
2147483648
);
CHECK_XER
(
-
1
,
"<INTEGER>-2147483649</INTEGER>"
,
0
);
CHECK_XER
(
-
1
,
"<INTEGER>2147483648</INTEGER>"
,
0
);
CHECK_XER
(
-
1
,
"<INTEGER>2147483649</INTEGER>"
,
0
);
CHECK_XER
(
-
1
,
"<INTEGER>3147483649</INTEGER>"
,
0
);
CHECK_XER
(
-
1
,
"<INTEGER>4147483649</INTEGER>"
,
0
);
CHECK_XER
(
-
1
,
"<INTEGER>5147483649</INTEGER>"
,
0
);
/* special */
CHECK_XER
(
-
1
,
"<INTEGER>9147483649</INTEGER>"
,
0
);
CHECK_XER
(
-
1
,
"<INTEGER>9999999999</INTEGER>"
,
0
);
CHECK_XER
(
-
1
,
"<INTEGER>-5147483649</INTEGER>"
,
0
);
/* special */
CHECK_XER
(
-
1
,
"<INTEGER>-9147483649</INTEGER>"
,
0
);
CHECK_XER
(
-
1
,
"<INTEGER>-9999999999</INTEGER>"
,
0
);
}
#ifdef TEST_64BIT
if
(
sizeof
(
long
)
==
8
)
{
check_xer
(
0
,
"<INTEGER>2147483648</INTEGER>"
,
2147483648
);
check_xer
(
0
,
"<INTEGER>2147483649</INTEGER>"
,
2147483649
);
check_xer
(
0
,
"<INTEGER>3147483649</INTEGER>"
,
3147483649
);
check_xer
(
0
,
"<INTEGER>4147483649</INTEGER>"
,
4147483649
);
check_xer
(
0
,
"<INTEGER>5147483649</INTEGER>"
,
5147483649
);
check_xer
(
0
,
"<INTEGER>9147483649</INTEGER>"
,
9147483649
);
check_xer
(
0
,
"<INTEGER>9999999999</INTEGER>"
,
9999999999
);
check_xer
(
0
,
"<INTEGER>9223372036854775807</INTEGER>"
,
9223372036854775807
);
check_xer
(
-
1
,
"<INTEGER>9223372036854775808</INTEGER>"
,
0
);
check_xer
(
-
1
,
"<INTEGER>10223372036854775807</INTEGER>"
,
0
);
check_xer
(
-
1
,
"<INTEGER>50223372036854775807</INTEGER>"
,
0
);
check_xer
(
-
1
,
"<INTEGER>100223372036854775807</INTEGER>"
,
0
);
check_xer
(
-
1
,
"<INTEGER>500223372036854775807</INTEGER>"
,
0
);
check_xer
(
0
,
"<INTEGER>-9223372036854775808</INTEGER>"
,
-
9223372036854775807
-
1
);
check_xer
(
-
1
,
"<INTEGER>-9223372036854775809</INTEGER>"
,
0
);
check_xer
(
-
1
,
"<INTEGER>-10223372036854775807</INTEGER>"
,
0
);
check_xer
(
-
1
,
"<INTEGER>-50223372036854775807</INTEGER>"
,
0
);
check_xer
(
-
1
,
"<INTEGER>-100223372036854775807</INTEGER>"
,
0
);
check_xer
(
-
1
,
"<INTEGER>-500223372036854775807</INTEGER>"
,
0
);
}
CHECK_XER
(
0
,
"<INTEGER>2147483648</INTEGER>"
,
2147483648
);
CHECK_XER
(
0
,
"<INTEGER>2147483649</INTEGER>"
,
2147483649
);
CHECK_XER
(
0
,
"<INTEGER>3147483649</INTEGER>"
,
3147483649
);
CHECK_XER
(
0
,
"<INTEGER>4147483649</INTEGER>"
,
4147483649
);
CHECK_XER
(
0
,
"<INTEGER>5147483649</INTEGER>"
,
5147483649
);
CHECK_XER
(
0
,
"<INTEGER>9147483649</INTEGER>"
,
9147483649
);
CHECK_XER
(
0
,
"<INTEGER>9999999999</INTEGER>"
,
9999999999
);
CHECK_XER
(
0
,
"<INTEGER>9223372036854775807</INTEGER>"
,
9223372036854775807
);
CHECK_XER
(
-
1
,
"<INTEGER>9223372036854775808</INTEGER>"
,
0
);
CHECK_XER
(
-
1
,
"<INTEGER>10223372036854775807</INTEGER>"
,
0
);
CHECK_XER
(
-
1
,
"<INTEGER>50223372036854775807</INTEGER>"
,
0
);
CHECK_XER
(
-
1
,
"<INTEGER>100223372036854775807</INTEGER>"
,
0
);
CHECK_XER
(
-
1
,
"<INTEGER>500223372036854775807</INTEGER>"
,
0
);
CHECK_XER
(
0
,
"<INTEGER>-9223372036854775808</INTEGER>"
,
-
9223372036854775807
-
1
);
CHECK_XER
(
-
1
,
"<INTEGER>-9223372036854775809</INTEGER>"
,
0
);
CHECK_XER
(
-
1
,
"<INTEGER>-10223372036854775807</INTEGER>"
,
0
);
CHECK_XER
(
-
1
,
"<INTEGER>-50223372036854775807</INTEGER>"
,
0
);
CHECK_XER
(
-
1
,
"<INTEGER>-100223372036854775807</INTEGER>"
,
0
);
CHECK_XER
(
-
1
,
"<INTEGER>-500223372036854775807</INTEGER>"
,
0
);
}
else
{
assert
(
sizeof
(
long
)
==
8
);
}
#endif
return
0
;
}
tests/tests-skeletons/check-OER-INTEGER.c
View file @
6cbed3dd
#include <stdio.h>
#include <assert.h>
#include <asn_
codecs
.h>
#include <asn_
application
.h>
#include <INTEGER.h>
#define CHECK_DECODE(code, a, b, c, d, e, f) check_decode(__LINE__, code, a, b, c, d, e, f)
...
...
tests/tests-skeletons/check-OER-NativeEnumerated.c
View file @
6cbed3dd
#include <stdio.h>
#include <assert.h>
#include <asn_
codecs
.h>
#include <asn_
application
.h>
#include <NativeEnumerated.h>
#define CHECK_DECODE(code, a, b, c) check_decode(__LINE__, code, a, b, c)
#define CHECK_ROUNDTRIP(a) check_roundtrip(__LINE__, a);
static
void
check_decode
(
int
lineno
,
enum
asn_dec_rval_code_e
code
,
intmax_t
control
,
const
char
*
buf
,
size_t
size
)
{
check_decode
(
int
lineno
,
enum
asn_dec_rval_code_e
code
,
long
control
,
const
char
*
buf
,
size_t
size
)
{
static
char
*
code_s
[]
=
{
"RC_OK"
,
"RC_WMORE"
,
"RC_FAIL"
,
"<error>"
};
fprintf
(
stderr
,
"
\n
%d: OER decode (control %
"
PRIdMAX
"
)
\n
"
,
lineno
,
control
);
fprintf
(
stderr
,
"
\n
%d: OER decode (control %
ld
)
\n
"
,
lineno
,
control
);
long
value
;
long
*
value_ptr
=
&
value
;
...
...
@@ -25,7 +25,7 @@ check_decode(int lineno, enum asn_dec_rval_code_e code, intmax_t control, const
(
void
**
)
&
value_ptr
,
buf
,
size
);
if
(
ret
.
code
!=
RC_OK
)
{
/* Basic OER decode does not work */
fprintf
(
stderr
,
"%d: Failed oer_decode(ctl=%
"
PRIdMAX
"
, size=%zu)
\n
"
,
fprintf
(
stderr
,
"%d: Failed oer_decode(ctl=%
ld
, size=%zu)
\n
"
,
lineno
,
control
,
size
);
if
(
ret
.
code
==
code
)
{
fprintf
(
stderr
,
" (That was expected)
\n
"
);
...
...
@@ -38,18 +38,17 @@ check_decode(int lineno, enum asn_dec_rval_code_e code, intmax_t control, const
assert
(
ret
.
code
==
code
);
}
}
else
{
intmax_t
outcome
=
value
;
long
outcome
=
value
;
if
(
outcome
!=
control
)
{
/* Decoded value is wrong */
fprintf
(
stderr
,
"%d: Decode result %"
PRIdMAX
" is not expected %"
PRIdMAX
"
\n
"
,
"%d: Decode result %ld is not expected %ld
\n
"
,
lineno
,
outcome
,
control
);
assert
(
outcome
==
control
);
}
}
fprintf
(
stderr
,
"%d: Decode result %
"
PRIdMAX
"
\n
"
,
lineno
,
control
);
fprintf
(
stderr
,
"%d: Decode result %
ld
\n
"
,
lineno
,
control
);
}
static
void
...
...
@@ -66,15 +65,14 @@ dump_data(int lineno, const uint8_t *buf, size_t size) {
}
static
void
check_roundtrip
(
int
lineno
,
intmax_t
control
)
{
check_roundtrip
(
int
lineno
,
long
control
)
{
uint8_t
tmpbuf
[
32
];
size_t
tmpbuf_size
;
fprintf
(
stderr
,
"
\n
%d: OER round-trip value %"
PRIdMAX
"
\n
"
,
lineno
,
control
);
asn_enc_rval_t
er
;
asn_dec_rval_t
ret
;
fprintf
(
stderr
,
"
\n
%d: OER round-trip value %ld
\n
"
,
lineno
,
control
);
long
value_out
=
control
;
long
value_in
=
-
42
;
long
*
value_in_ptr
=
&
value_in
;
...
...
@@ -95,22 +93,21 @@ check_roundtrip(int lineno, intmax_t control) {
tmpbuf
,
tmpbuf_size
);
if
(
ret
.
code
!=
RC_OK
)
{
/* Basic OER decode does not work */
fprintf
(
stderr
,
"%d: Failed oer_decode(value=%
"
PRIdMAX
"
, size=%zu)
\n
"
,
fprintf
(
stderr
,
"%d: Failed oer_decode(value=%
ld
, size=%zu)
\n
"
,
lineno
,
control
,
tmpbuf_size
);
assert
(
ret
.
code
==
0
);
}
else
{
intmax_t
outcome
=
value_in
;
long
outcome
=
value_in
;
if
(
outcome
!=
control
)
{
/* Decoded value is wrong */
fprintf
(
stderr
,
"%d: Decode result %"
PRIdMAX
" is not expected %"
PRIdMAX
"
\n
"
,
"%d: Decode result %ld is not expected %ld
\n
"
,
lineno
,
outcome
,
control
);
assert
(
outcome
==
control
);
}
}
fprintf
(
stderr
,
"%d: Decode result %
"
PRIdMAX
"
\n
"
,
lineno
,
control
);
fprintf
(
stderr
,
"%d: Decode result %
ld
\n
"
,
lineno
,
control
);
}
int
...
...
@@ -161,32 +158,13 @@ main() {
CHECK_ROUNDTRIP
(
65536
);
CHECK_ROUNDTRIP
(
32000
);
for
(
size_t
i
=
0
;
i
<
7
;
i
++
)
{
intmax_t
value
=
(
intmax_t
)
1
<<
i
;
CHECK_ROUNDTRIP
(
value
);
value
=
-
value
;
CHECK_ROUNDTRIP
(
value
);
}
for
(
size_t
i
=
0
;
i
<
16
;
i
++
)
{
intmax_t
value
=
(
intmax_t
)
1
<<
i
;
CHECK_ROUNDTRIP
(
value
);
value
=
-
value
;
CHECK_ROUNDTRIP
(
value
);
}
for
(
size_t
i
=
0
;
i
<
32
;
i
++
)
{
intmax_t
value
=
(
intmax_t
)
1
<<
i
;
CHECK_ROUNDTRIP
(
value
);
value
=
-
value
;
CHECK_ROUNDTRIP
(
value
);
}
for
(
size_t
i
=
0
;
i
<
8
*
sizeof
(
intmax_t
)
-
1
;
i
++
)
{
intmax_t
value
=
(
intmax_t
)
1
<<
i
;
for
(
size_t
i
=
0
;
i
<
8
*
sizeof
(
long
)
-
1
;
i
++
)
{
long
value
=
(
long
)
1
<<
i
;
CHECK_ROUNDTRIP
(
value
);
value
=
-
value
;
CHECK_ROUNDTRIP
(
value
);
}
CHECK_ROUNDTRIP
(
LONG_MIN
);
CHECK_ROUNDTRIP
(
LONG_MAX
);
}
tests/tests-skeletons/check-OER-support.c
View file @
6cbed3dd
...
...
@@ -11,13 +11,16 @@ static int fill_buffer(const void *data, size_t size, void *app_key) {
return
0
;
}
#define CHECK(a, b) check_round_trip(__LINE__, a, b)
static
void
check_round_trip
(
size_t
length
)
{
fprintf
(
stderr
,
"
Round-trip for %zu
\n
"
,
length
);
check_round_trip
(
int
lineno
,
int
ok
,
size_t
length
)
{
fprintf
(
stderr
,
"
%03d: Round-trip for %zu
\n
"
,
lineno
,
length
);
/* Serialize */
size_t
enc_len
=
0
;
size_t
enc_len_len
=
oer_serialize_length
(
length
,
fill_buffer
,
&
enc_len
);
ssize_t
enc_len_len
=
oer_serialize_length
(
length
,
fill_buffer
,
&
enc_len
);
assert
(
enc_len_len
>
0
);
assert
(
enc_len
==
enc_len_len
);
/* Deserialize */
...
...
@@ -26,32 +29,38 @@ check_round_trip(size_t length) {
size_t
ret
=
oer_fetch_length
(
buffer
,
part
,
&
recovered_length
);
assert
(
ret
==
0
);
/* More data expected. */
}
size_t
dec_len
=
oer_fetch_length
(
buffer
,
enc_len
,
&
recovered_length
);
assert
(
dec_len
==
enc_len
);
if
(
recovered_length
!=
length
)
{
fprintf
(
stderr
,
"Round-trip failed %zu->%zu (encoded %zd, decoded %zd)
\n
"
,
length
,
recovered_length
,
enc_len
,
dec_len
);
assert
(
recovered_length
==
length
);
ssize_t
dec_len
=
oer_fetch_length
(
buffer
,
enc_len
,
&
recovered_length
);
if
(
ok
)
{
assert
(
dec_len
==
enc_len
);
if
(
recovered_length
!=
length
)
{
fprintf
(
stderr
,
"Round-trip failed %zu->%zu (encoded %zd, decoded %zd)
\n
"
,
length
,
recovered_length
,
enc_len
,
dec_len
);
assert
(
recovered_length
==
length
);
}
}
else
{
assert
(
dec_len
==
-
1
);
}
}
int
main
()
{
int
bits64
=
sizeof
(
size_t
)
>
4
;
check_round_trip
(
0
);
check_round_trip
(
1
);
check_round_trip
(
127
);
check_round_trip
(
128
);
check_round_trip
(
129
);
check_round_trip
(
255
);
check_round_trip
(
256
);
check_round_trip
(
65534
);
check_round_trip
(
65535
);
check_round_trip
(
65536
);
check_round_trip
(
65538
);
check_round_trip
(
16000000
);
check_round_trip
(
16777216
);
check_round_trip
(
2147483648
);
check_round_trip
(
4294967296
);
CHECK
(
1
,
0
);
CHECK
(
1
,
1
);
CHECK
(
1
,
127
);
CHECK
(
1
,
128
);
CHECK
(
1
,
129
);
CHECK
(
1
,
255
);
CHECK
(
1
,
256
);
CHECK
(
1
,
65534
);
CHECK
(
1
,
65535
);
CHECK
(
1
,
65536
);
CHECK
(
1
,
65538
);
CHECK
(
1
,
16000000
);
CHECK
(
1
,
16777216
);
CHECK
(
bits64
,
2147483648
);
CHECK
(
bits64
,
4294967295UL
);
}
tests/tests-skeletons/check-OIDs.c
View file @
6cbed3dd
#include <stdio.h>
#include <assert.h>
#include <errno.h>
#include <sys/time.h>
#include <OBJECT_IDENTIFIER.h>
...
...
@@ -13,7 +14,7 @@ _print(const void *buffer, size_t size, void *app_key) {
}
static
void
check_OID
(
int
lineno
,
uint8_t
*
buf
,
size_t
len
,
int
*
ck_buf
,
int
ck_len
)
{
check_OID
(
int
lineno
,
uint8_t
*
buf
,
size_t
len
,
unsigned
*
ck_buf
,
int
ck_len
)
{
OBJECT_IDENTIFIER_t
*
oid
;
asn_dec_rval_t
rval
;
unsigned
long
arcs
[
10
];
...
...
@@ -23,7 +24,7 @@ check_OID(int lineno, uint8_t *buf, size_t len, int *ck_buf, int ck_len) {
printf
(
"%03d: Checking {"
,
lineno
);
for
(
i
=
0
;
i
<
(
int
)
len
;
i
++
)
{
printf
(
"%s%02x"
,
i
?
" "
:
""
,
buf
[
i
]);
}
printf
(
"} against {"
);
for
(
i
=
0
;
i
<
ck_len
;
i
++
)
{
printf
(
"%s%
d
"
,
i
?
" "
:
""
,
ck_buf
[
i
]);
}
for
(
i
=
0
;
i
<
ck_len
;
i
++
)
{
printf
(
"%s%
u
"
,
i
?
" "
:
""
,
ck_buf
[
i
]);
}
printf
(
"}
\n
"
);
oid
=
NULL
;
...
...
@@ -51,7 +52,7 @@ check_OID(int lineno, uint8_t *buf, size_t len, int *ck_buf, int ck_len) {
for
(
i
=
0
;
i
<
alen
;
i
++
)
{
printf
(
" %lu"
,
arcs
[
i
]);
if
(
alen
==
ck_len
)
{
assert
(
arcs
[
i
]
==
(
unsigned
long
)
ck_buf
[
i
]);
assert
(
arcs
[
i
]
==
ck_buf
[
i
]);
}
}
printf
(
" }
\n
"
);
...
...
@@ -61,7 +62,7 @@ check_OID(int lineno, uint8_t *buf, size_t len, int *ck_buf, int ck_len) {
}
static
void
check_ROID
(
int
lineno
,
uint8_t
*
buf
,
size_t
len
,
int
*
ck_buf
,
int
ck_len
)
{
check_ROID
(
int
lineno
,
uint8_t
*
buf
,
size_t
len
,
unsigned
*
ck_buf
,
int
ck_len
)
{
RELATIVE_OID_t
*
oid
;
asn_dec_rval_t
rval
;
unsigned
long
arcs
[
10
];
...
...
@@ -71,7 +72,7 @@ check_ROID(int lineno, uint8_t *buf, size_t len, int *ck_buf, int ck_len) {
printf
(
"%03d: Checking {"
,
lineno
);
for
(
i
=
0
;
i
<
(
ssize_t
)
len
;
i
++
)
{
printf
(
"%s%02x"
,
i
?
" "
:
""
,
buf
[
i
]);
}
printf
(
"} against {"
);
for
(
i
=
0
;
i
<
ck_len
;
i
++
)
{
printf
(
"%s%
d
"
,
i
?
" "
:
""
,
ck_buf
[
i
]);
}
for
(
i
=
0
;
i
<
ck_len
;
i
++
)
{
printf
(
"%s%
u
"
,
i
?
" "
:
""
,
ck_buf
[
i
]);
}
printf
(
"}
\n
"
);
oid
=
NULL
;
...
...
@@ -98,98 +99,13 @@ check_ROID(int lineno, uint8_t *buf, size_t len, int *ck_buf, int ck_len) {
*/
printf
(
"RELATIVE_OID_get_arcs() => {"
);
for
(
i
=
0
;
i
<
alen
;
i
++
)
{
printf
(
" %lu"
,
(
unsigned
long
)
arcs
[
i
]);
assert
(
arcs
[
i
]
==
(
unsigned
long
)
ck_buf
[
i
]);
printf
(
" %lu"
,
arcs
[
i
]);
assert
(
arcs
[
i
]
==
ck_buf
[
i
]);
}
printf
(
" }
\n
"
);
ASN_STRUCT_FREE
(
asn_DEF_RELATIVE_OID
,
oid
);
}
/*
* Encode the specified array of arcs as RELATIVE-OID, decode it and compare.
*/
static
void
check_REGEN
(
int
lineno
,
int
*
arcs
,
int
acount
)
{
static
RELATIVE_OID_t
oid
;
unsigned
long
tmp_arcs
[
10
];
int
tmp_alen
=
10
;
int
alen
;
int
ret
;
int
i
;
if
(
0
)
{
fprintf
(
stderr
,
"%03d: Encoding (R) {"
,
lineno
);
for
(
i
=
0
;
i
<
acount
;
i
++
)
{
fprintf
(
stderr
,
" %u"
,
arcs
[
i
]);
}
fprintf
(
stderr
,
" }
\n
"
);
}
ret
=
RELATIVE_OID_set_arcs
(
&
oid
,
arcs
,
sizeof
(
arcs
[
0
]),
acount
);
assert
(
ret
==
0
);
memset
(
tmp_arcs
,
'A'
,
sizeof
(
tmp_arcs
));
alen
=
RELATIVE_OID_get_arcs
(
&
oid
,
tmp_arcs
,
sizeof
(
tmp_arcs
[
0
]),
tmp_alen
);
assert
(
alen
>=
0
);
assert
(
alen
<=
tmp_alen
);
assert
(
alen
==
acount
);
if
(
0
)
{
fprintf
(
stderr
,
"Encoded (R) { "
);
for
(
i
=
0
;
i
<
alen
;
i
++
)
{
fprintf
(
stderr
,
"%lu "
,
tmp_arcs
[
i
]);
fflush
(
stdout
);
assert
(
arcs
[
i
]
==
(
int
)
tmp_arcs
[
i
]);
}
fprintf
(
stderr
,
"}
\n
"
);
}
ASN_STRUCT_RESET
(
asn_DEF_RELATIVE_OID
,
&
oid
);
}
/*
* Encode the specified array of arcs as OBJECT IDENTIFIER,
* decode it and compare.
*/
static
void
check_REGEN_OID
(
int
lineno
,
int
*
arcs
,
int
acount
)
{
static
OBJECT_IDENTIFIER_t
oid
;
unsigned
long
tmp_arcs
[
10
];
int
tmp_alen
=
10
;
int
alen
;
int
ret
;
int
i
;
if
(
0
)
{
fprintf
(
stderr
,
"%03d: Encoding (O) {"
,
lineno
);
for
(
i
=
0
;
i
<
acount
;
i
++
)
{
fprintf
(
stderr
,
" %u"
,
arcs
[
i
]);
}
fprintf
(
stderr
,
" }
\n
"
);
}
ret
=
OBJECT_IDENTIFIER_set_arcs
(
&
oid
,
arcs
,
sizeof
(
arcs
[
0
]),
acount
);
assert
(
ret
==
0
);
memset
(
tmp_arcs
,
'A'
,
sizeof
(
tmp_arcs
));
alen
=
OBJECT_IDENTIFIER_get_arcs
(
&
oid
,
tmp_arcs
,
sizeof
(
tmp_arcs
[
0
]),
tmp_alen
);
assert
(
alen
>=
0
);
assert
(
alen
<=
tmp_alen
);
assert
(
alen
==
acount
);
if
(
0
)
{
fprintf
(
stderr
,
"Encoded (O) { "
);
for
(
i
=
0
;
i
<
alen
;
i
++
)
{
fprintf
(
stderr
,
"%lu "
,
tmp_arcs
[
i
]);
fflush
(
stdout
);
assert
(
arcs
[
i
]
==
(
int
)
tmp_arcs
[
i
]);
}
fprintf
(
stderr
,
"}
\n
"
);
}
ASN_STRUCT_RESET
(
asn_DEF_RELATIVE_OID
,
&
oid
);
}
static
int
check_speed
()
{
uint8_t
buf
[]
=
{
0x80
|
7
,
0x80
|
2
,
0x80
|
3
,
0x80
|
4
,
13
};
...
...
@@ -288,24 +204,17 @@ static void check_xer(int expect_arcs, char *xer) {
#define CHECK_ROID(n) \
check_ROID(__LINE__, buf##n, sizeof(buf##n), buf##n##_check, \
sizeof(buf##n##_check) / sizeof(buf##n##_check[0]))
#define CHECK_REGEN(n) \
check_REGEN(__LINE__, buf##n##_check, \
sizeof(buf##n##_check) / sizeof(buf##n##_check[0]))
#define CHECK_REGEN_OID(n) \
check_REGEN_OID(__LINE__, buf##n##_check, \
sizeof(buf##n##_check) / sizeof(buf##n##_check[0]))
int
main
()
{
int
i
;
static
void
check_binary_parsing
()
{
/* {joint-iso-itu-t 230 3} */
/* {joint-iso-itu-t 230 3} */
uint8_t
buf1
[]
=
{
0x06
,
/* OBJECT IDENTIFIER */
0x03
,
/* Length */
0x82
,
0x36
,
0x03
};
int
buf1_check
[]
=
{
2
,
230
,
3
};
unsigned
buf1_check
[]
=
{
2
,
230
,
3
};
/* {8571 3 2} */
uint8_t
buf2
[]
=
{
...
...
@@ -313,7 +222,7 @@ main() {
0x04
,
/* Length */
0xC2
,
0x7B
,
0x03
,
0x02
};
int
buf2_check
[]
=
{
8571
,
3
,
2
};
unsigned
buf2_check
[]
=
{
8571
,
3
,
2
};
/* {joint-iso-itu-t 42 } */
uint8_t
buf3
[]
=
{
...
...
@@ -321,7 +230,7 @@ main() {
0x01
,
/* Length */
0x7A
};
int
buf3_check
[]
=
{
2
,
42
};
unsigned
buf3_check
[]
=
{
2
,
42
};
/* {joint-iso-itu-t 25957 } */
uint8_t
buf4
[]
=
{
...
...
@@ -329,74 +238,36 @@ main() {
0x03
,
/* Length */
0x81
,
0x80
+
0x4B
,
0x35
};
int
buf4_check
[]
=
{
2
,
25957
};
int
buf5_check
[]
=
{
0
};
int
buf6_check
[]
=
{
1
};
int
buf7_check
[]
=
{
80
,
40
};
int
buf8_check
[]
=
{
127
};
int
buf9_check
[]
=
{
128
};
int
buf10_check
[]
=
{
65535
,
65536
};
int
buf11_check
[]
=
{
100000
,
0x20000
,
1234
,
256
,
127
,
128
};
int
buf12_check
[]
=
{
0
,
0xffffffff
,
0xff00ff00
,
0
};
int
buf13_check
[]
=
{
0
,
1
,
2
};
int
buf14_check
[]
=
{
1
,
38
,
3
};
int
buf15_check
[]
=
{
0
,
0
,
0xf000
};
int
buf16_check
[]
=
{
0
,
0
,
0
,
1
,
0
};
int
buf17_check
[]
=
{
2
,
0xffffffAf
,
0xff00ff00
,
0
};
int
buf18_check
[]
=
{
2
,
2
,
1
,
1
};
/* { joint-iso-itu-t 2 1 1 } */
uint8_t
buf19
[]
=
{
unsigned
buf4_check
[]
=
{
2
,
25957
};
/* { jounsigned-iso-itu-t 2 1 1 } */
uint8_t
buf5
[]
=
{
0x06
,
/* OBJECT IDENTIFIER */
0x03
,
/* Length */
0x52
,
0x01
,
0x01
};
int
buf19
_check
[]
=
{
2
,
2
,
1
,
1
};
unsigned
buf5
_check
[]
=
{
2
,
2
,
1
,
1
};
/* { jo
int
-iso-itu-t 2 1 0 1 } */
uint8_t
buf
20
[]
=
{
/* { jo
unsigned
-iso-itu-t 2 1 0 1 } */
uint8_t
buf
6
[]
=
{
0x06
,
/* OBJECT IDENTIFIER */
0x04
,
/* Length */
0x52
,
0x01
,
0x00
,
0x01
};
int
buf20_check
[]
=
{
2
,
2
,
1
,
0
,
1
};
CHECK_OID
(
1
);
/* buf1, buf1_check */
CHECK_ROID
(
2
);
/* buf2, buf2_check */
CHECK_OID
(
3
);
/* buf3, buf3_check */
CHECK_OID
(
4
);
/* buf4, buf4_check */
CHECK_OID
(
19
);
/* buf19, buf19_check */
CHECK_OID
(
20
);
/* buf20, buf20_check */
CHECK_REGEN
(
5
);
/* Regenerate RELATIVE-OID */
CHECK_REGEN
(
6
);
CHECK_REGEN
(
7
);
CHECK_REGEN
(
8
);
CHECK_REGEN
(
9
);
CHECK_REGEN
(
10
);
CHECK_REGEN
(
11
);
CHECK_REGEN
(
12
);
CHECK_REGEN
(
13
);
CHECK_REGEN
(
14
);
CHECK_REGEN
(
15
);
CHECK_REGEN
(
16
);
CHECK_REGEN
(
17
);
CHECK_REGEN_OID
(
1
);
/* Regenerate OBJECT IDENTIFIER */
CHECK_REGEN_OID
(
3
);
/* Regenerate OBJECT IDENTIFIER */
CHECK_REGEN_OID
(
4
);
/* Regenerate OBJECT IDENTIFIER */
CHECK_REGEN_OID
(
13
);
CHECK_REGEN_OID
(
14
);
CHECK_REGEN_OID
(
15
);
CHECK_REGEN_OID
(
16
);
CHECK_REGEN_OID
(
17
);
CHECK_REGEN_OID
(
18
);
CHECK_REGEN_OID
(
19
);
CHECK_REGEN_OID
(
20
);
check_parse
(
""
,
0
);
check_parse
(
" "
,
0
);
unsigned
buf6_check
[]
=
{
2
,
2
,
1
,
0
,
1
};
CHECK_OID
(
1
);
CHECK_ROID
(
2
);
CHECK_OID
(
3
);
CHECK_OID
(
4
);
CHECK_OID
(
5
);
CHECK_OID
(
6
);
}
static
void
check_text_parsing
()
{
check_parse
(
""
,
0
);
check_parse
(
" "
,
0
);
check_parse
(
"."
,
-
1
);
check_parse
(
" ."
,
-
1
);
check_parse
(
".1"
,
-
1
);
...
...
@@ -440,24 +311,22 @@ main() {
}
check_parse
(
"1.900a0000000.3"
,
-
1
);
check_parse
(
"1.900a.3"
,
-
1
);
}
static
void
check_xer_parsing
()
{
check_xer
(
-
1
,
"<t></t>"
);
check_xer
(
2
,
"<t>1.2</t>"
);
check_xer
(
3
,
"<t>1.2.3</t>"
);
check_xer
(
3
,
"<t> 1.2.3 </t>"
);
check_xer
(
-
1
,
"<t>1.2.3 1</t>"
);
}
for
(
i
=
0
;
i
<
100000
;
i
++
)
{
int
bufA_check
[
3
]
=
{
2
,
i
,
rand
()
};
int
bufB_check
[
2
]
=
{
rand
(),
i
*
121
};
CHECK_REGEN
(
A
);
CHECK_REGEN_OID
(
A
);
CHECK_REGEN
(
B
);
if
(
i
>
100
)
i
++
;
if
(
i
>
500
)
i
++
;
if
(
i
>
1000
)
i
+=
3
;
if
(
i
>
5000
)
i
+=
151
;
}
int
main
()
{
check_binary_parsing
();
check_text_parsing
();
check_xer_parsing
();
if
(
getenv
(
"CHECK_SPEED"
))
{
/* Useful for developers only */
...
...
tests/tests-skeletons/check-PER-INTEGER.c
View file @
6cbed3dd
...
...
@@ -40,6 +40,11 @@ check_per_encode_constrained(int lineno, int unsigned_, long value, long lbound,
printf
(
"%d: Recoding %s %ld [%ld..%lu]
\n
"
,
lineno
,
unsigned_
?
"unsigned"
:
"signed"
,
value
,
lbound
,
ubound
);
if
(
ubound
>
LONG_MAX
)
{
printf
(
"Skipped test, unsupported
\n
"
);
return
;
}
memset
(
&
st
,
0
,
sizeof
(
st
));
memset
(
&
po
,
0
,
sizeof
(
po
));
memset
(
&
pd
,
0
,
sizeof
(
pd
));
...
...
@@ -89,8 +94,12 @@ check_per_encode_constrained(int lineno, int unsigned_, long value, long lbound,
|
((
uint32_t
)
po
.
tmpspace
[
2
]
<<
8
)
|
((
uint32_t
)
po
.
tmpspace
[
3
]
<<
0
);
recovered_value
=
(
unsigned
long
)
recovered_value
>>
(
32
-
bit_range
);
recovered_value
+=
cts
.
value
.
lower_bound
;
assert
((
long
)
recovered_value
==
value
);
if
(
per_long_range_unrebase
(
recovered_value
,
cts
.
value
.
lower_bound
,
cts
.
value
.
upper_bound
,
&
recovered_value
)
<
0
)
{
assert
(
!
"Unreachable"
);
}
assert
(
recovered_value
==
value
);
}
assert
(
po
.
nboff
==
(
size_t
)((
bit_range
==
32
)
?
0
:
(
8
-
(
32
-
bit_range
))));
assert
(
po
.
nbits
==
8
*
(
sizeof
(
po
.
tmpspace
)
-
(
po
.
buffer
-
po
.
tmpspace
)));
...
...
@@ -173,6 +182,7 @@ main() {
CHECK
(
0
,
-
2147483648
,
-
2147483648
,
2147483647
,
32
);
CHECK
(
0
,
-
10
,
-
2147483648
,
2147483647
,
32
);
CHECK
(
0
,
-
1
,
-
2147483648
,
2147483647
,
32
);
CHECK
(
0
,
0
,
INT32_MIN
,
INT32_MAX
,
32
);
CHECK
(
0
,
0
,
-
2147483648
,
2147483647
,
32
);
CHECK
(
0
,
1
,
-
2147483648
,
2147483647
,
32
);
CHECK
(
0
,
10
,
-
2147483648
,
2147483647
,
32
);
...
...
@@ -183,13 +193,17 @@ main() {
CHECK
(
1
,
10
,
0
,
4294967295UL
,
32
);
CHECK
(
1
,
2000000000
,
0
,
4294967295UL
,
32
);
CHECK
(
1
,
2147483647
,
0
,
4294967295UL
,
32
);
#ifdef TEST_64BIT
CHECK
(
1
,
2147483648
,
0
,
4294967295UL
,
32
);
CHECK
(
1
,
4000000000
,
0
,
4294967295UL
,
32
);
CHECK
(
1
,
4294967295UL
,
0
,
4294967295UL
,
32
);
#endif
CHECK
(
1
,
10
,
10
,
4294967285UL
,
32
);
CHECK
(
1
,
11
,
10
,
4294967285UL
,
32
);
#ifdef TEST_64BIT
if
(
sizeof
(
long
)
>
sizeof
(
uint32_t
))
{
CHECK
(
0
,
0
,
-
10
,
4294967285UL
,
32
);
CHECK
(
0
,
1
,
-
10
,
4294967285UL
,
32
);
...
...
@@ -211,6 +225,7 @@ main() {
CHECK
(
u
,
2147483648
,
0
,
4294967295UL
,
32
);
CHECK
(
u
,
4000000000
,
0
,
4294967295UL
,
32
);
}
#endif
}
return
0
;
...
...
tests/tests-skeletons/check-PER-support.c
View file @
6cbed3dd
...
...
@@ -61,8 +61,12 @@ check_round_trip(size_t length) {
assert
(
recovered
==
length
);
}
int
main
()
{
/*
* Checks that we can get the PER length that we have just put,
* and receive the same value.
*/
static
void
check_round_trips
()
{
check_round_trip
(
0
);
check_round_trip
(
1
);
check_round_trip
(
127
);
...
...
@@ -80,6 +84,192 @@ int main() {
check_round_trip
(
i
*
16384
);
check_round_trip
(
i
*
16384
+
1
);
}
}
#define OK_UNREBASE(w, l, u, c) check_unrebase(__LINE__, 0, w, l, u, c)
#define NO_UNREBASE(w, l, u) check_unrebase(__LINE__, 1, w, l, u, 0)
static
void
check_unrebase
(
int
lineno
,
int
expected_to_fail
,
unsigned
long
wire_value
,
long
lb
,
long
ub
,
long
control
)
{
fprintf
(
stderr
,
"%03d: Checking recovery of %lu (%ld..%ld)"
,
lineno
,
wire_value
,
lb
,
ub
);
if
(
expected_to_fail
)
{
fprintf
(
stderr
,
" to FAIL
\n
"
);
}
else
{
fprintf
(
stderr
,
" into %ld
\n
"
,
control
);
}
long
outcome
;
int
ret
=
per_long_range_unrebase
(
wire_value
,
lb
,
ub
,
&
outcome
);
if
(
ret
==
0
)
{
assert
(
!
expected_to_fail
);
}
else
{
assert
(
expected_to_fail
);
return
;
}
assert
(
outcome
==
control
);
}
#define OK_REBASE_ROUNDTRIP(v, l, u) \
check_range_rebase_round_trip(__LINE__, 0, v, l, u)
#define NO_REBASE_ROUNDTRIP(v, l, u) \
check_range_rebase_round_trip(__LINE__, 1, v, l, u)
static
void
check_range_rebase_round_trip
(
int
lineno
,
int
expected_to_fail
,
long
value
,
long
lb
,
long
ub
)
{
unsigned
long
wire_value
;
int
ret
;
fprintf
(
stderr
,
"%03d: Rebase %ld into (%ld..%ld) %s
\n
"
,
lineno
,
value
,
lb
,
ub
,
expected_to_fail
?
"FAIL"
:
"OK"
);
ret
=
per_long_range_rebase
(
value
,
lb
,
ub
,
&
wire_value
);
if
(
ret
!=
0
)
{
if
(
expected_to_fail
)
{
return
;
}
else
{
fprintf
(
stderr
,
"%03d: Original %ld (%ld..%ld) failed to rebase
\n
"
,
lineno
,
value
,
lb
,
ub
);
assert
(
ret
==
0
);
}
}
if
(
expected_to_fail
)
{
fprintf
(
stderr
,
"%03d: Original %ld (%ld..%ld) rebased to %lu where it shouldn't
\n
"
,
lineno
,
value
,
lb
,
ub
,
wire_value
);
assert
(
expected_to_fail
&&
ret
==
-
1
);
}
fprintf
(
stderr
,
"%03d: Recover %lu into (%ld..%ld)
\n
"
,
lineno
,
wire_value
,
lb
,
ub
);
long
recovered
;
ret
=
per_long_range_unrebase
(
wire_value
,
lb
,
ub
,
&
recovered
);
if
(
ret
!=
0
)
{
fprintf
(
stderr
,
"%03d: Wire value %lu (%ld..%ld) failed to unrebase
\n
"
,
lineno
,
wire_value
,
lb
,
ub
);
assert
(
ret
==
0
);
}
if
(
value
!=
recovered
)
{
fprintf
(
stderr
,
"%03d: Value %ld (%ld..%ld) failed to round-trip (=%ld)
\n
"
,
lineno
,
value
,
lb
,
ub
,
recovered
);
assert
(
value
==
recovered
);
}
}
static
void
check_range_rebase
()
{
OK_UNREBASE
(
0U
,
0
,
0
,
0
);
NO_UNREBASE
(
1U
,
0
,
0
);
OK_UNREBASE
(
0
,
LONG_MAX
,
LONG_MAX
,
LONG_MAX
);
NO_UNREBASE
(
1
,
LONG_MAX
,
LONG_MAX
);
OK_UNREBASE
(
0
,
LONG_MAX
-
1
,
LONG_MAX
-
1
,
LONG_MAX
-
1
);
NO_UNREBASE
(
1
,
LONG_MAX
-
1
,
LONG_MAX
-
1
);
OK_REBASE_ROUNDTRIP
(
0
,
0
,
0
);
OK_REBASE_ROUNDTRIP
(
0
,
0
,
1
);
OK_REBASE_ROUNDTRIP
(
1
,
0
,
1
);
NO_REBASE_ROUNDTRIP
(
-
1
,
0
,
0
);
NO_REBASE_ROUNDTRIP
(
1
,
0
,
0
);
NO_REBASE_ROUNDTRIP
(
LONG_MIN
,
0
,
0
);
NO_REBASE_ROUNDTRIP
(
LONG_MAX
,
0
,
0
);
OK_REBASE_ROUNDTRIP
(
-
2
,
-
2
,
-
1
);
OK_REBASE_ROUNDTRIP
(
-
1
,
-
2
,
-
1
);
NO_REBASE_ROUNDTRIP
(
-
3
,
-
2
,
-
1
);
NO_REBASE_ROUNDTRIP
(
0
,
-
2
,
-
1
);
OK_REBASE_ROUNDTRIP
(
LONG_MAX
,
LONG_MAX
,
LONG_MAX
);
NO_REBASE_ROUNDTRIP
(
LONG_MAX
-
1
,
LONG_MAX
,
LONG_MAX
);
NO_REBASE_ROUNDTRIP
(
0
,
LONG_MAX
,
LONG_MAX
);
NO_REBASE_ROUNDTRIP
(
LONG_MIN
,
LONG_MAX
,
LONG_MAX
);
NO_REBASE_ROUNDTRIP
(
LONG_MIN
+
1
,
LONG_MAX
,
LONG_MAX
);
OK_REBASE_ROUNDTRIP
(
LONG_MIN
,
LONG_MIN
,
LONG_MIN
);
NO_REBASE_ROUNDTRIP
(
LONG_MIN
+
1
,
LONG_MIN
,
LONG_MIN
);
NO_REBASE_ROUNDTRIP
(
0
,
LONG_MIN
,
LONG_MIN
);
NO_REBASE_ROUNDTRIP
(
LONG_MAX
-
1
,
LONG_MIN
,
LONG_MIN
);
NO_REBASE_ROUNDTRIP
(
LONG_MAX
,
LONG_MIN
,
LONG_MIN
);
OK_REBASE_ROUNDTRIP
(
LONG_MAX
-
10
,
LONG_MAX
-
10
,
LONG_MAX
-
5
);
OK_REBASE_ROUNDTRIP
(
LONG_MAX
-
5
,
LONG_MAX
-
10
,
LONG_MAX
-
5
);
OK_REBASE_ROUNDTRIP
(
LONG_MAX
-
7
,
LONG_MAX
-
10
,
LONG_MAX
-
5
);
NO_REBASE_ROUNDTRIP
(
LONG_MAX
-
4
,
LONG_MAX
-
10
,
LONG_MAX
-
5
);
NO_REBASE_ROUNDTRIP
(
LONG_MIN
,
LONG_MIN
+
1
,
LONG_MIN
+
2
);
OK_REBASE_ROUNDTRIP
(
LONG_MIN
+
1
,
LONG_MIN
+
1
,
LONG_MIN
+
2
);
OK_REBASE_ROUNDTRIP
(
LONG_MIN
+
2
,
LONG_MIN
+
1
,
LONG_MIN
+
2
);
NO_REBASE_ROUNDTRIP
(
LONG_MIN
+
3
,
LONG_MIN
+
1
,
LONG_MIN
+
2
);
OK_REBASE_ROUNDTRIP
(
LONG_MIN
,
LONG_MIN
,
LONG_MIN
+
1
);
OK_REBASE_ROUNDTRIP
(
LONG_MIN
+
1
,
LONG_MIN
,
0
);
OK_REBASE_ROUNDTRIP
(
LONG_MIN
+
1
,
LONG_MIN
,
LONG_MIN
+
1
);
NO_REBASE_ROUNDTRIP
(
LONG_MIN
+
2
,
LONG_MIN
,
LONG_MIN
+
1
);
OK_REBASE_ROUNDTRIP
(
-
1
,
-
1
,
1
);
OK_REBASE_ROUNDTRIP
(
0
,
-
1
,
1
);
OK_REBASE_ROUNDTRIP
(
1
,
-
1
,
1
);
NO_REBASE_ROUNDTRIP
(
-
2
,
-
1
,
1
);
NO_REBASE_ROUNDTRIP
(
2
,
-
1
,
1
);
NO_REBASE_ROUNDTRIP
(
LONG_MIN
,
-
1
,
1
);
NO_REBASE_ROUNDTRIP
(
LONG_MAX
,
-
1
,
1
);
OK_REBASE_ROUNDTRIP
(
-
1
,
LONG_MIN
,
LONG_MAX
);
OK_REBASE_ROUNDTRIP
(
0
,
LONG_MIN
,
LONG_MAX
);
OK_REBASE_ROUNDTRIP
(
1
,
LONG_MIN
,
LONG_MAX
);
OK_REBASE_ROUNDTRIP
(
LONG_MIN
,
LONG_MIN
,
LONG_MAX
);
OK_REBASE_ROUNDTRIP
(
LONG_MAX
,
LONG_MIN
,
LONG_MAX
);
if
(
sizeof
(
long
)
==
8
)
{
OK_REBASE_ROUNDTRIP
(
0
,
LONG_MIN
,
LONG_MAX
);
/* Too wide range, not fit uint32_t */
OK_REBASE_ROUNDTRIP
(
INT32_MIN
,
(
long
)
INT32_MIN
-
1
,
(
long
)
INT32_MAX
+
1
);
OK_REBASE_ROUNDTRIP
(
INT32_MAX
,
(
long
)
INT32_MIN
-
1
,
(
long
)
INT32_MAX
+
1
);
OK_REBASE_ROUNDTRIP
((
long
)
INT32_MIN
-
1
,
(
long
)
INT32_MIN
-
1
,
(
long
)
INT32_MAX
+
1
);
OK_REBASE_ROUNDTRIP
((
long
)
INT32_MAX
+
1
,
(
long
)
INT32_MIN
-
1
,
(
long
)
INT32_MAX
+
1
);
NO_REBASE_ROUNDTRIP
(
LONG_MIN
,
(
long
)
INT32_MIN
-
1
,
(
long
)
INT32_MAX
+
1
);
NO_REBASE_ROUNDTRIP
(
LONG_MAX
,
(
long
)
INT32_MIN
-
1
,
(
long
)
INT32_MAX
+
1
);
NO_REBASE_ROUNDTRIP
(((
long
)
INT32_MIN
)
-
1
,
INT32_MIN
,
INT32_MAX
);
NO_REBASE_ROUNDTRIP
(((
long
)
INT32_MAX
)
+
1
,
INT32_MIN
,
INT32_MAX
);
NO_REBASE_ROUNDTRIP
(
LONG_MIN
,
INT32_MIN
,
INT32_MAX
);
NO_REBASE_ROUNDTRIP
(
LONG_MAX
,
INT32_MIN
,
INT32_MAX
);
}
OK_REBASE_ROUNDTRIP
(
-
1
,
LONG_MIN
+
1
,
LONG_MAX
-
1
);
OK_REBASE_ROUNDTRIP
(
0
,
LONG_MIN
+
1
,
LONG_MAX
-
1
);
OK_REBASE_ROUNDTRIP
(
-
1
,
LONG_MIN
+
1
,
LONG_MAX
-
1
);
OK_REBASE_ROUNDTRIP
(
LONG_MIN
+
1
,
LONG_MIN
+
1
,
LONG_MAX
-
1
);
OK_REBASE_ROUNDTRIP
(
LONG_MAX
-
1
,
LONG_MIN
+
1
,
LONG_MAX
-
1
);
NO_REBASE_ROUNDTRIP
(
LONG_MIN
,
LONG_MIN
+
1
,
LONG_MAX
-
1
);
NO_REBASE_ROUNDTRIP
(
LONG_MAX
,
LONG_MIN
+
1
,
LONG_MAX
-
1
);
if
(
sizeof
(
long
)
==
8
)
{
NO_REBASE_ROUNDTRIP
(
LONG_MIN
,
INT32_MIN
+
1
,
INT32_MAX
-
1
);
NO_REBASE_ROUNDTRIP
(
LONG_MAX
,
INT32_MIN
+
1
,
INT32_MAX
-
1
);
}
}
int
main
()
{
check_range_rebase
();
check_round_trips
();
}
tests/tests-skeletons/check-REAL.c
View file @
6cbed3dd
...
...
@@ -215,7 +215,7 @@ check_ber_buffer_twoway(double d, const char *sample, const char *canonical_samp
ret
=
asn_double2REAL
(
&
rn
,
d
);
assert
(
ret
==
0
);
if
((
size_t
)
rn
.
size
!=
outsize
)
{
printf
(
"Encoded %f into %d expected %
l
d
\n
"
,
printf
(
"Encoded %f into %d expected %
z
d
\n
"
,
d
,
(
int
)
rn
.
size
,
outsize
);
assert
((
size_t
)
rn
.
size
==
outsize
);
}
...
...
tests/tests-skeletons/check-ber_tlv_tag.c
View file @
6cbed3dd
...
...
@@ -145,5 +145,6 @@ check_encode(struct tag_control_s *ctrl) {
}
}
printf
(
"
\n
"
);
}
tests/tests-skeletons/check-length.c
View file @
6cbed3dd
...
...
@@ -80,44 +80,48 @@ check(size_t size) {
int
main
()
{
uint8_t
buf1
[]
=
{
0x85
,
0x00
,
0x01
,
0x02
,
0x03
,
0x04
};
uint8_t
buf2
[]
=
{
0x85
,
0x00
,
0x7f
,
0xff
,
0x03
,
0x04
};
uint8_t
buf3
[]
=
{
0x85
,
0x00
,
0x7f
,
0xff
,
0xff
,
0x04
};
uint8_t
buf4
[]
=
{
0x89
,
0x00
,
0x7f
,
0xff
,
0xff
,
0xff
,
0xff
,
0xff
,
0xff
,
0x04
};
ber_tlv_len_t
tlv_len
;
ssize_t
ret
;
for
(
size_t
i
=
0
;
i
<
66000
;
i
++
)
{
if
(
i
==
4500
)
i
=
64000
;
/* Jump */
check
(
i
);
}
ret
=
ber_fetch_length
(
0
,
buf1
,
sizeof
(
buf1
),
&
tlv_len
);
printf
(
"ret=%ld, len=%ld
\n
"
,
(
long
)
ret
,
(
long
)
tlv_len
);
assert
(
ret
==
sizeof
(
buf1
));
assert
(
tlv_len
==
0x01020304
);
ret
=
ber_fetch_length
(
0
,
buf2
,
sizeof
(
buf2
),
&
tlv_len
);
printf
(
"ret=%ld, len=%ld
\n
"
,
(
long
)
ret
,
(
long
)
tlv_len
);
assert
(
ret
==
sizeof
(
buf2
));
assert
(
tlv_len
==
0x7fff0304
);
/*
* Here although tlv_len is not greater than 2^31,
* we ought to hit an embedded length exploitation preventive check.
*/
printf
(
"sizeof(tlv_len) = %d
\n
"
,
(
int
)
sizeof
(
tlv_len
));
if
(
sizeof
(
tlv_len
)
<=
4
)
{
ret
=
ber_fetch_length
(
0
,
buf3
,
sizeof
(
buf3
),
&
tlv_len
);
printf
(
"ret=%ld
\n
"
,
(
long
)
ret
);
printf
(
"len=0x%x
\n
"
,
(
unsigned
int
)
tlv_len
);
assert
(
ret
==
-
1
);
}
if
(
sizeof
(
tlv_len
)
<=
8
)
{
ret
=
ber_fetch_length
(
0
,
buf4
,
sizeof
(
buf4
),
&
tlv_len
);
printf
(
"ret=%lld
\n
"
,
(
long
long
)
ret
);
assert
(
ret
==
-
1
);
}
return
0
;
uint8_t
buf1
[]
=
{
0x85
,
0x00
,
0x01
,
0x02
,
0x03
,
0x04
};
uint8_t
buf2
[]
=
{
0x85
,
0x00
,
0x7f
,
0xff
,
0x03
,
0x04
};
uint8_t
buf3
[]
=
{
0x85
,
0x00
,
0x7f
,
0xff
,
0xff
,
0x04
};
uint8_t
buf4
[]
=
{
0x89
,
0x00
,
0x7f
,
0xff
,
0xff
,
0xff
,
0xff
,
0xff
,
0xff
,
0x04
};
ber_tlv_len_t
tlv_len
;
ssize_t
ret
;
for
(
size_t
i
=
0
;
i
<
66000
;
i
++
)
{
if
(
i
==
4500
)
i
=
64000
;
/* Jump */
check
(
i
);
}
ret
=
ber_fetch_length
(
0
,
buf1
,
sizeof
(
buf1
),
&
tlv_len
);
printf
(
"ret=%zd, len=%zd
\n
"
,
ret
,
tlv_len
);
assert
(
ret
==
sizeof
(
buf1
));
assert
(
tlv_len
==
0x01020304
);
/*
* Here although tlv_len is not greater than 2^31,
* we ought to hit embedded length exploitation preventive checks.
*/
ret
=
ber_fetch_length
(
0
,
buf2
,
sizeof
(
buf2
),
&
tlv_len
);
if
(
sizeof
(
tlv_len
)
<=
4
)
{
assert
(
ret
==
-
1
);
}
else
{
printf
(
"ret=%zd, len=%zd
\n
"
,
ret
,
tlv_len
);
assert
(
ret
==
sizeof
(
buf2
));
assert
(
tlv_len
==
0x7fff0304
);
}
if
(
sizeof
(
tlv_len
)
<=
4
)
{
ret
=
ber_fetch_length
(
0
,
buf3
,
sizeof
(
buf3
),
&
tlv_len
);
printf
(
"ret=%zd
\n
"
,
ret
);
printf
(
"len=0x%08zx
\n
"
,
tlv_len
);
assert
(
ret
==
-
1
);
}
if
(
sizeof
(
tlv_len
)
<=
8
)
{
ret
=
ber_fetch_length
(
0
,
buf4
,
sizeof
(
buf4
),
&
tlv_len
);
printf
(
"ret=%zd
\n
"
,
ret
);
assert
(
ret
==
-
1
);
}
return
0
;
}
tests/tests-skeletons/disable-leak-check-m32.sh
0 → 100755
View file @
6cbed3dd
#!/bin/sh
#
# It is found that leak checker doesn't work in 32-bit mode.
# Disable in runtime.
#
if
echo
"
$*
"
|
sed
-e
's/.*--//'
|
grep
'check-32-'
>
/dev/null
;
then
unset
ASAN_OPTIONS
fi
exec
"
$@
"
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