1
0
mirror of https://github.com/mfontanini/libtins synced 2026-01-23 02:35:57 +01:00

Fix issues pointed out by scan.coverity

This commit is contained in:
Matias Fontanini
2016-03-07 20:29:12 -08:00
parent 42b6c40433
commit 97e24131c6
16 changed files with 57 additions and 32 deletions

View File

@@ -463,7 +463,8 @@ public:
uint16_t dwell_time;
uint8_t hop_set, hop_pattern, hop_index;
fh_params_set() {}
fh_params_set()
: dwell_time(0), hop_set(0), hop_pattern(0), hop_index(0) {}
fh_params_set(uint16_t dwell_time,
uint8_t hop_set,
@@ -482,7 +483,8 @@ public:
uint8_t cfp_count, cfp_period;
uint16_t cfp_max_duration, cfp_dur_remaining;
cf_params_set() {}
cf_params_set()
: cfp_count(0), cfp_period(0), cfp_max_duration(0), cfp_dur_remaining(0) {}
cf_params_set(uint8_t cfp_count,
uint8_t cfp_period,
@@ -505,7 +507,7 @@ public:
uint8_t recovery_interval;
channel_map_type channel_map;
ibss_dfs_params() {}
ibss_dfs_params() : recovery_interval(0) {}
ibss_dfs_params(const address_type& addr,
uint8_t recovery_interval,
@@ -547,7 +549,8 @@ public:
uint8_t flag, number_of_sets, modulus, offset;
byte_array random_table;
fh_pattern_type() {}
fh_pattern_type()
: flag(0), number_of_sets(0), modulus(0), offset(0) {}
fh_pattern_type(uint8_t flag,
uint8_t sets,
@@ -566,7 +569,8 @@ public:
struct channel_switch_type {
uint8_t switch_mode, new_channel, switch_count;
channel_switch_type() {}
channel_switch_type()
: switch_mode(0), new_channel(0), switch_count(0) {}
channel_switch_type(uint8_t mode,
uint8_t channel,
@@ -583,7 +587,8 @@ public:
uint8_t quiet_count, quiet_period;
uint16_t quiet_duration, quiet_offset;
quiet_type() {}
quiet_type()
: quiet_count(0), quiet_period(0), quiet_duration(0), quiet_offset(0) {}
quiet_type(uint8_t count,
uint8_t period,
@@ -603,7 +608,8 @@ public:
uint16_t available_capacity;
uint8_t channel_utilization;
bss_load_type() {}
bss_load_type()
: station_count(0), available_capacity(0), channel_utilization(0) {}
bss_load_type(uint16_t count, uint8_t utilization, uint16_t capacity)
: station_count(count), available_capacity(capacity),
@@ -619,7 +625,8 @@ public:
uint8_t dtim_count, dtim_period, bitmap_control;
byte_array partial_virtual_bitmap;
tim_type() {}
tim_type()
: dtim_count(0), dtim_period(0), bitmap_control(0) {}
tim_type(uint8_t count,
uint8_t period,

View File

@@ -507,7 +507,9 @@ private:
bool are_extensions_allowed() const;
icmp_header header_;
uint32_t orig_timestamp_or_address_mask_, recv_timestamp_, trans_timestamp_;
uint32_t orig_timestamp_or_address_mask_;
uint32_t recv_timestamp_;
uint32_t trans_timestamp_;
ICMPExtensionsStructure extensions_;
};

View File

@@ -251,8 +251,8 @@ public:
uint8_t prefix_len;
small_uint<1> A, L;
uint32_t valid_lifetime,
preferred_lifetime,
reserved2;
preferred_lifetime,
reserved2;
ipaddress_type prefix;
prefix_info_type(uint8_t prefix_len = 0,
@@ -262,7 +262,7 @@ public:
uint32_t preferred_lifetime = 0,
const ipaddress_type& prefix = ipaddress_type())
: prefix_len(prefix_len), A(A), L(L), valid_lifetime(valid_lifetime),
preferred_lifetime(preferred_lifetime), prefix(prefix) { }
preferred_lifetime(preferred_lifetime), reserved2(0), prefix(prefix) { }
static prefix_info_type from_option(const option& opt);
};

View File

@@ -333,8 +333,10 @@ public:
PDUOption(option_type opt = option_type(),
size_t length = 0,
const data_type* data = 0)
: option_(opt), size_(static_cast<uint16_t>(length)) {
set_payload_contents(data, data + (data ? length : 0));
: option_(opt), size_(static_cast<uint16_t>(length)), real_size_(0) {
if (data != 0) {
set_payload_contents(data, data + length);
}
}
/**

View File

@@ -506,10 +506,21 @@ private:
radiotap_hdr radio_;
// present fields...
uint64_t tsft_;
uint16_t channel_type_, channel_freq_, rx_flags_, signal_quality_, tx_flags_;
uint16_t channel_type_;
uint16_t channel_freq_;
uint16_t rx_flags_;
uint16_t signal_quality_;
uint16_t tx_flags_;
mcs_type mcs_;
uint8_t antenna_, flags_, rate_, channel_, max_power_, db_signal_, data_retries_;
int8_t dbm_signal_, dbm_noise_;
uint8_t antenna_;
uint8_t flags_;
uint8_t rate_;
uint8_t channel_;
uint8_t max_power_;
uint8_t db_signal_;
uint8_t data_retries_;
int8_t dbm_signal_;
int8_t dbm_noise_;
};
}

View File

@@ -297,7 +297,7 @@ public:
private:
// Compress all flags into just one struct using bitfields
struct flags {
flags() : ignore_data_packets(0), sack_permitted(0), ack_tracking(0) {
flags() : is_v6(0), ignore_data_packets(0), sack_permitted(0), ack_tracking(0) {
}

View File

@@ -60,10 +60,10 @@ public:
IPv4Address client_addr, server_addr;
uint16_t client_port, server_port;
StreamInfo() {}
StreamInfo() : client_port(0), server_port(0) {}
StreamInfo(IPv4Address client, IPv4Address server,
uint16_t cport, uint16_t sport);
uint16_t cport, uint16_t sport);
bool operator<(const StreamInfo& rhs) const;
};

View File

@@ -270,7 +270,7 @@ SessionKeys::SessionKeys(const ptk_type& ptk, bool is_ccmp)
}
SessionKeys::SessionKeys(const RSNHandshake& hs, const pmk_type& pmk)
: ptk_(PTK_SIZE) {
: ptk_(PTK_SIZE), is_ccmp_(false) {
if (pmk.size() != PMK_SIZE) {
throw invalid_handshake();
}

View File

@@ -605,7 +605,7 @@ bool DNS::matches_response(const uint8_t* ptr, uint32_t total_sz) const {
// SOA record
DNS::soa_record::soa_record()
: serial_(0), refresh_(0), retry_(0), expire_(0) {
: serial_(0), refresh_(0), retry_(0), expire_(0), minimum_ttl_(0) {
}

View File

@@ -196,7 +196,7 @@ uint32_t Dot11BlockAckRequest::header_size() const {
Dot11BlockAck::Dot11BlockAck(const address_type& dst_addr,
const address_type& target_addr)
: Dot11ControlTA(dst_addr, target_addr), bitmap_() {
: Dot11ControlTA(dst_addr, target_addr), bar_control_(0), start_sequence_(0), bitmap_() {
subtype(BLOCK_ACK);
}

View File

@@ -59,7 +59,8 @@ ICMP::ICMP(Flags flag)
type(flag);
}
ICMP::ICMP(const uint8_t* buffer, uint32_t total_sz) {
ICMP::ICMP(const uint8_t* buffer, uint32_t total_sz)
: orig_timestamp_or_address_mask_(), recv_timestamp_(), trans_timestamp_() {
InputMemoryStream stream(buffer, total_sz);
stream.read(header_);
if (type() == TIMESTAMP_REQUEST || type() == TIMESTAMP_REPLY) {

View File

@@ -47,13 +47,13 @@ using Tins::Memory::OutputMemoryStream;
namespace Tins {
ICMPv6::ICMPv6(Types tp)
: options_size_(), reach_time_(0), retrans_timer_(0) {
: options_size_(), reach_time_(0), retrans_timer_(0), mlqm_() {
memset(&header_, 0, sizeof(header_));
type(tp);
}
ICMPv6::ICMPv6(const uint8_t* buffer, uint32_t total_sz)
: options_size_(), reach_time_(0), retrans_timer_(0) {
: options_size_(), reach_time_(0), retrans_timer_(0), mlqm_() {
InputMemoryStream stream(buffer, total_sz);
stream.read(header_);
if (has_target_addr()) {
@@ -850,7 +850,7 @@ ICMPv6::prefix_info_type ICMPv6::prefix_info_type::from_option(const option& opt
output.A = (stream.read<uint8_t>() >> 6) & 0x1;
output.valid_lifetime = stream.read_be<uint32_t>();
output.preferred_lifetime = stream.read_be<uint32_t>();
stream.skip(sizeof(uint32_t));
output.reserved2 = stream.read_be<uint32_t>();
output.prefix = stream.read<ICMPv6::ipaddress_type>();
return output;
}

View File

@@ -39,7 +39,7 @@ namespace Tins {
namespace Internals {
IPv4Stream::IPv4Stream()
: received_end_(false), received_size_(), total_size_() {
: received_end_(false), transport_proto_(0xff), received_size_(), total_size_() {
}

View File

@@ -263,7 +263,9 @@ void PacketSender::open_l3_socket(SocketType type) {
#else
typedef const char* option_ptr;
#endif
setsockopt(sockfd, IPPROTO_IP, IP_HDRINCL,(option_ptr)&on,sizeof(on));
if (setsockopt(sockfd, IPPROTO_IP, IP_HDRINCL, (option_ptr)&on, sizeof(on)) != 0) {
throw socket_open_error(make_error_string());
}
sockets_[type] = static_cast<int>(sockfd);
}

View File

@@ -43,7 +43,7 @@ using Tins::Memory::OutputMemoryStream;
namespace Tins {
RSNInformation::RSNInformation()
: version_(1), capabilities_(0) {
: version_(1), capabilities_(0), group_suite_(static_cast<CypherSuites>(0)) {
}

View File

@@ -87,7 +87,7 @@ struct sniff_data {
PDU* pdu;
bool packet_processed;
sniff_data() : pdu(0), packet_processed(true) { }
sniff_data() : tv(), pdu(0), packet_processed(true) { }
};
template<typename T>
@@ -408,7 +408,7 @@ const unsigned SnifferConfiguration::DEFAULT_TIMEOUT = 1000;
SnifferConfiguration::SnifferConfiguration()
: flags_(0), snap_len_(DEFAULT_SNAP_LEN), buffer_size_(0), timeout_(DEFAULT_TIMEOUT),
promisc_(false), rfmon_(false), immediate_mode_(false) {
promisc_(false), rfmon_(false), immediate_mode_(false), direction_(PCAP_D_INOUT) {
}