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
798a79fb
Commit
798a79fb
authored
Jul 12, 2022
by
Pau Espin Pedrol
Committed by
Mouse
Jul 12, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
aper: Uncover bug encoding OCTET_STRING with constrained size
parent
81d4017d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
90 additions
and
0 deletions
+90
-0
tests/tests-skeletons/Makefile.am
tests/tests-skeletons/Makefile.am
+5
-0
tests/tests-skeletons/check-APER-OCTET_STRING.c
tests/tests-skeletons/check-APER-OCTET_STRING.c
+85
-0
No files found.
tests/tests-skeletons/Makefile.am
View file @
798a79fb
...
...
@@ -16,6 +16,7 @@ check_PROGRAMS = \
check-OER-INTEGER
\
check-OER-NativeEnumerated
\
check-APER-support
\
check-APER-OCTET_STRING
\
check-APER-INTEGER
\
check-UPER-support
\
check-UPER-UniversalString
\
...
...
@@ -38,6 +39,7 @@ check_PROGRAMS += \
check-32-OER-INTEGER
\
check-32-OER-NativeEnumerated
\
check-32-APER-support
\
check-32-APER-OCTET_STRING
\
check-32-APER-INTEGER
\
check-32-UPER-support
\
check-32-UPER-UniversalString
\
...
...
@@ -88,6 +90,9 @@ check_32_OER_NativeEnumerated_SOURCES=check-OER-NativeEnumerated.c
check_32_APER_support_CFLAGS
=
$(CFLAGS_M32)
check_32_APER_support_LDADD
=
$(LDADD_32)
check_32_APER_support_SOURCES
=
check-APER-support.c
check_32_APER_OCTET_STRING_CFLAGS
=
$(CFLAGS_M32)
check_32_APER_OCTET_STRING_LDADD
=
$(LDADD_32)
check_32_APER_OCTET_STRING_SOURCES
=
check-APER-OCTET_STRING.c
check_32_APER_INTEGER_CFLAGS
=
$(CFLAGS_M32)
check_32_APER_INTEGER_LDADD
=
$(LDADD_32)
check_32_APER_INTEGER_SOURCES
=
check-APER-INTEGER.c
...
...
tests/tests-skeletons/check-APER-OCTET_STRING.c
0 → 100644
View file @
798a79fb
#include <stdio.h>
#include <assert.h>
#include <time.h>
#include <sys/time.h>
#include <OCTET_STRING.h>
#include <OCTET_STRING.c>
#include <OCTET_STRING_aper.c>
#include <BIT_STRING.h>
#include <per_support.c>
#include <aper_support.h>
static
char
buf
[
1024
];
static
int
write_buf
(
const
void
*
buffer
,
size_t
size
,
void
*
key
)
{
size_t
*
off
=
key
;
assert
(
*
off
+
size
<
sizeof
(
buf
));
memcpy
(
buf
+
*
off
,
buffer
,
size
);
*
off
+=
size
;
return
0
;
}
extern
asn_enc_rval_t
OCTET_STRING_encode_aper
(
const
asn_TYPE_descriptor_t
*
td
,
const
asn_per_constraints_t
*
constraints
,
const
void
*
sptr
,
asn_per_outp_t
*
po
);
static
void
encode_constrained_size
(
char
*
orig
,
char
*
encoded
,
long
lbound
,
unsigned
long
ubound
,
int
bit_range
)
{
OCTET_STRING_t
os
;
asn_enc_rval_t
er
;
struct
asn_per_constraints_s
cts
;
asn_per_outp_t
po
;
#if 0
char *out_str;
#endif
memset
(
&
os
,
0
,
sizeof
(
os
));
OCTET_STRING_fromString
(
&
os
,
orig
);
memset
(
&
po
,
0
,
sizeof
(
po
));
memset
(
&
cts
,
0
,
sizeof
(
cts
));
cts
.
value
.
flags
=
APC_UNCONSTRAINED
;
cts
.
value
.
range_bits
=
-
1
;
cts
.
value
.
effective_bits
=
-
1
;
cts
.
value
.
lower_bound
=
0
;
cts
.
value
.
upper_bound
=
0
;
cts
.
size
.
flags
=
APC_CONSTRAINED
;
cts
.
size
.
range_bits
=
bit_range
;
cts
.
size
.
effective_bits
=
bit_range
;
cts
.
size
.
lower_bound
=
lbound
;
cts
.
size
.
upper_bound
=
ubound
;
po
.
buffer
=
po
.
tmpspace
;
po
.
nboff
=
0
;
po
.
nbits
=
8
*
sizeof
(
po
.
tmpspace
);
po
.
output
=
write_buf
;
er
=
OCTET_STRING_encode_aper
(
&
asn_DEF_OCTET_STRING
,
&
cts
,
&
os
,
&
po
);
assert
(
er
.
encoded
<
0
);
/* BUG! it should be >= 0 */
#if 0
unsigned l = (po.buffer - po.tmpspace) + (po.nboff + 7)/8;
memcpy(&buf[er.encoded], po.tmpspace, l);
er.encoded += l;
buf[er.encoded] = '\0';
/* Get rid of length at start: */
out_str = &buf[0] + (cts.size.effective_bits + 7) / 8;
printf("Orig: [%s], encoded: [%s], check [%s]\n",
orig, out_str, encoded);
assert(strcmp(out_str, encoded) == 0);
#endif
ASN_STRUCT_RESET
(
asn_DEF_OCTET_STRING
,
&
os
);
}
int
main
()
{
encode_constrained_size
(
"12345678901234567890"
,
"12345678901234567890"
,
1
,
9600
,
14
);
return
0
;
}
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