upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/tools/rtti_scan.py
diff options
context:
space:
mode:
authorkotorvr <332716892+kotorvr@users.noreply.github.com>2026-11-22 02:54:59 +0000
committerkotorvr <332716892+kotorvr@users.noreply.github.com>2026-11-22 02:54:59 +0000
commitd0ca262e7cc6d2ad86905e429ae84574d20b34ff (patch)
tree846e9c373c9694983d7421571e27471653a096ca /tools/rtti_scan.py
parentd0f0a510f3523ada86905fb5a2d922ae5ef2b8c5 (diff)
rtti_scan: the swapped-in report keeps the old report's permission bits
NamedTemporaryFile creates its file 0600, so a new report lost the umask default (0644 under umask 022) and a replaced 0640 report lost group read (found by @VictorJulianiR on Ubuntu). The temp file now gets the old report's mode, or 0666 minus the umask for a new report, before os.replace. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'tools/rtti_scan.py')
-rw-r--r--tools/rtti_scan.py16
1 files changed, 15 insertions, 1 deletions
diff --git a/tools/rtti_scan.py b/tools/rtti_scan.py
index 92e26bd14..654742ed6 100644
--- a/tools/rtti_scan.py
+++ b/tools/rtti_scan.py
@@ -18,6 +18,7 @@ import argparse
18import json 18import json
19import os 19import os
20import re 20import re
21import stat
21import struct 22import struct
22import sys 23import sys
23import tempfile 24import tempfile
@@ -189,9 +190,21 @@ def scan_pe64_rtti(data: bytes) -> dict:
189 } 190 }
190 191
191 192
193def _report_mode(path):
194 """The permission bits the report should end up with: those of the report it replaces, or what open() would
195 give a new file (0666 minus the umask). NamedTemporaryFile creates its file 0600."""
196 try:
197 return stat.S_IMODE(os.stat(path).st_mode)
198 except FileNotFoundError:
199 mask = os.umask(0)
200 os.umask(mask)
201 return 0o666 & ~mask
202
203
192def write_report(path, text): 204def write_report(path, text):
193 """Write the report next to its destination and swap it in, so a write that fails part-way (a full disk, a 205 """Write the report next to its destination and swap it in, so a write that fails part-way (a full disk, a
194 locked range) leaves the previous report as it was instead of an empty or truncated file.""" 206 locked range) leaves the previous report as it was instead of an empty or truncated file. The result keeps
207 the previous report's permission bits, or gets the usual ones for a new file."""
195 parent = os.path.dirname(os.path.abspath(path)) 208 parent = os.path.dirname(os.path.abspath(path))
196 tmp = None 209 tmp = None
197 try: 210 try:
@@ -199,6 +212,7 @@ def write_report(path, text):
199 delete=False) as f: 212 delete=False) as f:
200 tmp = f.name 213 tmp = f.name
201 f.write(text) 214 f.write(text)
215 os.chmod(tmp, _report_mode(path))
202 os.replace(tmp, path) 216 os.replace(tmp, path)
203 except BaseException: 217 except BaseException:
204 if tmp is not None: 218 if tmp is not None: