Ticket #13579: 13579_scripts.patch

File 13579_scripts.patch, 2.2 KB (added by jdemeyer, 9 years ago)
  • sage-ptest

    # HG changeset patch
    # User Jeroen Demeyer <jdemeyer@cage.ugent.be>
    # Date 1350402175 -7200
    # Node ID 674909732ddff09890eaeb91e708de59d86766da
    # Parent  061ee93f75f7736e214dacd4e32a9c5b9d4a5cbf
    Only run doctests from safe directories (not writable by untrusted users)
    
    diff --git a/sage-ptest b/sage-ptest
    a b  
    6666# Exit status for the whole run.
    6767err = 0
    6868
     69# Check that the current directory is sufficiently safe to run Python
     70# code from.  We use the check added to Python for this, which gives a
     71# warning when the current directory is considered unsafe.  We promote
     72# this warning to an error with -Werror.  See sage/tests/cmdline.py
     73# for a doctest that this works, see also Sage Trac #13579.
     74import subprocess
     75with open(os.devnull, 'w') as dev_null:
     76    if subprocess.call(['python', '-Werror', '-c', ''], stdout=dev_null, stderr=dev_null) != 0:
     77        raise RuntimeError("refusing to run doctests from the current "\
     78            "directory '{}' since untrusted users could put files in "\
     79            "this directory, making it unsafe to run Sage code from"\
     80            .format(os.getcwd()))
     81
    6982def strip_automount_prefix(filename):
    7083    """
    7184    Strip prefixes added on automounted filesystems in some cases,
  • sage-test

    diff --git a/sage-test b/sage-test
    a b  
    3939    if not os.path.isdir(SAGE_TESTDIR):
    4040        raise
    4141
     42# Check that the current directory is sufficiently safe to run Python
     43# code from.  We use the check added to Python for this, which gives a
     44# warning when the current directory is considered unsafe.  We promote
     45# this warning to an error with -Werror.  See sage/tests/cmdline.py
     46# for a doctest that this works, see also Sage Trac #13579.
     47import subprocess
     48with open(os.devnull, 'w') as dev_null:
     49    if subprocess.call(['python', '-Werror', '-c', ''], stdout=dev_null, stderr=dev_null) != 0:
     50        raise RuntimeError("refusing to run doctests from the current "\
     51            "directory '{}' since untrusted users could put files in "\
     52            "this directory, making it unsafe to run Sage code from"\
     53            .format(os.getcwd()))
     54
    4255def sage_test_command(f):
    4356    g = abspath(f)
    4457    if SAGE_ROOT in g: