1
0
mirror of https://github.com/mfontanini/libtins synced 2026-01-29 21:14:28 +01:00

assert() is only called when TINS_DEBUG is defined.

This commit is contained in:
Matias Fontanini
2013-04-22 18:45:56 -03:00
parent 7e0e85db65
commit 66ff604580
25 changed files with 115 additions and 8626 deletions

View File

@@ -58,9 +58,13 @@ subdir = .
DIST_COMMON = README $(am__configure_deps) $(libtins_include_HEADERS) \
$(srcdir)/Makefile.am $(srcdir)/Makefile.in \
$(srcdir)/libtins.pc.in $(top_srcdir)/configure AUTHORS THANKS \
config.guess config.sub depcomp install-sh ltmain.sh missing
TODO config.guess config.sub depcomp install-sh ltmain.sh \
missing
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
am__aclocal_m4_deps = $(top_srcdir)/configure.ac
am__aclocal_m4_deps = $(top_srcdir)/m4/libtool.m4 \
$(top_srcdir)/m4/ltoptions.m4 $(top_srcdir)/m4/ltsugar.m4 \
$(top_srcdir)/m4/ltversion.m4 $(top_srcdir)/m4/lt~obsolete.m4 \
$(top_srcdir)/configure.ac
am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
$(ACLOCAL_M4)
am__CONFIG_DISTCLEAN_FILES = config.status config.cache config.log \

8611
aclocal.m4 vendored

File diff suppressed because it is too large Load Diff

4
configure vendored
View File

@@ -7914,6 +7914,10 @@ _lt_linker_boilerplate=`cat conftest.err`
$RM -r conftest*
## CAVEAT EMPTOR:
## There is no encapsulation within the following macros, do not change
## the running order or otherwise move them around unless you know exactly
## what you are doing...
if test -n "$compiler"; then
lt_prog_compiler_no_builtin_flag=

View File

@@ -108,7 +108,9 @@ uint32_t ARP::header_size() const {
}
void ARP::write_serialization(uint8_t *buffer, uint32_t total_sz, const PDU *) {
#ifdef TINS_DEBUG
assert(total_sz >= sizeof(arphdr));
#endif
memcpy(buffer, &_arp, sizeof(arphdr));
}

View File

@@ -114,7 +114,9 @@ void BootP::vend(const vend_type &new_vend) {
}
void BootP::write_serialization(uint8_t *buffer, uint32_t total_sz, const PDU *parent) {
#ifdef TINS_DEBUG
assert(total_sz >= sizeof(bootphdr) + _vend.size());
#endif
std::memcpy(buffer, &_bootp, sizeof(bootphdr));
std::copy(_vend.begin(), _vend.end(), buffer + sizeof(bootphdr));
}

View File

@@ -216,7 +216,9 @@ uint32_t DHCP::header_size() const {
}
void DHCP::write_serialization(uint8_t *buffer, uint32_t total_sz, const PDU *parent) {
#ifdef TINS_DEBUG
assert(total_sz >= header_size());
#endif
if(_size) {
vend_type &result(BootP::vend());
result.resize(_size);

View File

@@ -294,7 +294,9 @@ void DNS::unparse_domain_name(const std::string &dn, std::string &out) const {
}
void DNS::write_serialization(uint8_t *buffer, uint32_t total_sz, const PDU *parent) {
#ifdef TINS_DEBUG
assert(total_sz >= sizeof(dns) + extra_size);
#endif
std::memcpy(buffer, &dns, sizeof(dns));
buffer += sizeof(dns);
for(list<Query>::const_iterator it(queries_.begin()); it != queries_.end(); ++it) {

View File

@@ -203,8 +203,9 @@ void Dot11::send(PacketSender &sender, const NetworkInterface &iface) {
#endif // WIN32
void Dot11::write_serialization(uint8_t *buffer, uint32_t total_sz, const PDU *parent) {
uint32_t my_sz = header_size();
assert(total_sz >= my_sz);
#ifdef TINS_DEBUG
assert(total_sz >= header_size());
#endif
memcpy(buffer, &_header, sizeof(_header));
buffer += sizeof(_header);
total_sz -= sizeof(_header);
@@ -215,7 +216,9 @@ void Dot11::write_serialization(uint8_t *buffer, uint32_t total_sz, const PDU *p
uint32_t child_len = write_fixed_parameters(buffer, total_sz - _options_size);
buffer += child_len;
#ifdef TINS_DEBUG
assert(total_sz >= child_len + _options_size);
#endif
for(std::list<option>::const_iterator it = _options.begin(); it != _options.end(); ++it) {
*(buffer++) = it->option();
*(buffer++) = it->length_field();
@@ -881,7 +884,9 @@ uint32_t Dot11Beacon::header_size() const {
uint32_t Dot11Beacon::write_fixed_parameters(uint8_t *buffer, uint32_t total_sz) {
uint32_t sz = sizeof(_body);
#ifdef TINS_DEBUG
assert(sz <= total_sz);
#endif
memcpy(buffer, &this->_body, sz);
return sz;
}
@@ -919,7 +924,9 @@ uint32_t Dot11Disassoc::header_size() const {
uint32_t Dot11Disassoc::write_fixed_parameters(uint8_t *buffer, uint32_t total_sz) {
uint32_t sz = sizeof(DisassocBody);
#ifdef TINS_DEBUG
assert(sz <= total_sz);
#endif
memcpy(buffer, &this->_body, sz);
return sz;
}
@@ -958,7 +965,9 @@ uint32_t Dot11AssocRequest::header_size() const {
uint32_t Dot11AssocRequest::write_fixed_parameters(uint8_t *buffer, uint32_t total_sz) {
uint32_t sz = sizeof(AssocReqBody);
#ifdef TINS_DEBUG
assert(sz <= total_sz);
#endif
memcpy(buffer, &this->_body, sz);
return sz;
}
@@ -1001,7 +1010,9 @@ uint32_t Dot11AssocResponse::header_size() const {
uint32_t Dot11AssocResponse::write_fixed_parameters(uint8_t *buffer, uint32_t total_sz) {
uint32_t sz = sizeof(AssocRespBody);
#ifdef TINS_DEBUG
assert(sz <= total_sz);
#endif
memcpy(buffer, &this->_body, sz);
return sz;
}
@@ -1044,7 +1055,9 @@ uint32_t Dot11ReAssocRequest::header_size() const {
uint32_t Dot11ReAssocRequest::write_fixed_parameters(uint8_t *buffer, uint32_t total_sz) {
uint32_t sz = sizeof(this->_body);
#ifdef TINS_DEBUG
assert(sz <= total_sz);
#endif
memcpy(buffer, &this->_body, sz);
return sz;
}
@@ -1086,7 +1099,9 @@ uint32_t Dot11ReAssocResponse::header_size() const {
uint32_t Dot11ReAssocResponse::write_fixed_parameters(uint8_t *buffer, uint32_t total_sz) {
uint32_t sz = sizeof(this->_body);
#ifdef TINS_DEBUG
assert(sz <= total_sz);
#endif
memcpy(buffer, &this->_body, sz);
return sz;
}
@@ -1134,7 +1149,9 @@ uint32_t Dot11Authentication::header_size() const {
uint32_t Dot11Authentication::write_fixed_parameters(uint8_t *buffer, uint32_t total_sz) {
uint32_t sz = sizeof(this->_body);
#ifdef TINS_DEBUG
assert(sz <= total_sz);
#endif
memcpy(buffer, &this->_body, sz);
return sz;
}
@@ -1172,7 +1189,9 @@ uint32_t Dot11Deauthentication::header_size() const {
uint32_t Dot11Deauthentication::write_fixed_parameters(uint8_t *buffer, uint32_t total_sz) {
uint32_t sz = sizeof(this->_body);
#ifdef TINS_DEBUG
assert(sz <= total_sz);
#endif
memcpy(buffer, &this->_body, sz);
return sz;
}
@@ -1233,7 +1252,9 @@ uint32_t Dot11ProbeResponse::header_size() const {
uint32_t Dot11ProbeResponse::write_fixed_parameters(uint8_t *buffer, uint32_t total_sz) {
uint32_t sz = sizeof(this->_body);
#ifdef TINS_DEBUG
assert(sz <= total_sz);
#endif
memcpy(buffer, &this->_body, sz);
return sz;
}
@@ -1372,7 +1393,9 @@ uint32_t Dot11QoSData::header_size() const {
uint32_t Dot11QoSData::write_fixed_parameters(uint8_t *buffer, uint32_t total_sz) {
uint32_t sz = sizeof(this->_qos_control);
#ifdef TINS_DEBUG
assert(sz <= total_sz);
#endif
*(uint16_t*)buffer = this->_qos_control;
return sz;
}
@@ -1413,7 +1436,9 @@ uint32_t Dot11ControlTA::header_size() const {
}
uint32_t Dot11ControlTA::write_ext_header(uint8_t *buffer, uint32_t total_sz) {
#ifdef TINS_DEBUG
assert(total_sz >= sizeof(_taddr));
#endif
//std::memcpy(buffer, _taddr, sizeof(_taddr));
_taddr.copy(buffer);
return sizeof(_taddr);

View File

@@ -101,7 +101,7 @@ uint32_t Dot1Q::trailer_size() const {
void Dot1Q::write_serialization(uint8_t *buffer, uint32_t total_sz, const PDU *) {
uint32_t trailer = trailer_size();
#ifdef TINS_DEBUG
assert(total_sz >= sizeof(_header) + trailer);
assert(total_sz >= sizeof(_header) + trailer);
#endif
if ((payload_type() == 0) && inner_pdu()) {
Constants::Ethernet::e flag = Internals::pdu_flag_to_ether_type(

View File

@@ -27,7 +27,9 @@
*
*/
#ifdef TINS_DEBUG
#include <cassert>
#endif
#include <cstring>
#include <stdexcept>
#include <algorithm>
@@ -127,9 +129,10 @@ bool Dot3::matches_response(const uint8_t *ptr, uint32_t total_sz) const {
}
void Dot3::write_serialization(uint8_t *buffer, uint32_t total_sz, const PDU *parent) {
uint32_t my_sz = header_size();
bool set_length = _eth.length == 0;
assert(total_sz >= my_sz);
#ifdef TINS_DEBUG
assert(total_sz >= header_size());
#endif
if (set_length)
_eth.length = Endian::host_to_be(size() - sizeof(_eth));

View File

@@ -28,7 +28,9 @@
*/
#include <cstring>
#ifdef TINS_DEBUG
#include <cassert>
#endif
#include <stdexcept>
#include "eapol.h"
#include "dot11.h"
@@ -84,8 +86,9 @@ void EAPOL::type(uint8_t new_type) {
}
void EAPOL::write_serialization(uint8_t *buffer, uint32_t total_sz, const PDU *) {
uint32_t sz = header_size();
assert(total_sz >= sz);
#ifdef TINS_DEBUG
assert(total_sz >= header_size());
#endif
std::memcpy(buffer, &_header, sizeof(_header));
write_body(buffer + sizeof(_header), total_sz - sizeof(_header));
}
@@ -145,8 +148,9 @@ uint32_t RC4EAPOL::header_size() const {
}
void RC4EAPOL::write_body(uint8_t *buffer, uint32_t total_sz) {
uint32_t sz = sizeof(_header) + _key.size();
assert(total_sz >= sz);
#ifdef TINS_DEBUG
assert(total_sz >= sizeof(_header) + _key.size());
#endif
if(_key.size())
_header.key_length = Endian::host_to_be(_key.size());
std::memcpy(buffer, &_header, sizeof(_header));
@@ -259,8 +263,9 @@ uint32_t RSNEAPOL::header_size() const {
}
void RSNEAPOL::write_body(uint8_t *buffer, uint32_t total_sz) {
uint32_t sz = header_size() - sizeof(eapolhdr);
assert(total_sz >= sz);
#ifdef TINS_DEBUG
assert(total_sz >= header_size() - sizeof(eapolhdr));
#endif
if(_key.size()) {
if(!_header.key_t) {
_header.key_length = Endian::host_to_be<uint16_t>(32);

View File

@@ -27,7 +27,9 @@
*
*/
#ifdef TINS_DEBUG
#include <cassert>
#endif
#include <cstring>
#include <stdexcept>
#include <algorithm>
@@ -138,8 +140,9 @@ bool EthernetII::matches_response(const uint8_t *ptr, uint32_t total_sz) const {
}
void EthernetII::write_serialization(uint8_t *buffer, uint32_t total_sz, const PDU *parent) {
uint32_t my_sz = header_size();
assert(total_sz >= my_sz);
#ifdef TINS_DEBUG
assert(total_sz >= header_size());
#endif
/* Inner type defaults to IP */
if ((_eth.payload_type == 0) && inner_pdu()) {

View File

@@ -29,7 +29,9 @@
#include <stdexcept>
#include <cstring>
#ifdef TINS_DEBUG
#include <cassert>
#endif
#ifndef WIN32
#define NOMINMAX
#include <netinet/in.h>
@@ -148,7 +150,9 @@ void ICMP::set_redirect(uint8_t icode, uint32_t address) {
}
void ICMP::write_serialization(uint8_t *buffer, uint32_t total_sz, const PDU *) {
#ifdef TINS_DEBUG
assert(total_sz >= sizeof(icmphdr));
#endif
if(!_icmp.check) {
uint32_t checksum = Utils::do_checksum(buffer + sizeof(icmphdr), buffer + total_sz) +
Utils::do_checksum((uint8_t*)&_icmp, ((uint8_t*)&_icmp) + sizeof(icmphdr));

View File

@@ -27,7 +27,9 @@
*
*/
#ifdef TINS_DEBUG
#include <cassert>
#endif
#include <cstring>
#include "icmpv6.h"
#include "ipv6.h"
@@ -217,6 +219,7 @@ void ICMPv6::write_serialization(uint8_t *buffer, uint32_t total_sz, const PDU *
for(options_type::const_iterator it = _options.begin(); it != _options.end(); ++it) {
#ifdef TINS_DEBUG
assert(total_sz >= it->data_size() + sizeof(uint8_t) * 2);
// total_sz is only used if TINS_DEBUG is defined.
total_sz -= it->data_size() + sizeof(uint8_t) * 2;
#endif
buffer = write_option(*it, buffer);

View File

@@ -29,7 +29,9 @@
#include <stdexcept>
#include <cstring>
#ifdef TINS_DEBUG
#include <cassert>
#endif
#include <algorithm>
#ifndef WIN32
#include <netdb.h>
@@ -380,7 +382,9 @@ void IP::prepare_for_serialize(const PDU *parent) {
void IP::write_serialization(uint8_t *buffer, uint32_t total_sz, const PDU* parent) {
uint32_t my_sz = header_size();
#ifdef TINS_DEBUG
assert(total_sz >= my_sz);
#endif
check(0);
if(inner_pdu()) {
uint32_t new_flag;

View File

@@ -28,7 +28,9 @@
*/
#include <cstring>
#ifdef TINS_DEBUG
#include <cassert>
#endif
#ifndef WIN32
#include <netinet/in.h>
#include <sys/socket.h>
@@ -190,7 +192,7 @@ bool IPv6::matches_response(const uint8_t *ptr, uint32_t total_sz) const {
}
void IPv6::write_serialization(uint8_t *buffer, uint32_t total_sz, const PDU *parent) {
#ifdef DEBUG
#ifdef TINS_DEBUG
assert(total_sz >= header_size());
#endif
if(inner_pdu()) {

View File

@@ -29,7 +29,9 @@
#include <stdexcept>
#include <cstring>
#ifdef TINS_DEBUG
#include <cassert>
#endif
#include "llc.h"
#include "stp.h"
#include "rawpdu.h"
@@ -204,7 +206,9 @@ void LLC::clear_information_fields() {
}
void LLC::write_serialization(uint8_t *buffer, uint32_t total_sz, const Tins::PDU *parent) {
#ifdef TINS_DEBUG
assert(total_sz >= header_size());
#endif
if(inner_pdu() && inner_pdu()->pdu_type() == PDU::STP) {
dsap(0x42);
ssap(0x42);

View File

@@ -36,7 +36,9 @@
#endif
#endif
#include <stdexcept>
#ifdef TINS_DEBUG
#include <cassert>
#endif
#include <cstring>
#include "loopback.h"
#include "packet_sender.h"
@@ -97,7 +99,9 @@ uint32_t Loopback::header_size() const {
void Loopback::write_serialization(uint8_t *buffer, uint32_t total_sz, const PDU *)
{
#ifdef TINS_DEBUG
assert(total_sz >= sizeof(_family));
#endif
if(dynamic_cast<const Tins::IP*>(inner_pdu()))
_family = PF_INET;
else if(dynamic_cast<const Tins::LLC*>(inner_pdu()))

View File

@@ -53,7 +53,6 @@
#include <winsock2.h>
#include <ws2tcpip.h>
#endif
#include <cassert>
#include <cstring>
#include <ctime>
#include "pdu.h"

View File

@@ -26,8 +26,10 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifdef TINS_DEBUG
#include <cassert>
#endif
#include "pdu.h"
#include "rawpdu.h"
#include "packet_sender.h"

View File

@@ -28,7 +28,9 @@
*/
#include <cstring>
#ifdef TINS_DEBUG
#include <cassert>
#endif
#include <stdexcept>
#include "macros.h"
#ifndef WIN32
@@ -278,7 +280,9 @@ bool RadioTap::matches_response(const uint8_t *ptr, uint32_t total_sz) const {
void RadioTap::write_serialization(uint8_t *buffer, uint32_t total_sz, const PDU *parent) {
uint32_t sz = header_size();
uint8_t *buffer_start = buffer;
#ifdef TINS_DEBUG
assert(total_sz >= sz);
#endif
if(!_radio.it_len)
_radio.it_len = Endian::host_to_le<uint16_t>(sz);
memcpy(buffer, &_radio, sizeof(_radio));

View File

@@ -27,7 +27,9 @@
*
*/
#ifdef TINS_DEBUG
#include <cassert>
#endif
#include <algorithm>
#include "rawpdu.h"
@@ -49,7 +51,9 @@ uint32_t RawPDU::header_size() const {
}
void RawPDU::write_serialization(uint8_t *buffer, uint32_t total_sz, const PDU *) {
#ifdef TINS_DEBUG
assert(total_sz >= _payload.size());
#endif
std::copy(_payload.begin(), _payload.end(), buffer);
}

View File

@@ -28,7 +28,9 @@
*/
#include <cstring>
#ifdef TINS_DEBUG
#include <cassert>
#endif
#include <stdexcept>
#ifndef WIN32
#include <net/ethernet.h>
@@ -92,7 +94,9 @@ uint32_t Tins::SNAP::header_size() const {
}
void Tins::SNAP::write_serialization(uint8_t *buffer, uint32_t total_sz, const PDU *parent) {
#ifdef TINS_DEBUG
assert(total_sz >= sizeof(_snap));
#endif
if (!_snap.eth_type && inner_pdu()) {
uint16_t type = Tins::Constants::Ethernet::IP;
switch (inner_pdu()->pdu_type()) {

View File

@@ -28,7 +28,9 @@
*/
#include <cstring>
#ifdef TINS_DEBUG
#include <cassert>
#endif
#include <algorithm>
#include "stp.h"
#include "exceptions.h"
@@ -106,7 +108,7 @@ void STP::bridge_id(const bpdu_id_type &id) {
void STP::write_serialization(uint8_t *buffer, uint32_t total_sz, const PDU *) {
#ifdef TINS_DEBUG
assert(total_sz >= sizeof(_header));
assert(total_sz >= sizeof(_header));
#endif
std::memcpy(buffer, &_header, sizeof(_header));
}

View File

@@ -28,7 +28,9 @@
*/
#include <stdexcept>
#include <cassert>
#ifdef TINS_DEBUG
#include <cassert>
#endif
#include <cstring>
#include "udp.h"
#include "constants.h"