Skip to content

Commit a9bc1a2

Browse files
committed
do not use shell true instead
1 parent ca281bd commit a9bc1a2

File tree

1 file changed

+20
-17
lines changed

1 file changed

+20
-17
lines changed

koboldcpp.py

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3649,7 +3649,12 @@ def zenity_clean(txt: str):
36493649

36503650
def zenity_sanity_check(zenity_bin): #make sure zenity is sane
36513651
try: # Run `zenity --help` and pipe to grep
3652-
result = subprocess.run(f"{zenity_bin} --help", shell=True, capture_output=True, text=True, encoding='utf-8', timeout=10)
3652+
sc_clean_env = os.environ.copy()
3653+
sc_clean_env.pop("LD_LIBRARY_PATH", None)
3654+
sc_clean_env["PATH"] = "/usr/bin:/bin"
3655+
scargs = ['/usr/bin/env', zenity_bin, '--help']
3656+
result = subprocess.run(scargs, env=sc_clean_env, capture_output=True, text=True, encoding="utf-8", timeout=10)
3657+
36533658
if result.returncode == 0 and "Usage" in result.stdout:
36543659
return True
36553660
else:
@@ -5357,18 +5362,20 @@ def run_tunnel():
53575362
tunneloutput = ""
53585363
tunnelrawlog = ""
53595364
time.sleep(0.2)
5365+
tunnelbinary = ""
53605366
if os.name == 'nt':
53615367
print("Starting Cloudflare Tunnel for Windows, please wait...", flush=True)
5362-
tunnelproc = subprocess.Popen(f"cloudflared.exe tunnel --url {httpsaffix}://localhost:{args.port}{ssladd}", text=True, encoding='utf-8', shell=True, stdout=subprocess.DEVNULL, stderr=subprocess.PIPE)
5368+
tunnelbinary = "cloudflared.exe"
53635369
elif sys.platform=="darwin":
53645370
print("Starting Cloudflare Tunnel for MacOS, please wait...", flush=True)
5365-
tunnelproc = subprocess.Popen(f"./cloudflared tunnel --url {httpsaffix}://localhost:{args.port}{ssladd}", text=True, encoding='utf-8', shell=True, stdout=subprocess.DEVNULL, stderr=subprocess.PIPE)
5371+
tunnelbinary = "./cloudflared"
53665372
elif sys.platform == "linux" and platform.machine().lower() == "aarch64":
53675373
print("Starting Cloudflare Tunnel for ARM64 Linux, please wait...", flush=True)
5368-
tunnelproc = subprocess.Popen(f"./cloudflared-linux-arm64 tunnel --url {httpsaffix}://localhost:{args.port}{ssladd}", text=True, encoding='utf-8', shell=True, stdout=subprocess.DEVNULL, stderr=subprocess.PIPE)
5374+
tunnelbinary = "./cloudflared-linux-arm64"
53695375
else:
53705376
print("Starting Cloudflare Tunnel for Linux, please wait...", flush=True)
5371-
tunnelproc = subprocess.Popen(f"./cloudflared-linux-amd64 tunnel --url {httpsaffix}://localhost:{args.port}{ssladd}", text=True, encoding='utf-8', shell=True, stdout=subprocess.DEVNULL, stderr=subprocess.PIPE)
5377+
tunnelbinary = "./cloudflared-linux-amd64"
5378+
tunnelproc = subprocess.Popen(f"{tunnelbinary} tunnel --url {httpsaffix}://localhost:{args.port}{ssladd}", text=True, encoding='utf-8', shell=True, stdout=subprocess.DEVNULL, stderr=subprocess.PIPE)
53725379
time.sleep(10)
53735380
def tunnel_reader():
53745381
nonlocal tunnelproc,tunneloutput,tunnelrawlog
@@ -5608,30 +5615,26 @@ def downloader_internal(input_url, output_filename, capture_output, min_file_siz
56085615

56095616
try:
56105617
if shutil.which("aria2c") is not None:
5611-
rc = subprocess.run(
5612-
f"aria2c -x 16 -s 16 --summary-interval=30 --console-log-level=error --log-level=error --download-result=default --allow-overwrite=true --file-allocation=none -o {output_filename} {input_url}",
5613-
shell=True, capture_output=capture_output, text=True, check=True, encoding='utf-8'
5614-
)
5618+
rc = subprocess.run([
5619+
"aria2c", "-x", "16", "-s", "16", "--summary-interval=30", "--console-log-level=error", "--log-level=error",
5620+
"--download-result=default", "--allow-overwrite=true", "--file-allocation=none", "-o", output_filename, input_url
5621+
], capture_output=capture_output, text=True, check=True, encoding='utf-8')
56155622
dl_success = (rc.returncode == 0 and os.path.exists(output_filename) and os.path.getsize(output_filename) > min_file_size)
56165623
except subprocess.CalledProcessError as e:
56175624
print(f"aria2c failed: {e}")
56185625

56195626
try:
56205627
if not dl_success and shutil.which("curl") is not None:
5621-
rc = subprocess.run(
5622-
f"curl -fLo {output_filename} {input_url}",
5623-
shell=True, capture_output=capture_output, text=True, check=True, encoding='utf-8'
5624-
)
5628+
rc = subprocess.run(["curl", "-fLo", output_filename, input_url],
5629+
capture_output=capture_output, text=True, check=True, encoding="utf-8")
56255630
dl_success = (rc.returncode == 0 and os.path.exists(output_filename) and os.path.getsize(output_filename) > min_file_size)
56265631
except subprocess.CalledProcessError as e:
56275632
print(f"curl failed: {e}")
56285633

56295634
try:
56305635
if not dl_success and shutil.which("wget") is not None:
5631-
rc = subprocess.run(
5632-
f"wget -O {output_filename} {input_url}",
5633-
shell=True, capture_output=capture_output, text=True, check=True, encoding='utf-8'
5634-
)
5636+
rc = subprocess.run(["wget", "-O", output_filename, input_url],
5637+
capture_output=capture_output, text=True, check=True, encoding="utf-8")
56355638
dl_success = (rc.returncode == 0 and os.path.exists(output_filename) and os.path.getsize(output_filename) > min_file_size)
56365639
except subprocess.CalledProcessError as e:
56375640
print(f"wget failed: {e}")

0 commit comments

Comments
 (0)