Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unintended behaviour in absltest.py #248

Open
adric-work opened this issue Aug 24, 2023 · 0 comments
Open

Unintended behaviour in absltest.py #248

adric-work opened this issue Aug 24, 2023 · 0 comments

Comments

@adric-work
Copy link

It seems like this section of code allows someone to pass in an arbitrary path name in tempfile, which then causes the code to zero out the provided path (rather than a temporary file) if the person running the test also happens to own the file:

path = os.path.join(base_path, file_path)
os.makedirs(os.path.dirname(path), exist_ok=True)
# The file may already exist, in which case, ensure it's writable so that
# it can be truncated.
if os.path.exists(path) and not os.access(path, os.W_OK):
stat_info = os.stat(path)
os.chmod(path, stat_info.st_mode | stat.S_IWUSR)

Example:

import pathlib

from adric-work.testing.pybase import test

class BugTest(test.TestCase):

def testBug(self):
    # bad_path = pathlib.Path.home() / 'hello_bug' / 'a_file.txt'
    # my_file = self.create_tempfile(bad_path.as_posix())
    bad_path = '/usr/local/work/home/adric-work/hello_bug/a_file.txt'
    my_file = self.create_tempfile(bad_path)


if __name__ == '__main__':
  test.main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant