Project

General

Profile

Bug #4388

bitvec: bitvec_read_field() can never return negative value on error

Added by fixeria 8 months ago. Updated 7 months ago.

Status:
New
Priority:
High
Assignee:
-
Category:
libosmocore
Target version:
-
Start date:
02/05/2020
Due date:
% Done:

10%

Spec Reference:

Description

The doxygen documentation of bitvec_read_field() tells us that it can return a negative on error:

/*! read part of the vector
 *  \param[in] bv The boolean vector to work on
 *  \param[in,out] read_index Where reading supposed to start in the vector
 *  \param[in] len How many bits to read from vector
 *  \returns read bits or *negative value on error*
 */
uint64_t bitvec_read_field(struct bitvec *bv, unsigned int *read_index, unsigned int len) { ... }

However, as can be seen its return value is unsigned - uint64_t. So actually it returns a huge number on error.

This can be seen in the logs of OsmoPCU:

| Padding = 22|86|86|86|86|18446744073709551594|

where 18446744073709551594 is basically a negative number casted to uint64_t.

History

#1 Updated by fixeria 8 months ago

  • Priority changed from Normal to High

Not sure how we're supposed to fix this problem. Changing the type of return value to 'int' does not seem to be a good solution. Most likely, we would have to deprecate this function in favor of a new one... or even multiple functions like bitvec_read_u8(), bitvec_read_u16(), bitvec_read_u32() and bitvec_read_u64().

#2 Updated by fixeria 7 months ago

  • % Done changed from 0 to 10

Unit test demonstrating the problem: https://gerrit.osmocom.org/c/libosmocore/+/17220.

Also available in: Atom PDF

Add picture from clipboard (Maximum size: 48.8 MB)