mirror of
https://github.com/gnss-sdr/gnss-sdr
synced 2024-12-13 19:50:34 +00:00
Merge branch 'next' of https://github.com/carlesfernandez/gnss-sdr into next
This commit is contained in:
commit
aaeb01a073
@ -14,6 +14,7 @@
|
|||||||
|
|
||||||
### Improvements in Reliability:
|
### Improvements in Reliability:
|
||||||
|
|
||||||
|
- Decoding of navigation messages no longer rely on implementation defined behavior for shifting left a signed integer.
|
||||||
- Removed usage of functions with insecure API (e.g., strcpy)
|
- Removed usage of functions with insecure API (e.g., strcpy)
|
||||||
- Added clang-tidy checks clang-analyzer-security.*
|
- Added clang-tidy checks clang-analyzer-security.*
|
||||||
|
|
||||||
|
@ -137,7 +137,7 @@ INTEGER__dump(asn_TYPE_descriptor_t *td, const INTEGER_t *st, asn_app_consume_by
|
|||||||
} else {
|
} else {
|
||||||
accum = (*buf & 0x80) ? -1 : 0;
|
accum = (*buf & 0x80) ? -1 : 0;
|
||||||
for(; buf < buf_end; buf++)
|
for(; buf < buf_end; buf++)
|
||||||
accum = (accum << 8) | *buf;
|
accum = (accum * 256) | *buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
el = INTEGER_map_value2enum(specs, accum);
|
el = INTEGER_map_value2enum(specs, accum);
|
||||||
@ -545,7 +545,7 @@ INTEGER_encode_xer(asn_TYPE_descriptor_t *td, void *sptr,
|
|||||||
|
|
||||||
(void)ilevel;
|
(void)ilevel;
|
||||||
(void)flags;
|
(void)flags;
|
||||||
|
|
||||||
if(!st || !st->buf)
|
if(!st || !st->buf)
|
||||||
_ASN_ENCODE_FAILED;
|
_ASN_ENCODE_FAILED;
|
||||||
|
|
||||||
@ -818,7 +818,7 @@ asn_INTEGER2long(const INTEGER_t *iptr, long *lptr) {
|
|||||||
|
|
||||||
/* Conversion engine */
|
/* Conversion engine */
|
||||||
for(; b < end; b++)
|
for(; b < end; b++)
|
||||||
l = (l << 8) | *b;
|
l = (l * 256) | *b;
|
||||||
|
|
||||||
*lptr = l;
|
*lptr = l;
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -96,7 +96,8 @@ per_get_few_bits(asn_per_data_t *pd, int nbits) {
|
|||||||
/* The number of available bits in the stream allow
|
/* The number of available bits in the stream allow
|
||||||
* for the following operations to take place without
|
* for the following operations to take place without
|
||||||
* invoking the ->refill() function */
|
* invoking the ->refill() function */
|
||||||
accum = per_get_few_bits(&tpd, nbits - 24) << 24;
|
uint32_t two_twentyfour = 16777216;
|
||||||
|
accum = per_get_few_bits(&tpd, nbits - 24) * two_twentyfour;
|
||||||
accum |= per_get_few_bits(&tpd, 24);
|
accum |= per_get_few_bits(&tpd, 24);
|
||||||
} else {
|
} else {
|
||||||
per_get_undo(pd, nbits);
|
per_get_undo(pd, nbits);
|
||||||
@ -424,8 +425,11 @@ per_put_few_bits(asn_per_outp_t *po, uint32_t bits, int obits) {
|
|||||||
buf[2] = bits >> 8,
|
buf[2] = bits >> 8,
|
||||||
buf[3] = bits;
|
buf[3] = bits;
|
||||||
else {
|
else {
|
||||||
if(per_put_few_bits(po, bits >> (obits - 24), 24)) return -1;
|
if((obits - 24) > 0)
|
||||||
if(per_put_few_bits(po, bits, obits - 24)) return -1;
|
{
|
||||||
|
if(per_put_few_bits(po, bits >> (obits - 24), 24)) return -1;
|
||||||
|
}
|
||||||
|
if(per_put_few_bits(po, bits, obits - 24)) return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
ASN_DEBUG("[PER out %u/%x => %02x buf+%ld]",
|
ASN_DEBUG("[PER out %u/%x => %02x buf+%ld]",
|
||||||
|
@ -137,7 +137,7 @@ INTEGER__dump(asn_TYPE_descriptor_t *td, const INTEGER_t *st, asn_app_consume_by
|
|||||||
} else {
|
} else {
|
||||||
accum = (*buf & 0x80) ? -1 : 0;
|
accum = (*buf & 0x80) ? -1 : 0;
|
||||||
for(; buf < buf_end; buf++)
|
for(; buf < buf_end; buf++)
|
||||||
accum = (accum << 8) | *buf;
|
accum = (accum * 256) | *buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
el = INTEGER_map_value2enum(specs, accum);
|
el = INTEGER_map_value2enum(specs, accum);
|
||||||
@ -545,7 +545,7 @@ INTEGER_encode_xer(asn_TYPE_descriptor_t *td, void *sptr,
|
|||||||
|
|
||||||
(void)ilevel;
|
(void)ilevel;
|
||||||
(void)flags;
|
(void)flags;
|
||||||
|
|
||||||
if(!st || !st->buf)
|
if(!st || !st->buf)
|
||||||
_ASN_ENCODE_FAILED;
|
_ASN_ENCODE_FAILED;
|
||||||
|
|
||||||
@ -818,7 +818,7 @@ asn_INTEGER2long(const INTEGER_t *iptr, long *lptr) {
|
|||||||
|
|
||||||
/* Conversion engine */
|
/* Conversion engine */
|
||||||
for(; b < end; b++)
|
for(; b < end; b++)
|
||||||
l = (l << 8) | *b;
|
l = (l * 256) | *b;
|
||||||
|
|
||||||
*lptr = l;
|
*lptr = l;
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -96,7 +96,8 @@ per_get_few_bits(asn_per_data_t *pd, int nbits) {
|
|||||||
/* The number of available bits in the stream allow
|
/* The number of available bits in the stream allow
|
||||||
* for the following operations to take place without
|
* for the following operations to take place without
|
||||||
* invoking the ->refill() function */
|
* invoking the ->refill() function */
|
||||||
accum = per_get_few_bits(&tpd, nbits - 24) << 24;
|
uint32_t two_twentyfour = 16777216;
|
||||||
|
accum = per_get_few_bits(&tpd, nbits - 24) * two_twentyfour;
|
||||||
accum |= per_get_few_bits(&tpd, 24);
|
accum |= per_get_few_bits(&tpd, 24);
|
||||||
} else {
|
} else {
|
||||||
per_get_undo(pd, nbits);
|
per_get_undo(pd, nbits);
|
||||||
@ -424,7 +425,10 @@ per_put_few_bits(asn_per_outp_t *po, uint32_t bits, int obits) {
|
|||||||
buf[2] = bits >> 8,
|
buf[2] = bits >> 8,
|
||||||
buf[3] = bits;
|
buf[3] = bits;
|
||||||
else {
|
else {
|
||||||
if(per_put_few_bits(po, bits >> (obits - 24), 24)) return -1;
|
if((obits - 24) > 0)
|
||||||
|
{
|
||||||
|
if(per_put_few_bits(po, bits >> (obits - 24), 24)) return -1;
|
||||||
|
}
|
||||||
if(per_put_few_bits(po, bits, obits - 24)) return -1;
|
if(per_put_few_bits(po, bits, obits - 24)) return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,6 +34,7 @@
|
|||||||
#include "gnss_satellite.h"
|
#include "gnss_satellite.h"
|
||||||
#include <cmath> // for cos, sin, fmod, sqrt, atan2, fabs, floor
|
#include <cmath> // for cos, sin, fmod, sqrt, atan2, fabs, floor
|
||||||
#include <iostream> // for string, operator<<, cout, ostream, endl
|
#include <iostream> // for string, operator<<, cout, ostream, endl
|
||||||
|
#include <limits> // for std::numeric_limits
|
||||||
|
|
||||||
|
|
||||||
void Beidou_Dnav_Navigation_Message::reset()
|
void Beidou_Dnav_Navigation_Message::reset()
|
||||||
@ -273,55 +274,30 @@ int64_t Beidou_Dnav_Navigation_Message::read_navigation_signed(
|
|||||||
{
|
{
|
||||||
int64_t value = 0;
|
int64_t value = 0;
|
||||||
int32_t num_of_slices = parameter.size();
|
int32_t num_of_slices = parameter.size();
|
||||||
// Discriminate between 64 bits and 32 bits compiler
|
|
||||||
int32_t long_int_size_bytes = sizeof(int64_t);
|
|
||||||
if (long_int_size_bytes == 8) // if a long int takes 8 bytes, we are in a 64 bits system
|
|
||||||
{
|
|
||||||
// read the MSB and perform the sign extension
|
|
||||||
if (bits[BEIDOU_DNAV_SUBFRAME_DATA_BITS - parameter[0].first] == 1)
|
|
||||||
{
|
|
||||||
value ^= 0xFFFFFFFFFFFFFFFF; //64 bits variable
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
value &= 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int32_t i = 0; i < num_of_slices; i++)
|
// read the MSB and perform the sign extension
|
||||||
{
|
if (bits[BEIDOU_DNAV_SUBFRAME_DATA_BITS - parameter[0].first] == 1)
|
||||||
for (int32_t j = 0; j < parameter[i].second; j++)
|
{
|
||||||
{
|
value ^= 0xFFFFFFFFFFFFFFFF; // 64 bits variable
|
||||||
value <<= 1; //shift left
|
|
||||||
value &= 0xFFFFFFFFFFFFFFFE; //reset the corresponding bit (for the 64 bits variable)
|
|
||||||
if (bits[BEIDOU_DNAV_SUBFRAME_DATA_BITS - parameter[i].first - j] == 1)
|
|
||||||
{
|
|
||||||
value += 1; // insert the bit
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else // we assume we are in a 32 bits system
|
else
|
||||||
{
|
{
|
||||||
// read the MSB and perform the sign extension
|
value &= 0;
|
||||||
if (bits[BEIDOU_DNAV_SUBFRAME_DATA_BITS - parameter[0].first] == 1)
|
}
|
||||||
|
// Avoid saturation when decoding
|
||||||
|
if (value == std::numeric_limits<int64_t>::max() or value == std::numeric_limits<int64_t>::min())
|
||||||
|
{
|
||||||
|
value /= 2;
|
||||||
|
}
|
||||||
|
for (int32_t i = 0; i < num_of_slices; i++)
|
||||||
|
{
|
||||||
|
for (int32_t j = 0; j < parameter[i].second; j++)
|
||||||
{
|
{
|
||||||
value ^= 0xFFFFFFFF;
|
value *= 2; // shift left the signed integer
|
||||||
}
|
value &= 0xFFFFFFFFFFFFFFFE; // reset the corresponding bit (for the 64 bits variable)
|
||||||
else
|
if (bits[BEIDOU_DNAV_SUBFRAME_DATA_BITS - parameter[i].first - j] == 1)
|
||||||
{
|
|
||||||
value &= 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int32_t i = 0; i < num_of_slices; i++)
|
|
||||||
{
|
|
||||||
for (int32_t j = 0; j < parameter[i].second; j++)
|
|
||||||
{
|
{
|
||||||
value <<= 1; //shift left
|
value += 1; // insert the bit
|
||||||
value &= 0xFFFFFFFE; //reset the corresponding bit
|
|
||||||
if (bits[BEIDOU_DNAV_SUBFRAME_DATA_BITS - parameter[i].first - j] == 1)
|
|
||||||
{
|
|
||||||
value += 1; // insert the bit
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -36,6 +36,7 @@
|
|||||||
#include <glog/logging.h> // for DLOG
|
#include <glog/logging.h> // for DLOG
|
||||||
#include <algorithm> // for reverse
|
#include <algorithm> // for reverse
|
||||||
#include <iostream> // for operator<<
|
#include <iostream> // for operator<<
|
||||||
|
#include <limits> // for std::numeric_limits
|
||||||
|
|
||||||
|
|
||||||
using CRC_Galileo_INAV_type = boost::crc_optimal<24, 0x1864CFBU, 0x0, 0x0, false, false>;
|
using CRC_Galileo_INAV_type = boost::crc_optimal<24, 0x1864CFBU, 0x0, 0x0, false, false>;
|
||||||
@ -310,12 +311,16 @@ int64_t Galileo_Navigation_Message::read_navigation_signed(std::bitset<GALILEO_D
|
|||||||
{
|
{
|
||||||
value &= 0LL;
|
value &= 0LL;
|
||||||
}
|
}
|
||||||
|
// Avoid saturation when decoding
|
||||||
|
if (value == std::numeric_limits<int64_t>::max() or value == std::numeric_limits<int64_t>::min())
|
||||||
|
{
|
||||||
|
value /= 2;
|
||||||
|
}
|
||||||
for (int32_t i = 0; i < num_of_slices; i++)
|
for (int32_t i = 0; i < num_of_slices; i++)
|
||||||
{
|
{
|
||||||
for (int32_t j = 0; j < parameter[i].second; j++)
|
for (int32_t j = 0; j < parameter[i].second; j++)
|
||||||
{
|
{
|
||||||
value <<= 1; // shift left
|
value *= 2; // shift left the signed integer
|
||||||
value &= 0xFFFFFFFFFFFFFFFE; // reset the corresponding bit (for the 64 bits variable)
|
value &= 0xFFFFFFFFFFFFFFFE; // reset the corresponding bit (for the 64 bits variable)
|
||||||
if (static_cast<int>(bits[GALILEO_DATA_JK_BITS - parameter[i].first - j]) == 1)
|
if (static_cast<int>(bits[GALILEO_DATA_JK_BITS - parameter[i].first - j]) == 1)
|
||||||
{
|
{
|
||||||
|
@ -32,6 +32,7 @@
|
|||||||
|
|
||||||
#include "gps_cnav_navigation_message.h"
|
#include "gps_cnav_navigation_message.h"
|
||||||
#include "gnss_satellite.h"
|
#include "gnss_satellite.h"
|
||||||
|
#include <limits> // for std::numeric_limits
|
||||||
|
|
||||||
|
|
||||||
void Gps_CNAV_Navigation_Message::reset()
|
void Gps_CNAV_Navigation_Message::reset()
|
||||||
@ -121,12 +122,16 @@ int64_t Gps_CNAV_Navigation_Message::read_navigation_signed(std::bitset<GPS_CNAV
|
|||||||
{
|
{
|
||||||
value &= 0LL;
|
value &= 0LL;
|
||||||
}
|
}
|
||||||
|
// Avoid saturation when decoding
|
||||||
|
if (value == std::numeric_limits<int64_t>::max() or value == std::numeric_limits<int64_t>::min())
|
||||||
|
{
|
||||||
|
value /= 2;
|
||||||
|
}
|
||||||
for (int32_t i = 0; i < num_of_slices; i++)
|
for (int32_t i = 0; i < num_of_slices; i++)
|
||||||
{
|
{
|
||||||
for (int32_t j = 0; j < parameter[i].second; j++)
|
for (int32_t j = 0; j < parameter[i].second; j++)
|
||||||
{
|
{
|
||||||
value <<= 1; // shift left
|
value *= 2; // shift left the signed integer
|
||||||
value &= 0xFFFFFFFFFFFFFFFELL; // reset the corresponding bit (for the 64 bits variable)
|
value &= 0xFFFFFFFFFFFFFFFELL; // reset the corresponding bit (for the 64 bits variable)
|
||||||
if (static_cast<int>(bits[GPS_CNAV_DATA_PAGE_BITS - parameter[i].first - j]) == 1)
|
if (static_cast<int>(bits[GPS_CNAV_DATA_PAGE_BITS - parameter[i].first - j]) == 1)
|
||||||
{
|
{
|
||||||
|
@ -35,6 +35,7 @@ m * \file gps_navigation_message.cc
|
|||||||
#include <cmath> // for fmod, abs, floor
|
#include <cmath> // for fmod, abs, floor
|
||||||
#include <cstring> // for memcpy
|
#include <cstring> // for memcpy
|
||||||
#include <iostream> // for operator<<, cout, endl
|
#include <iostream> // for operator<<, cout, endl
|
||||||
|
#include <limits> // for std::numeric_limits
|
||||||
|
|
||||||
|
|
||||||
void Gps_Navigation_Message::reset()
|
void Gps_Navigation_Message::reset()
|
||||||
@ -211,12 +212,16 @@ int64_t Gps_Navigation_Message::read_navigation_signed(std::bitset<GPS_SUBFRAME_
|
|||||||
{
|
{
|
||||||
value &= 0LL;
|
value &= 0LL;
|
||||||
}
|
}
|
||||||
|
// Avoid salutation when decoding;
|
||||||
|
if (value == std::numeric_limits<int64_t>::max() or value == std::numeric_limits<int64_t>::min())
|
||||||
|
{
|
||||||
|
value /= 2;
|
||||||
|
}
|
||||||
for (int32_t i = 0; i < num_of_slices; i++)
|
for (int32_t i = 0; i < num_of_slices; i++)
|
||||||
{
|
{
|
||||||
for (int32_t j = 0; j < parameter[i].second; j++)
|
for (int32_t j = 0; j < parameter[i].second; j++)
|
||||||
{
|
{
|
||||||
value <<= 1; // shift left
|
value *= 2; // shift left the signed integer
|
||||||
value &= 0xFFFFFFFFFFFFFFFELL; // reset the corresponding bit (for the 64 bits variable)
|
value &= 0xFFFFFFFFFFFFFFFELL; // reset the corresponding bit (for the 64 bits variable)
|
||||||
if (static_cast<int>(bits[GPS_SUBFRAME_BITS - parameter[i].first - j]) == 1)
|
if (static_cast<int>(bits[GPS_SUBFRAME_BITS - parameter[i].first - j]) == 1)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user