Skip to content

Commit

Permalink
[ASN1C] Fixed asn1c library on 32bit (open5gs#2934)
Browse files Browse the repository at this point in the history
APER encoding fails when using the asn_uint642INTEGER function on a 32-bit machine as shown below.

```C
   asn_uint642INTEGER(AMF_UE_NGAP_ID, 0xffffffff);
   ...
   aper_encode_to_buffer(...)
```

INTEGER APER encode/decode functions seem to be operating internally with long variables instead of intmax_t.
That is probably the reason of the failure.

@v0-e fixed this issues in the mouse07410/asn1c pull request.
mouse07410/asn1c#176
mouse07410/asn1c#177
  • Loading branch information
acetcom committed Feb 12, 2024
1 parent 94bd68a commit 843c495
Show file tree
Hide file tree
Showing 3,528 changed files with 4,782 additions and 4,373 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
1 change: 1 addition & 0 deletions docker/debian/bookworm
1 change: 1 addition & 0 deletions docker/i386/debian
1 change: 1 addition & 0 deletions docker/i386/ubuntu
1 change: 1 addition & 0 deletions docker/ubuntu/lunar
1 change: 1 addition & 0 deletions docker/ubuntu/noble
56 changes: 56 additions & 0 deletions docs/_docs/troubleshoot/02-now-in-github-issues.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,62 @@ head_inline: "<style> .blue { color: blue; } </style>"
}
</style>

#### How to run wireshark from within Docker?

In the following, I will explain how to run wireshark on Ubuntu 32bit.

First, make the following modifications to get wireshark working.

```diff
$ diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml
index 01925303b..8d5e23a4f 100644
--- a/docker/docker-compose.yml
+++ b/docker/docker-compose.yml
@@ -105,7 +105,7 @@ services:
volumes:
- home:/home/${USER}
- ${HOME}:/mnt
- # - /tmp/.X11-unix:/tmp/.X11-unix
+ - /tmp/.X11-unix:/tmp/.X11-unix
# - /etc/localtime:/etc/localtime:ro
# - /usr/share/zoneinfo/Europe/Helsinki:/etc/localtime:ro
hostname: open5gs-dev

$ diff --git a/docker/ubuntu/latest/dev/Dockerfile b/docker/ubuntu/latest/dev/Dockerfile
index 970dddb72..6902fc59c 100644
--- a/docker/ubuntu/latest/dev/Dockerfile
+++ b/docker/ubuntu/latest/dev/Dockerfile
@@ -23,12 +23,12 @@ RUN apt-get update && \
net-tools && \
apt-get clean

-#RUN apt-get update && \
-# apt-get install -y software-properties-common && \
-# sudo add-apt-repository ppa:wireshark-dev/stable -y && \
-# apt-get update && \
-# DEBIAN_FRONTEND=noninteractive \
-# apt-get install -y wireshark
+RUN apt-get update && \
+ apt-get install -y software-properties-common && \
+ sudo add-apt-repository ppa:wireshark-dev/stable -y && \
+ apt-get update && \
+ DEBIAN_FRONTEND=noninteractive \
+ apt-get install -y wireshark

COPY setup.sh /root
```

It allows any program run by the docker user to communicate with X windows.
```
$ xhost +local:docker
```

And run 32bit ubuntu like below.
```
$ cd docker
$ DIST=i386/ubuntu docker compose run dev
```

#### What to do if a FATAL occurs?

You may occasionally encounter a FATAL like the one below.
Expand Down
3 changes: 3 additions & 0 deletions lib/asn1c/common/ANY.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ asn_TYPE_operation_t asn_OP_ANY = {
0,
#endif /* !defined(ASN_DISABLE_PRINT_SUPPORT) */
OCTET_STRING_compare,
OCTET_STRING_copy,
#if !defined(ASN_DISABLE_BER_SUPPORT)
OCTET_STRING_decode_ber,
OCTET_STRING_encode_der,
Expand All @@ -33,9 +34,11 @@ asn_TYPE_operation_t asn_OP_ANY = {
0,
#endif /* !defined(ASN_DISABLE_XER_SUPPORT) */
#if !defined(ASN_DISABLE_JER_SUPPORT)
OCTET_STRING_decode_jer_hex,
ANY_encode_jer,
#else
0,
0,
#endif /* !defined(ASN_DISABLE_JER_SUPPORT) */
#if !defined(ASN_DISABLE_OER_SUPPORT)
0,
Expand Down
2 changes: 2 additions & 0 deletions lib/asn1c/common/ANY.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ extern asn_OCTET_STRING_specifics_t asn_SPC_ANY_specs;
#endif /* !defined(ASN_DISABLE_PRINT_SUPPORT) */

#define ANY_compare OCTET_STRING_compare
#define ANY_copy OCTET_STRING_copy

#define ANY_constraint asn_generic_no_constraint

Expand All @@ -43,6 +44,7 @@ xer_type_encoder_f ANY_encode_xer;
#endif /* !defined(ASN_DISABLE_XER_SUPPORT) */

#if !defined(ASN_DISABLE_JER_SUPPORT)
jer_type_decoder_f ANY_decode_jer;
jer_type_encoder_f ANY_encode_jer;
#endif /* !defined(ASN_DISABLE_JER_SUPPORT) */

Expand Down
37 changes: 37 additions & 0 deletions lib/asn1c/common/BIT_STRING.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ asn_TYPE_operation_t asn_OP_BIT_STRING = {
0,
#endif /* !defined(ASN_DISABLE_PRINT_SUPPORT) */
BIT_STRING_compare,
BIT_STRING_copy,
#if !defined(ASN_DISABLE_BER_SUPPORT)
OCTET_STRING_decode_ber, /* Implemented in terms of OCTET STRING */
OCTET_STRING_encode_der, /* Implemented in terms of OCTET STRING */
Expand All @@ -39,9 +40,11 @@ asn_TYPE_operation_t asn_OP_BIT_STRING = {
0,
#endif /* !defined(ASN_DISABLE_XER_SUPPORT) */
#if !defined(ASN_DISABLE_JER_SUPPORT)
OCTET_STRING_decode_jer_hex,
BIT_STRING_encode_jer,
#else
0,
0,
#endif /* !defined(ASN_DISABLE_JER_SUPPORT) */
#if !defined(ASN_DISABLE_OER_SUPPORT)
BIT_STRING_decode_oer,
Expand Down Expand Up @@ -211,3 +214,37 @@ BIT_STRING_compare(const asn_TYPE_descriptor_t *td, const void *aptr,
return 1;
}
}

int
BIT_STRING_copy(const asn_TYPE_descriptor_t *td, void **aptr,
const void *bptr) {
const asn_OCTET_STRING_specifics_t *specs = td->specifics;
BIT_STRING_t *a = (BIT_STRING_t *)*aptr;
const BIT_STRING_t *b = (const BIT_STRING_t *)bptr;

if(!b) {
if(a) {
FREEMEM(a->buf);
FREEMEM(a);
*aptr = 0;
}
return 0;
}

if(!a) {
a = *aptr = CALLOC(1, specs->struct_size);
if(!a) return -1;
}

uint8_t* buf = MALLOC(b->size + 1);
if(!buf) return -1;
memcpy(buf, b->buf, b->size);
buf[b->size] = 0;

FREEMEM(a->buf);
a->buf = buf;
a->size = b->size;
a->bits_unused = b->bits_unused;

return 0;
}
2 changes: 2 additions & 0 deletions lib/asn1c/common/BIT_STRING.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ asn_struct_print_f BIT_STRING_print; /* Human-readable output */
#endif /* !defined(ASN_DISABLE_PRINT_SUPPORT) */

asn_struct_compare_f BIT_STRING_compare;
asn_struct_copy_f BIT_STRING_copy;

asn_constr_check_f BIT_STRING_constraint;

Expand All @@ -45,6 +46,7 @@ xer_type_encoder_f BIT_STRING_encode_xer;
#endif /* !defined(ASN_DISABLE_XER_SUPPORT) */

#if !defined(ASN_DISABLE_JER_SUPPORT)
#define BIT_STRING_decode_jer OCTET_STRING_decode_jer_binary
jer_type_encoder_f BIT_STRING_encode_jer;
#endif /* !defined(ASN_DISABLE_JER_SUPPORT) */

Expand Down
92 changes: 92 additions & 0 deletions lib/asn1c/common/ENUMERATED.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/*-
* Copyright (c) 2003, 2005, 2006 Lev Walkin <vlm@lionet.info>.
* All rights reserved.
* Redistribution and modifications are permitted subject to BSD license.
*/
#include <asn_internal.h>
#include <ENUMERATED.h>

/*
* ENUMERATED basic type description.
*/
static const ber_tlv_tag_t asn_DEF_ENUMERATED_tags[] = {
(ASN_TAG_CLASS_UNIVERSAL | (10 << 2))
};
asn_TYPE_operation_t asn_OP_ENUMERATED = {
ASN__PRIMITIVE_TYPE_free,
#if !defined(ASN_DISABLE_PRINT_SUPPORT)
INTEGER_print, /* Implemented in terms of INTEGER */
#else
0,
#endif /* !defined(ASN_DISABLE_PRINT_SUPPORT) */
INTEGER_compare, /* Implemented in terms of INTEGER */
INTEGER_copy, /* Implemented in terms of INTEGER */
#if !defined(ASN_DISABLE_BER_SUPPORT)
ber_decode_primitive,
INTEGER_encode_der, /* Implemented in terms of INTEGER */
#else
0,
0,
#endif /* !defined(ASN_DISABLE_BER_SUPPORT) */
#if !defined(ASN_DISABLE_XER_SUPPORT)
INTEGER_decode_xer, /* This is temporary! */
INTEGER_encode_xer,
#else
0,
0,
#endif /* !defined(ASN_DISABLE_XER_SUPPORT) */
#if !defined(ASN_DISABLE_JER_SUPPORT)
ENUMERATED_decode_jer,
INTEGER_encode_jer,
#else
0,
0,
#endif /* !defined(ASN_DISABLE_JER_SUPPORT) */
#if !defined(ASN_DISABLE_OER_SUPPORT)
ENUMERATED_decode_oer,
ENUMERATED_encode_oer,
#else
0,
0,
#endif /* !defined(ASN_DISABLE_OER_SUPPORT) */
#if !defined(ASN_DISABLE_UPER_SUPPORT)
ENUMERATED_decode_uper, /* Unaligned PER decoder */
ENUMERATED_encode_uper, /* Unaligned PER encoder */
#else
0,
0,
#endif /* !defined(ASN_DISABLE_UPER_SUPPORT) */
#if !defined(ASN_DISABLE_APER_SUPPORT)
ENUMERATED_decode_aper, /* Aligned PER decoder */
ENUMERATED_encode_aper, /* Aligned PER encoder */
#else
0,
0,
#endif /* !defined(ASN_DISABLE_APER_SUPPORT) */
#if !defined(ASN_DISABLE_RFILL_SUPPORT)
ENUMERATED_random_fill,
#else
0,
#endif /* !defined(ASN_DISABLE_RFILL_SUPPORT) */
0 /* Use generic outmost tag fetcher */
};
asn_TYPE_descriptor_t asn_DEF_ENUMERATED = {
"ENUMERATED",
"ENUMERATED",
&asn_OP_ENUMERATED,
asn_DEF_ENUMERATED_tags,
sizeof(asn_DEF_ENUMERATED_tags) / sizeof(asn_DEF_ENUMERATED_tags[0]),
asn_DEF_ENUMERATED_tags, /* Same as above */
sizeof(asn_DEF_ENUMERATED_tags) / sizeof(asn_DEF_ENUMERATED_tags[0]),
{
#if !defined(ASN_DISABLE_OER_SUPPORT)
0,
#endif /* !defined(ASN_DISABLE_OER_SUPPORT) */
#if !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT)
0,
#endif /* !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) */
asn_generic_no_constraint
},
0, 0, /* No members */
0 /* No specifics */
};
67 changes: 67 additions & 0 deletions lib/asn1c/common/ENUMERATED.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*-
* Copyright (c) 2003-2017 Lev Walkin <vlm@lionet.info>. All rights reserved.
* Redistribution and modifications are permitted subject to BSD license.
*/
#ifndef _ENUMERATED_H_
#define _ENUMERATED_H_

#include <INTEGER.h>

#ifdef __cplusplus
extern "C" {
#endif

typedef INTEGER_t ENUMERATED_t; /* Implemented via INTEGER */

extern asn_TYPE_descriptor_t asn_DEF_ENUMERATED;
extern asn_TYPE_operation_t asn_OP_ENUMERATED;

#define ENUMERATED_free ASN__PRIMITIVE_TYPE_free

#if !defined(ASN_DISABLE_PRINT_SUPPORT)
#define ENUMERATED_print INTEGER_print
#endif /* !defined(ASN_DISABLE_PRINT_SUPPORT) */

#define ENUMERATED_compare INTEGER_compare
#define ENUMERATED_copy INTEGER_copy

#define ENUMERATED_constraint asn_generic_no_constraint

#if !defined(ASN_DISABLE_BER_SUPPORT)
#define ENUMERATED_decode_ber ber_decode_primitive
#define ENUMERATED_encode_der INTEGER_encode_der
#endif /* !defined(ASN_DISABLE_BER_SUPPORT) */

#if !defined(ASN_DISABLE_XER_SUPPORT)
#define ENUMERATED_decode_xer INTEGER_decode_xer
#define ENUMERATED_encode_xer INTEGER_encode_xer
#endif /* !defined(ASN_DISABLE_XER_SUPPORT) */

#if !defined(ASN_DISABLE_JER_SUPPORT)
jer_type_decoder_f ENUMERATED_decode_jer;
#define ENUMERATED_encode_jer INTEGER_encode_jer
#endif /* !defined(ASN_DISABLE_JER_SUPPORT) */

#if !defined(ASN_DISABLE_OER_SUPPORT)
oer_type_decoder_f ENUMERATED_decode_oer;
oer_type_encoder_f ENUMERATED_encode_oer;
#endif /* !defined(ASN_DISABLE_OER_SUPPORT) */

#if !defined(ASN_DISABLE_UPER_SUPPORT)
per_type_decoder_f ENUMERATED_decode_uper;
per_type_encoder_f ENUMERATED_encode_uper;
#endif /* !defined(ASN_DISABLE_UPER_SUPPORT) */
#if !defined(ASN_DISABLE_APER_SUPPORT)
per_type_decoder_f ENUMERATED_decode_aper;
per_type_encoder_f ENUMERATED_encode_aper;
#endif /* !defined(ASN_DISABLE_APER_SUPPORT) */

#if !defined(ASN_DISABLE_RFILL_SUPPORT)
#define ENUMERATED_random_fill INTEGER_random_fill
#endif /* !defined(ASN_DISABLE_RFILL_SUPPORT) */

#ifdef __cplusplus
}
#endif

#endif /* _ENUMERATED_H_ */
43 changes: 43 additions & 0 deletions lib/asn1c/common/ENUMERATED_aper.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright (c) 2017 Lev Walkin <vlm@lionet.info>.
* All rights reserved.
* Redistribution and modifications are permitted subject to BSD license.
*/
#include <asn_internal.h>
#include <ENUMERATED.h>
#include <NativeEnumerated.h>

asn_dec_rval_t
ENUMERATED_decode_aper(const asn_codec_ctx_t *opt_codec_ctx,
const asn_TYPE_descriptor_t *td,
const asn_per_constraints_t *constraints, void **sptr, asn_per_data_t *pd) {
asn_dec_rval_t rval;
ENUMERATED_t *st = (ENUMERATED_t *)*sptr;
long value;
void *vptr = &value;

if(!st) {
st = (ENUMERATED_t *)(*sptr = CALLOC(1, sizeof(*st)));
if(!st) ASN__DECODE_FAILED;
}

rval = NativeEnumerated_decode_aper(opt_codec_ctx, td, constraints,
(void **)&vptr, pd);
if(rval.code == RC_OK)
if(asn_long2INTEGER(st, value))
rval.code = RC_FAIL;
return rval;
}

asn_enc_rval_t
ENUMERATED_encode_aper(const asn_TYPE_descriptor_t *td,
const asn_per_constraints_t *constraints,
const void *sptr, asn_per_outp_t *po) {
const ENUMERATED_t *st = (const ENUMERATED_t *)sptr;
long value;

if(asn_INTEGER2long(st, &value))
ASN__ENCODE_FAILED;

return NativeEnumerated_encode_aper(td, constraints, &value, po);
}
Loading

0 comments on commit 843c495

Please sign in to comment.