Changeset 11130 in ntrip for trunk/BNC/src/RTCM3


Ignore:
Timestamp:
Oct 28, 2026, 9:32:30 AM (2 weeks ago)
Author:
stuerze
Message:

Some fixes from security point of view

Location:
trunk/BNC/src/RTCM3
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/BNC/src/RTCM3/RTCM3Decoder.cpp

    r11124 r11130  
    3939 * -----------------------------------------------------------------------*/
    4040
     41#include <atomic>
    4142#include <iostream>
    4243#include <iomanip>
    … …  
    241242/**
    242243 * Frequency numbers of GLONASS with an offset of 100 to detect unset values.
    243  * Gets filled by ephemeris and data blocks and shared between different streams.
     244 * Gets filled by ephemeris and data blocks and shared between different streams
     245 * (MSM4/6 streams without channel numbers use those of an ephemeris stream).
     246 * Atomic, as the streams are decoded in different threads.
    244247 */
    245 static int GLOFreq[RTCM3_MSM_NUMSAT];
     248static std::atomic<int> GLOFreq[RTCM3_MSM_NUMSAT];
    246249
    247250/*
    … …  
    19982001  GETSTRING(antnum, antenna)
    19992002  if ((antnum > -1 && antnum < 265) &&
    2000       (_antType.empty() || strncmp(_antType.back()._descriptor, antenna, recnum) != 0)) {
     2003      (_antType.empty() || int(strlen(_antType.back()._descriptor)) != antnum ||
     2004       strncmp(_antType.back()._descriptor, antenna, antnum) != 0)) {
    20012005    _antType.push_back(t_antInfo());
    20022006    memcpy(_antType.back()._descriptor, antenna, antnum);
    … …  
    20172021    GETSTRING(recsernum, recserialnum)
    20182022    if ((recnum > -1 && recnum < 265) &&
    2019         (_recType.empty() || strncmp(_recType.back()._descriptor, receiver, recnum) != 0)) {
     2023        (_recType.empty() || int(strlen(_recType.back()._descriptor)) != recnum ||
     2024         strncmp(_recType.back()._descriptor, receiver, recnum) != 0)) {
    20202025      _recType.push_back(t_recInfo());
    20212026      memcpy(_recType.back()._descriptor, receiver, recnum);
  • trunk/BNC/src/RTCM3/bits.h

    r11023 r11130  
    104104   b = variable to store size, s = variable to store string pointer */
    105105#define GETSTRING(b, s) { \
     106  if(size < 1) return false; \
    106107  b = *(data++); \
     108  --size; \
     109  if((b) > size) return false; \
    107110  s = (char *) data; \
    108111  data += b; \
    109   size -= b+1; \
     112  size -= b; \
    110113}
    111114
    … …  
    126129  }
    127130
     131/* up to 56 bits: less than 8 bits are pending in the 64-bit bitbuffer */
    128132#define ADDBITS(a, b) { \
    129     bitbuffer = (bitbuffer<<(a))|((b)&((1<<a)-1)); \
     133    bitbuffer = (bitbuffer<<(a))|((uint64_t)(b)&((1ULL<<(a))-1)); \
    130134    numbits += (a); \
    131135    STOREBITS \
  • trunk/BNC/src/RTCM3/clock_and_orbit/clock_orbit.h

    r11124 r11130  
    605605#define E_NADIR_ANGLE_DEPENDENT_CORR_RANGE_EXTENSION(a) ADDBITS(4,  a)                      /* DF+015 (new RTCM) to extend DF+021*/
    606606#define E_SATELLITE_SET_INDICATOR(a)                    ADDBITS(1,  a)                      /* DF+016 (new RTCM) */
    607 /* ADDBITS' mask "(1<<a)-1" uses a 32-bit int literal, so a plain
    608    ADDBITS(64, a) is broken the same way GETSSRBITS(a, 64) was on decode
    609    (see D_SATELLITE_MASK) - here even ADDBITS(32, ...) is unsafe, since
    610    shifting a 32-bit int by exactly its own width is undefined behavior
    611    too. Stay well clear of that edge by writing four 16-bit chunks. */
     607/* ADDBITS handles up to 56 bits, so the 64-bit mask is written as two
     608   32-bit halves (as GETSSRBITS(a, 64) does not work either, see
     609   D_SATELLITE_MASK). */
    612610#define E_SATELLITE_MASK(a)                             { \
    613611  uint64_t mask64_ = (a); \
    614   ADDBITS(16, (mask64_ >> 48) & 0xFFFFU) \
    615   ADDBITS(16, (mask64_ >> 32) & 0xFFFFU) \
    616   ADDBITS(16, (mask64_ >> 16) & 0xFFFFU) \
    617   ADDBITS(16,  mask64_        & 0xFFFFU) \
     612  ADDBITS(32, mask64_ >> 32) \
     613  ADDBITS(32, mask64_ & 0xFFFFFFFFU) \
    618614}                                                                                           /* DF394 */
    619615#define E_FREQUENCY_SET_INDICATOR(a)                    ADDBITS(1,  a)                      /* DF+017 (new RTCM) */
  • trunk/BNC/src/RTCM3/clock_and_orbit/clock_orbit_rtcm_new.cpp

    r11126 r11130  
    489489        if (md->Entries[i].nonDefaultIndicator &&
    490490            md->Entries[i].additionalParameterIndicator) {
    491           /* up to 255 bits, only 32 stored (leading bits zero); in pieces of
    492              16 bits, as ADDBITS cannot handle more than 30 bits */
     491          /* up to 255 bits, only 32 stored: leading zero bits (ADDBITS
     492             handles at most 56 bits at a time), then the value */
    493493          unsigned int k = md->Entries[i].additionalParameterNumBits;
    494           while (k) {
    495             unsigned int n = (k > 16) ? 16 : k;
     494          while (k > 32) {
     495            unsigned int n = (k - 32 > 56) ? 56 : k - 32;
     496            ADDBITS(n, 0)
    496497            k -= n;
    497             E_ADDITIONAL_MODEL_PARAMETER_DATA((k < 32) ? (md->Entries[i].additionalParameterData >> k) : 0, n)
    498           }
     498          }
     499          if (k)
     500            E_ADDITIONAL_MODEL_PARAMETER_DATA(md->Entries[i].additionalParameterData, k)
    499501      }
    500502    }
Note: See TracChangeset for help on using the changeset viewer.