From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 05B59A04B5; Fri, 11 Sep 2020 04:26:43 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id D46EF1B75C; Fri, 11 Sep 2020 04:26:43 +0200 (CEST) Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) by dpdk.org (Postfix) with ESMTP id 4A1A7DE0 for ; Fri, 11 Sep 2020 04:26:41 +0200 (CEST) IronPort-SDR: q+tjMjwAzlXOUl402IUapkkdKxcypwg4B6Ud7EGUD9bhVmjs8QL8G0toK2ba/L2YBwJN6OXYyc SAAUSTuRX91A== X-IronPort-AV: E=McAfee;i="6000,8403,9740"; a="220231477" X-IronPort-AV: E=Sophos;i="5.76,413,1592895600"; d="scan'208";a="220231477" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Sep 2020 19:26:40 -0700 IronPort-SDR: dSC6TKojFL4Xe2ARftQ2lDZBA4X1hODiHXDlsM8gACM1/C1ZpwncETLS0e7gVzCMVZZOzwmSEj 9qquhYrEdNtA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.76,413,1592895600"; d="scan'208";a="337355041" Received: from dpdk-lihong-ub1604.sh.intel.com ([10.67.118.174]) by fmsmga002.fm.intel.com with ESMTP; 10 Sep 2020 19:26:39 -0700 From: LihongX Ma To: dts@dpdk.org Cc: LihongX Ma Date: Fri, 11 Sep 2020 02:53:15 +0800 Message-Id: <1599763995-937-1-git-send-email-lihongx.ma@intel.com> X-Mailer: git-send-email 2.7.4 Subject: [dts] [PATCH V1] framework/main: use safer methods instead of unsafe methods X-BeenThere: dts@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: test suite reviews and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dts-bounces@dpdk.org Sender: "dts" it is unsafe to call a system command or execute an external program with user input, so use the safer method instead of it. Signed-off-by: LihongX Ma --- framework/main.py | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/framework/main.py b/framework/main.py index f6e3ae9..a081b85 100755 --- a/framework/main.py +++ b/framework/main.py @@ -37,6 +37,7 @@ A test framework for testing DPDK. import os import sys import argparse +import subprocess # change operation directory os.chdir("../") @@ -48,14 +49,17 @@ sys.path.append(cwd + '/dep') import dts -def git_build_package(gitLabel, pkgName, depot="dep"): +def git_build_package(gitLabel, pkgName): """ generate package from git, if dpdk existed will pull latest code """ gitURL = r"http://dpdk.org/git/dpdk" gitPrefix = r"dpdk/" + depot = r"dep" if os.path.exists("%s/%s" % (depot, gitPrefix)) is True: - ret = os.system("cd %s/%s && git pull --force" % (depot, gitPrefix)) + os.chdir("%s/%s" % (depot, gitPrefix)) + ret = os.system("git pull --force") + os.chdir(cwd) else: print("git clone %s %s/%s" % (gitURL, depot, gitPrefix)) ret = os.system("git clone %s %s/%s" % (gitURL, depot, gitPrefix)) @@ -63,9 +67,17 @@ def git_build_package(gitLabel, pkgName, depot="dep"): raise EnvironmentError print("git archive --format=tar.gz --prefix=%s %s -o %s" % (gitPrefix, gitLabel, pkgName)) - ret = os.system("cd %s/%s && git archive --format=tar.gz --prefix=%s/ %s -o ../%s" - % (depot, gitPrefix, gitPrefix, gitLabel, pkgName)) - if ret != 0: + os.chdir("%s/%s/%s" % (cwd, depot, gitPrefix)) + try: + ret = subprocess.run(["git", "archive", "--format=tar.gz", "--prefix=%s/" % gitPrefix, + "%s" % gitLabel, "-o", "../%s" % pkgName], shell=False) + except Exception as e: + print("git archive failed of : %s" % str(e)) + sys.exit() + + os.chdir(cwd) + if ret.returncode != 0: + print(ret) raise EnvironmentError -- 2.7.4