summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoraristocratos <gnmjpl@gmail.com>2020-07-06 13:44:15 +0200
committeraristocratos <gnmjpl@gmail.com>2020-07-06 13:44:15 +0200
commitd90c45623810979b75f506ab0e0db31b5c6a9f74 (patch)
treed6ade1aecc0e3c2cca1676f6aec6080347a06599
parentbb7643d43c1819021ab7a67b93d323a58ff94b4e (diff)
Fixed psutil script security issue
-rwxr-xr-xbashtop11
-rwxr-xr-xsrc/bashtop.psutil.py4
2 files changed, 8 insertions, 7 deletions
diff --git a/bashtop b/bashtop
index f3884c8..9f4b624 100755
--- a/bashtop
+++ b/bashtop
@@ -589,7 +589,7 @@ quit_() { #? Clean exit
if [[ $use_psutil == true && $2 != "psutil" ]]; then
py_command quit
sleep 0.1
- rm "${pywrapper}"
+ rm -rf "${pytmpdir}"
fi
echo -en "${clear_screen}${normal_screen}${show_cursor}"
${stty} "${saved_stty}"
@@ -877,7 +877,7 @@ get_cpu_info() {
if [[ $use_psutil == true ]]; then
if [[ -z ${cpu[threads]} || -z ${cpu[cores]} ]]; then
py_command -v pyin "get_cpu_cores()"
- read cpu[threads] cpu[cores] <<<"${pyin}"
+ read cpu[cores] cpu[threads] <<<"${pyin}"
fi
else
@@ -4816,7 +4816,8 @@ if [[ $use_psutil == true ]]; then
return 0
}
- pywrapper=$(mktemp "${TMPDIR:-/tmp}"/bashtop.psutil.XXXX)
+ pytmpdir=$(mktemp -d "${TMPDIR:-/tmp}"/XXXXXXXXXXXX)
+ pywrapper=$(mktemp "${pytmpdir}"/bashtop.psutil.XXXX)
cat << 'EOF' > "${pywrapper}"
import os, sys, subprocess, re, time, psutil
@@ -4938,8 +4939,8 @@ def get_cpu_name():
def get_cpu_cores():
'''Get number of CPU cores and threads'''
- cores: int = psutil.cpu_count(logical=True)
- threads: int = psutil.cpu_count(logical=False)
+ cores: int = psutil.cpu_count(logical=False)
+ threads: int = psutil.cpu_count(logical=True)
print(f'{cores} {threads if threads else cores}')
def get_cpu_usage():
diff --git a/src/bashtop.psutil.py b/src/bashtop.psutil.py
index 9c56498..9d394d3 100755
--- a/src/bashtop.psutil.py
+++ b/src/bashtop.psutil.py
@@ -121,8 +121,8 @@ def get_cpu_name():
def get_cpu_cores():
'''Get number of CPU cores and threads'''
- cores: int = psutil.cpu_count(logical=True)
- threads: int = psutil.cpu_count(logical=False)
+ cores: int = psutil.cpu_count(logical=False)
+ threads: int = psutil.cpu_count(logical=True)
print(f'{cores} {threads if threads else cores}')
def get_cpu_usage():