shell: Fix tst_get_unused_port endianity
PATCH 1/1 shell: Fix tst_get_unused_port endianity
tst_get_unused_port is a shell helper, therefore it should use host byte order (we're not expecting this value would be added directly to sockaddr_in structure, which require network byte order). Wrap TST_GET_UNUSED_PORT() with ntohs() to achieve it.
---
Hi,
I guess we didn't noticed this in shell script as sendfile01 is the only
one not requiring root (dns-stress, tst_net_stress.sh, ssh-stress, ssh-stress03-rmt do require it).
I tested patch with little script (could be easily converted to proper test placed in lib/newlib_tests/)
export PATH="/opt/ltp/testcases/bin/:$PATH"
i=0
while [ $i -lt 2048 ]; do
for j in ipv4 ipv6; do
for k in stream dgram; do
p="$(tst_get_unused_port $j $k)"
printf "$i ($j $k): $p "
if [ $p -lt 1024 ]; then
echo "(bad)"
exit 1
else
echo "(ok)"
fi
done
done
i=$((i+1))done
echo "Test was ok"
testcases/lib/tst_get_unused_port.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
testcases/lib/tst_get_unused_port.c +1 -1
@@ -54,6 +54,6 @@ int main(int argc, char *argv[])return 1 ; } -printf ("%d" ,TST_GET_UNUSED_PORT (family, type)); +printf ("%d" ,ntohs (TST_GET_UNUSED_PORT (family, type)));return 0 ; }
Signature · 1 line
2.21.0
PATCH 1/1 shell: Fix tst_get_unused_port endianity
Quoted 56 lines · Petr Vorel
tst_get_unused_portis a shell helper, therefore it should use host byte order (we're not expecting this value would be added directly tosockaddr_instructure, which require network byte order). WrapTST_GET_UNUSED_PORT()withntohs()to achieve it.Reported-by Christian Amann <[email protected]>Suggested-by Cyril Hrubis <[email protected]>Signed-off-by Petr Vorel <[email protected]>---
Hi,I guess we didn't noticed this in shell script as sendfile01 is the only
one not requiring root (dns-stress,tst_net_stress.sh, ssh-stress, ssh-stress03-rmt do require it).I tested patch with little script (could be easily converted to proper test placed in
lib/newlib_tests/)export PATH="/opt/ltp/testcases/bin/:$PATH"
i=0
while [ $i -lt 2048 ]; do
for j in ipv4 ipv6; dofor k in stream dgram; do p="$(tst_get_unused_port $j $k)" printf "$i ($j $k): $p " if [ $p -lt 1024 ]; then echo "(bad)" exit 1 else echo "(ok)" fi donedone
i=$((i+1))
done
echo "Test was ok"
testcases/lib/tst_get_unused_port.c| 2 +-1 file changed, 1 insertion(+), 1 deletion(-)testcases/lib/tst_get_unused_port.c +1
-1@@ -54,6 +54,6 @@ int main(int argc, char *argv[])return 1 ; } -printf ("%d" ,TST_GET_UNUSED_PORT (family, type)); +printf ("%d" ,ntohs (TST_GET_UNUSED_PORT (family, type)));return 0 ; }Signature · 1 line
2.21.0
Thanks!
-Enji
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linux.it/pipermail/ltp/attachments/20190606/b78a0519/attachment.html>
PATCH 1/1 shell: Fix tst_get_unused_port endianity
Hi,
Quoted 1 line
Reviewed-by Enji Cooper <[email protected] <mailto:[email protected]>>
Thanks, merged.
Quoted 2 lines
Thanks!
-Enji
Kind regards,
Petr