diff options
-rwxr-xr-x | clip | 10 |
1 files changed, 2 insertions, 8 deletions
@@ -37,18 +37,12 @@ def fileno(filelike): @contextlib.contextmanager -def secure_open(path, mode='r', *l, **kw): +def secure_open(path, *l, **kw): if os.path.islink(path): raise SecurityError("The clipboard file can not be a symlink") - real_mode = mode - if 'w' in real_mode: - real_mode = real_mode.replace('w', 'a') - with open(path, real_mode, *l, **kw) as fo: + with open(path, *l, **kw) as fo: if os.fstat(fileno(fo)) != os.stat(path): raise SecurityError("Intrusion might have been done on %s" % path) - if 'w' in mode: - os.lseek(fileno(fo), 0, os.SEEK_SET) - os.ftruncate(fileno(fo), 0) os.fchmod(fileno(fo), 0o600) yield fo |