Skip to content

Problem in ASN.1 UPER Enumerated Unpacking #1399

@zhouxt1

Description

@zhouxt1

Hi,

I found that the enum_unpack in lib/asn1/asn1_utils.cpp has some issues.

SRSASN_CODE pack_enum(bit_ref& bref, uint32_t enum_val, uint32_t nbits, uint32_t nof_noext)
{
  bool ext = enum_val >= nof_noext;
  HANDLE_CODE(bref.pack((bool)ext, 1));
  SRSASN_CODE ret;
  if (not ext) {
    ret = bref.pack(enum_val, nbits);
    // Potential fix: add some checks if enum_val is within the root
  } else {
    ret = pack_norm_small_non_neg_whole_number(bref, enum_val - nof_noext);
  }
  return ret;
}

The issue can be explained with this small example,

S1 ::= ENUMERATED { e1, e2, e3, ..., e4 }

The correct encoding of e4 should be [ 1 | 0000000 ] in binary.
However, here the code would accept [ 0 | 11 ] as e4 instead of rejecting it.

To fix it, simply add a check to see if enum_val is within the root.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions