Subject: | m3UA padding not calculated correctly |
Date: | Fri, 9 Sep 2016 10:15:38 +0000 |
To: | <bug-Net-SIGTRAN [...] rt.cpan.org> |
From: | <john_cochrane [...] keysight.com> |
In SIGTRAN::M3UA sub encodepdu
The section of code to pad a message is:
my $mod4=length($message) % 4;
for (my $i=0;$i<$mod4;$i++) {
$message.=chr(0);
}
This is incorrect and result in the wrong amount of padding being added.
1) It assumes that the remainder is equal to the amount of padding required, rather than taking the modulus value into account.
2) It does not allow for the fact that adding a padding character/value to the $message, changes the length of $message.
A solution is:
while (length($message) % 4 != 0)
{
$message.=chr(0);
}