From patchwork Thu Jun 6 14:30:17 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Vorel X-Patchwork-Id: 1111167 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=lists.linux.it (client-ip=213.254.12.146; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=suse.cz Received: from picard.linux.it (picard.linux.it [213.254.12.146]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 45KSkt4Czqz9sND for ; Fri, 7 Jun 2019 00:31:01 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 3189C390322 for ; Thu, 6 Jun 2019 16:30:58 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-6.smtp.seeweb.it (in-6.smtp.seeweb.it [217.194.8.6]) by picard.linux.it (Postfix) with ESMTP id DCA923EA9CC for ; Thu, 6 Jun 2019 16:30:55 +0200 (CEST) Received: from mx1.suse.de (mx2.suse.de [195.135.220.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by in-6.smtp.seeweb.it (Postfix) with ESMTPS id 107271401AED for ; Thu, 6 Jun 2019 16:30:22 +0200 (CEST) Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 153EBAFE3; Thu, 6 Jun 2019 14:30:22 +0000 (UTC) From: Petr Vorel To: ltp@lists.linux.it Date: Thu, 6 Jun 2019 16:30:17 +0200 Message-Id: <20190606143017.2233-1-pvorel@suse.cz> X-Mailer: git-send-email 2.21.0 MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.99.2 at in-6.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=0.0 required=7.0 tests=SPF_HELO_NONE,SPF_PASS autolearn=disabled version=3.4.0 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on in-6.smtp.seeweb.it Subject: [LTP] [PATCH] shell: Fix tst_get_unused_port endianity X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.18 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" 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. Reported-by: Christian Amann Suggested-by: Cyril Hrubis Signed-off-by: Petr Vorel Reviewed-by: Enji Cooper > --- 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(-) diff --git a/testcases/lib/tst_get_unused_port.c b/testcases/lib/tst_get_unused_port.c index 0173f1634..a843cc6e3 100644 --- a/testcases/lib/tst_get_unused_port.c +++ b/testcases/lib/tst_get_unused_port.c @@ -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; }