Merge remote-tracking branch 'origin/topic/christian/1074-avoid-packed-member-warning'

* origin/topic/christian/1074-avoid-packed-member-warning:
  Avoid passing address of member in packed struct #1074
This commit is contained in:
Tim Wojtulewicz 2020-09-17 11:24:42 -07:00
commit 0cb39a5c31
3 changed files with 19 additions and 5 deletions

View file

@ -1,3 +1,9 @@
3.3.0-dev.265 | 2020-09-17 11:24:42 -0700
* Avoid passing address of member in packed struct #1074
This appeases -Waddress-of-packed-member warnings in some
compiler/platform combinations via use of local variables. (Christian Kreibich, Corelight)
3.3.0-dev.262 | 2020-09-14 12:27:52 -0700

View file

@ -1 +1 @@
3.3.0-dev.262
3.3.0-dev.265

View file

@ -230,21 +230,29 @@ void PIA_TCP::FirstPacket(bool is_orig, const IP_Hdr* ip)
ip4_hdr = new IP_Hdr(ip4, false);
}
// Locals used to avoid potentil alignment problems
// with some archs/compilers when grabbing the address
// of the struct member directly in the following.
in_addr tmp_src;
in_addr tmp_dst;
if ( is_orig )
{
Conn()->OrigAddr().CopyIPv4(&ip4->ip_src);
Conn()->RespAddr().CopyIPv4(&ip4->ip_dst);
Conn()->OrigAddr().CopyIPv4(&tmp_src);
Conn()->RespAddr().CopyIPv4(&tmp_dst);
tcp4->th_sport = htons(Conn()->OrigPort());
tcp4->th_dport = htons(Conn()->RespPort());
}
else
{
Conn()->RespAddr().CopyIPv4(&ip4->ip_src);
Conn()->OrigAddr().CopyIPv4(&ip4->ip_dst);
Conn()->RespAddr().CopyIPv4(&tmp_src);
Conn()->OrigAddr().CopyIPv4(&tmp_dst);
tcp4->th_sport = htons(Conn()->RespPort());
tcp4->th_dport = htons(Conn()->OrigPort());
}
ip4->ip_src = tmp_src;
ip4->ip_dst = tmp_dst;
ip = ip4_hdr;
}