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

Some fixes from security point of view

Location:
trunk/BNC/src/RTCM3/clock_and_orbit
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • 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.