From a4e394925c249b7afd150fe2a6c7c77a3702f1b7 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Nov 19 2018 09:30:19 +0000 Subject: Verify the value of '-s' when execute the CLI of cProfile Resolves: rhbz#1160640 --- diff --git a/00313-cprofile-sort-option.patch b/00313-cprofile-sort-option.patch new file mode 100644 index 0000000..fe427e5 --- /dev/null +++ b/00313-cprofile-sort-option.patch @@ -0,0 +1,61 @@ +commit c36e8721f276e7cc09cecdb9c04783630f0ba82a +Author: Victor Stinner +Date: Wed Nov 7 00:34:22 2018 +0100 + + bpo-23420: Verify the value of '-s' when execute the CLI of cProfile + + Verify the value for the parameter '-s' of the cProfile CLI. Patch by Robert + Kuska. + + Resolves: rhbz#1160640 + +diff --git a/Lib/cProfile.py b/Lib/cProfile.py +index c044be8..f6e423b 100755 +--- a/Lib/cProfile.py ++++ b/Lib/cProfile.py +@@ -124,6 +124,7 @@ def main(): + import os + import sys + import runpy ++ import pstats + from optparse import OptionParser + usage = "cProfile.py [-o output_file_path] [-s sort] [-m module | scriptfile] [arg] ..." + parser = OptionParser(usage=usage) +@@ -132,7 +133,8 @@ def main(): + help="Save stats to ", default=None) + parser.add_option('-s', '--sort', dest="sort", + help="Sort order when printing to stdout, based on pstats.Stats class", +- default=-1) ++ default=-1, ++ choices=sorted(pstats.Stats.sort_arg_dict_default)) + parser.add_option('-m', dest="module", action="store_true", + help="Profile a library module", default=False) + +diff --git a/Lib/test/test_cprofile.py b/Lib/test/test_cprofile.py +index 1430d22..5c4ec5b 100644 +--- a/Lib/test/test_cprofile.py ++++ b/Lib/test/test_cprofile.py +@@ -2,6 +2,7 @@ + + import sys + from test.support import run_unittest, TESTFN, unlink ++import unittest + + # rip off all interesting stuff from test_profile + import cProfile +@@ -50,8 +51,14 @@ class CProfileTest(ProfileTest): + assert_python_ok('-m', 'cProfile', '-m', 'timeit', '-n', '1') + + ++class TestCommandLine(unittest.TestCase): ++ def test_sort(self): ++ rc, out, err = assert_python_failure('-m', 'cProfile', '-s', 'demo') ++ self.assertGreater(rc, 0) ++ self.assertIn(b"option -s: invalid choice: 'demo'", err) ++ + def test_main(): +- run_unittest(CProfileTest) ++ run_unittest(CProfileTest, TestCommandLine) + + def main(): + if '-r' not in sys.argv: diff --git a/python3.spec b/python3.spec index dffcbdc..2cbf972 100644 --- a/python3.spec +++ b/python3.spec @@ -14,7 +14,7 @@ URL: https://www.python.org/ # WARNING When rebasing to a new Python version, # remember to update the python3-docs package as well Version: %{pybasever}.1 -Release: 2%{?dist} +Release: 3%{?dist} License: Python @@ -312,6 +312,12 @@ Patch291: 00291-setup-Link-ctypes-against-dl-explicitly.patch # See: https://bugzilla.redhat.com/show_bug.cgi?id=1644936 Patch312: 00312-revert-bpo-6721.patch +# 00313 # +# Verify the value of '-s' when execute the CLI of cProfile +# http://bugs.python.org/issue23420 +# https://bugzilla.redhat.com/show_bug.cgi?id=1160640 +Patch313: 00313-cprofile-sort-option.patch + # (New patches go here ^^^) # # When adding new patches to "python" and "python3" in Fedora, EL, etc., @@ -643,6 +649,7 @@ rm Lib/ensurepip/_bundled/*.whl %patch274 -p1 %patch291 -p1 %patch312 -p1 +%patch313 -p1 # Remove files that should be generated by the build @@ -1542,6 +1549,9 @@ CheckPython optimized # ====================================================== %changelog +* Tue Nov 06 2018 Victor Stinner - 3.7.1-3 +- Verify the value of '-s' when execute the CLI of cProfile (rhbz#1160640) + * Sun Nov 04 2018 Miro HronĨok - 3.7.1-2 - Temporarily revert upstream commit 3b699932e5ac3e7 - This is dirty workaround for (#1644936)