Harden against large inline scripts

Can produce OSError 63 filename too long
This commit is contained in:
Reid 'arrdem' McKenzie 2022-11-28 20:12:43 -07:00
parent 5da29e1d9d
commit f4308ac0c7

View file

@ -75,17 +75,25 @@ class PackageV1(Package):
sum = sum.hexdigest() sum = sum.hexdigest()
installf = self.root / content installf = self.root / content
if installf.exists():
with open(installf, "r") as fp:
self.do_sh_or_script(fp.read(), fs, dest)
elif content: def _installf_exists():
try:
return installf.exists()
except OSError as e:
return False
if content.startswith("#!") or "\n" in content or not _installf_exists():
f = tempf(self.global_config, f"{sum}.sh") f = tempf(self.global_config, f"{sum}.sh")
f.parent.mkdir(exist_ok=True, parents=True) f.parent.mkdir(exist_ok=True, parents=True)
with open(f, "w") as fp: with open(f, "w") as fp:
fp.write(content) fp.write(content)
fs.exec(cwd, sh(self.global_config, [str(f)])) fs.exec(cwd, sh(self.global_config, [str(f)]))
else:
with open(installf, "r") as fp:
self.do_sh_or_script(fp.read(), fs, dest)
def do_build(self, fs: Vfs, dest: Path): def do_build(self, fs: Vfs, dest: Path):
self.do_sh_or_script(self.config().get("package", {}).get("build"), fs, dest) self.do_sh_or_script(self.config().get("package", {}).get("build"), fs, dest)