test suite reviews and discussions
 help / color / mirror / Atom feed
From: LihongX Ma <lihongx.ma@intel.com>
To: dts@dpdk.org
Cc: LihongX Ma <lihongx.ma@intel.com>
Subject: [dts] [PATCH V1] framework/main: use safer methods instead of unsafe methods
Date: Fri, 11 Sep 2020 02:53:15 +0800	[thread overview]
Message-ID: <1599763995-937-1-git-send-email-lihongx.ma@intel.com> (raw)

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 <lihongx.ma@intel.com>
---
 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


             reply	other threads:[~2020-09-11  2:26 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-10 18:53 LihongX Ma [this message]
2020-09-15  8:36 ` Tu, Lijuan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1599763995-937-1-git-send-email-lihongx.ma@intel.com \
    --to=lihongx.ma@intel.com \
    --cc=dts@dpdk.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).