Project

General

Profile

Actions

Bug #64

open

added zero check to avoid integer overflow in uw-al

Added by Pietro Trabuio about 22 hours ago.

Status:
New
Priority:
Normal
Assignee:
-
Target version:
Start date:
07/30/2026
Due date:
% Done:

0%

Estimated time:

Description

This error is caused by a missing null check inside the method restoreSignedValue(…) of the file /home/pietro/signet/repos/DESERT_Underwater/DESERT_Framework/DESERT/physical/uw-al/packer.h.

Specifically, at line 178, the bitset my_bitset (created a couple of lines above) is accessed at position _num_compressed_bits - 1. When _num_compressed_bits is equal to 0, the value overflows to 4294967295, accessing unwanted memory and throwing an assertion:

/usr/include/c++/16/bitset:1294: std::bitset<_Nb>::reference std::bitset<_Nb>::operator[](std::size_t) [with long unsigned int _Nb = 32; std::size_t = long unsigned int]: Assertion '__position < _Nb' failed.

In my case, the specific call that causes this error is in DESERT_Underwater/DESERT_Framework/DESERT/physical/uw-al/packer_common/packer_common.cpp on line 323 inside packerCOMMON::unpackMyHdr(). When calling restoreSignedValue(), ch->errbitcnt_ is set to 0, causing the error.

This has always happened but was ignored, as by itself it does not seem to create any error. With newer versions of g++ (>=g++14), to avoid out-of-bounds memory access, the compilers are set up to throw hard errors. I was specifically using g++ (GCC) 16.1.1 20260515 (Red Hat 16.1.1-2) with Fedora 44.

I encountered this error while setting the destination address in the Application layer to 255, to use the broadcast functionality in ns. This error will be present every time the unpackMyHdr() method is called.

The fix adds a check for _num_compressed_bits == 0 and changes the way to access the bitset from the operator[] to .test(), which functions the exact same way but returns an error, not an assertion, in case of future errors.

Pull Request on Github: https://github.com/signetlabdei/DESERT_Underwater/pull/70

No data to display

Actions

Also available in: Atom PDF