]> Kevux Git Server - tkis/commitdiff
Security: Add IFS protection to all functions. development
authorKevin Day <Kevin@kevux.org>
Thu, 14 May 2026 02:42:04 +0000 (21:42 -0500)
committerKevin Day <Kevin@kevux.org>
Thu, 14 May 2026 02:42:04 +0000 (21:42 -0500)
This prevents abusive behavior if the `IFS` is changed.

The individual functions might be called in an environment that changes.
Therefore, each function must set the `IFS`.

12 files changed:
scripts/install
scripts/programs/distribution
scripts/programs/documentation
scripts/programs/execute
scripts/programs/obtain
scripts/programs/output
scripts/programs/package
scripts/programs/security
scripts/programs/single_execution
scripts/programs/system
scripts/programs/tkis_local_environment
scripts/programs/upgrade

index de32e39f25779e450aa7b89be9532de0d0b785cc..51f38f485d8747098319469e4b2ca4e4b7a7338a 100755 (executable)
@@ -17,6 +17,8 @@ color_important="\\033[0;32m"
 
 # a function to simplify load management
 tkis_source_file(){
+  local IFS=$' \t\n' # Prevent IFS exploits by overriding with a local scope.
+
   if [ ! -f $1 ] ; then
    echo -e "${color_error}ERROR: Missing or Cannot Access $1$color_reset" 1>&2
    exit 1
@@ -26,6 +28,8 @@ tkis_source_file(){
 }
 
 tkis_command_line(){
+  local IFS=$' \t\n' # Prevent IFS exploits by overriding with a local scope.
+
   # first look for only -l, to see if the color needs to be light
   for i in $2 ; do
     if [[ $i == "-l" || $i == "--light" ]] ; then
@@ -229,6 +233,8 @@ tkis_command_line(){
 }
 
 tkis_main(){
+  local IFS=$' \t\n' # Prevent IFS exploits by overriding with a local scope.
+
   local tkis_version="1.2.0"
   local tkis_install_program=$(basename $0)
   local tkis_path=$(echo $0 | sed -e "s|scripts/$tkis_install_program$||")
@@ -346,6 +352,8 @@ tkis_main(){
 }
 
 bootstrap_check() {
+  local IFS=$' \t\n' # Prevent IFS exploits by overriding with a local scope.
+
   local bootstrap_needed=
 
   if [[ $(type -p fss_basic_read) == "" || $(type -p fss_basic_list_read) == "" ]] ; then
index d0fa4ff3ea36c3379321e9a35e5f8f30de2c2be6..62d928ffb8f95ba81813b7918e21856e1c7d53d9 100755 (executable)
@@ -2,6 +2,8 @@
 
 # distributions are specific to their file and can be directly called without searching
 tkis_load_distribution_list(){
+  local IFS=$' \t\n' # Prevent IFS exploits by overriding with a local scope.
+
   debug "Searching For List: $1 inside of ${DI}$tkis_distribution"
   local found_list=$(grep -s "^[[:space:]]*$1:[[:space:]]*$" ${DI}$tkis_distribution)
 
@@ -22,6 +24,8 @@ tkis_load_distribution_list(){
 }
 
 tkis_install_distribution(){
+  local IFS=$' \t\n' # Prevent IFS exploits by overriding with a local scope.
+
   echo
   echo -e "${color_title}Turtle Kevux Installation Scripts${color_reset}"
   echo -e "  ${color_notice}Installing Distribution:${color_reset} ${color_notice}$tkis_distribution${color_reset}"
@@ -106,7 +110,7 @@ tkis_install_distribution(){
     fi
 
     let dist_current=$dist_current+1
+
     if [[ $dist_current -lt $list_size ]] ; then
       # save the next spot so resume can work properly
       echo $dist_current > $tkis_resume_distribution
index 560c5e519f7e3ebc4e7ffa3b81e7c2d4e4254d83..28561824ff6befa62ac66656dfd8aeb29cb967a7 100755 (executable)
@@ -1,6 +1,8 @@
 #!/bin/bash
 
 tkis_handle_documentation(){
+  local IFS=$' \t\n' # Prevent IFS exploits by overriding with a local scope.
+
   local doc_type=${1}
   local classification=${2}
   local documentation=$(echo ${*} | sed -e "s|^${doc_type}[[:space:]]*${classification}[[:space:]]*||")
index e1a000f707ae3281dfe7a94cda6938997c1efc88..bf46d40b02cb8aed03fee1af9c862e1ce96c1704 100755 (executable)
@@ -3,6 +3,8 @@
 # directly process all given information as a single command
 # 1 = command to execute
 tkis_execute(){
+  local IFS=$' \t\n' # Prevent IFS exploits by overriding with a local scope.
+
   if [[ $1 == "" ]] ; then
     error "tkis_execute(): command name not supplied while trying to process $color_reset$color_notice$rule_name$color_reset$color_error on line #$color_reset$color_notice$current$color_reset$color_error with $color_reset$color_notice$tkis_process$color_reset$color_error for $color_reset$color_notice$program_name"
   fi
@@ -53,7 +55,7 @@ tkis_handle_patches(){
 
   debug "executing: tkis_get_patches $1 $2 $3"
   tkis_get_patches $1 $2 $3
+
   mkdir -p $tkis_data
 
   debug "found the following patches: $PATCHES"
@@ -137,7 +139,7 @@ tkis_handle_cleanup(){
   else
     debug "$WO$1-$2 does not exist and therefore the cleanup of that directory is being skipped"
   fi
-  
+
   if [ -f ${tkis_data}patched.$tkis_process.$1 ] ; then
     debug "executing: rm -Rf ${tkis_data}patched.$tkis_process.$1"
     rm -Rf ${tkis_data}patched.$tkis_process.$1
index fb5fb7e0459a2e3c1963cf51a4d8c0eded27352c..176fa5d0aa0410e83eade695c7a31148c7291a51 100755 (executable)
@@ -2,6 +2,8 @@
 
 # 1 = program name, 2 = version number, 3 (optional) = extraction point
 tkis_extract(){
+  local IFS=$' \t\n' # Prevent IFS exploits by overriding with a local scope.
+
   if [[ $1 == "" ]] ; then
     error "tkis_extract(): program name not supplied"
   fi
@@ -45,7 +47,7 @@ tkis_extract(){
       if [[ $(echo $archive | grep -s " ") != "" ]] ; then
         warning "You see to have multiple copies, remove the additional one to continue: $color_reset$color_notice$archive$color_reset${color_warning}, using the first occurance"
         archive=$(echo $archive | awk '{ print $1 }')
-      fi 
+      fi
 
       tar --no-same-permissions --no-same-owner -xf $archive -C $dest
 
@@ -89,6 +91,8 @@ tkis_extract(){
 # will store the version number inside of VERSION if one is found
 # 1 = program name
 tkis_get_version(){
+  local IFS=$' \t\n' # Prevent IFS exploits by overriding with a local scope.
+
   if [[ $1 == "" ]] ; then
     error "tkis_get_version(): program name not supplied"
   fi
@@ -124,6 +128,8 @@ tkis_get_version(){
 }
 
 tkis_process_version(){
+  local IFS=$' \t\n' # Prevent IFS exploits by overriding with a local scope.
+
   VERSION=$version
   SUBVERSION=$(echo $version | grep -o "^[[:alnum:]_-]*\.[[:alnum:]_-]*\.[[:alnum:]_-]*")
   MICVERSION=$(echo $version | grep -o "^[[:alnum:]_-]*\.[[:alnum:]_-]*")
@@ -158,6 +164,8 @@ tkis_process_version(){
 # will store the version number inside of PATCHES for all patches found
 # 1 = program name, 2 = version number 3 = subversion number
 tkis_get_patches(){
+  local IFS=$' \t\n' # Prevent IFS exploits by overriding with a local scope.
+
   if [[ $1 == "" ]] ; then
     error "tkis_get_patches(): program name not supplied"
   fi
@@ -260,6 +268,8 @@ tkis_get_patches(){
 
 # this is a get_version that rules are allowed to directly call
 tkis_local_get_version(){
+  local IFS=$' \t\n' # Prevent IFS exploits by overriding with a local scope.
+
   local old_version=$VERSION
   local old_subversion=$SUBVERSION
   LOCAL_VERSION=
@@ -276,6 +286,8 @@ tkis_local_get_version(){
 
 # If a script requires the use of certain non-standard parameters that may or may not be defined, make sure they get defined
 tkis_local_require(){
+  local IFS=$' \t\n' # Prevent IFS exploits by overriding with a local scope.
+
   for i in $* ; do
     if [[ $(eval "echo \$$i") == "" ]] ; then
       echo -e "${color_warning}The variable $color_reset$color_notice$i$color_reset$color_warning is not defined, define it now:$color_reset"
index 986dbca0928c1c3921e00c87d1f2043234dafda5..787cad8fa9c8c8c51c1dbc5cc4f7023d5cf01955 100755 (executable)
@@ -2,8 +2,10 @@
 
 # 1 = message
 error(){
+  local IFS=$' \t\n' # Prevent IFS exploits by overriding with a local scope.
+
   echo -e "${color_error}ERROR: $1${color_reset}" 1>&2
-  mkdir -p $tkis_output 
+  mkdir -p $tkis_output
 
   if [ -d $WO ] ; then
     if [[ $tkis_process == "" ]] ; then
@@ -21,8 +23,10 @@ error(){
 
 # 1 = message
 warning(){
+  local IFS=$' \t\n' # Prevent IFS exploits by overriding with a local scope.
+
   echo -e "${color_warning}WARNING: $1${color_reset}"
-  mkdir -p $tkis_output 
+  mkdir -p $tkis_output
 
   if [ -d $WO ] ; then
     if [[ $tkis_process == "" ]] ; then
@@ -38,10 +42,11 @@ warning(){
 
 # 1 = message
 debug(){
+  local IFS=$' \t\n' # Prevent IFS exploits by overriding with a local scope.
 
   if [[ $tkis_print_debug == "yes" ]] ; then
     echo -e "${color_notice}DEBUG:$color_reset $1"
-    mkdir -p $tkis_output 
+    mkdir -p $tkis_output
 
     if [ -d $WO ] ; then
       if [[ $tkis_process == "" ]] ; then
@@ -57,12 +62,16 @@ debug(){
 }
 
 echoit(){
+  local IFS=$' \t\n' # Prevent IFS exploits by overriding with a local scope.
+
   if [[ $tkis_silent != "true" ]] ; then
     echo -e "$color_important$*$color_reset"
   fi
 }
 
 notice(){
+  local IFS=$' \t\n' # Prevent IFS exploits by overriding with a local scope.
+
   if [[ $tkis_silent != "true" ]] ; then
     echo -e "$color_highlight$*$color_reset"
   fi
@@ -70,6 +79,8 @@ notice(){
 
 # this is a quick and dirty implementation, nothing fancy, and nowhere near as good as it could be
 tkis_print_environment(){
+  local IFS=$' \t\n' # Prevent IFS exploits by overriding with a local scope.
+
   local environment_file=${tkis_data}environment
 
   if [[ $tkis_process != "" ]] ; then
@@ -136,6 +147,8 @@ tkis_print_environment(){
 
 # a quick and simple implementation, nothing fancy so clock skews will mess this up
 tkis_calculate_time(){
+  local IFS=$' \t\n' # Prevent IFS exploits by overriding with a local scope.
+
   if [[ $tkis_output != "" ]] ; then mkdir -p $tkis_output ; fi
 
   local stop_time_second=
index 37a960970af1cd825c39bf7444effb516832a672..babb2279ac8385985cb271d602490e0ec0c1af3a 100755 (executable)
@@ -1,6 +1,8 @@
 #!/bin/bash
 
 tkis_package(){
+  local IFS=$' \t\n' # Prevent IFS exploits by overriding with a local scope.
+
   local version_override=$1
   local program_name=$2
   local rule_name=$3
index c016b115e86a4273db052093dcd29ed382735ada..8cb1a24537d8a4634db294d25606f78b9deabcb8 100755 (executable)
@@ -5,6 +5,8 @@
 # do not allow rules to directly call most/all internal tkis functions
 # do not allow rules to redefine local variables used by tkis
 tkis_security_check(){
+  local IFS=$' \t\n' # Prevent IFS exploits by overriding with a local scope.
+
   local insecure_call=
 
   if [[ $(echo $1 | grep -s "^[[:space:]]*tkis_source_file\>") != "" ]] ; then
@@ -76,6 +78,8 @@ tkis_security_check(){
 
 # do not allow rules to directly define their own variables so that they cannot work around the rule checks
 tkis_deny_private_variables(){
+  local IFS=$' \t\n' # Prevent IFS exploits by overriding with a local scope.
+
   local insecure_action=
 
   if [[ $(echo $1 | grep -s "^[[:space:]]*set[[:space:]]") != "" ]] ; then
@@ -97,6 +101,8 @@ tkis_deny_private_variables(){
 
 # prevent the most dangerous command to run as root
 tkis_security_check_remove(){
+  local IFS=$' \t\n' # Prevent IFS exploits by overriding with a local scope.
+
   local oh_shit=
 
   # check as many possible ways to remove / as I can think of
@@ -128,6 +134,8 @@ tkis_security_check_remove(){
 # prevent very dangerous commands to run as root outside of chroot
 # check for removal of /bin /boot /dev /etc /home /lib /mnt /proc /sys /tmp /toolchain /var /usr (against the host system)
 tkis_security_check_host_remove(){
+  local IFS=$' \t\n' # Prevent IFS exploits by overriding with a local scope.
+
   local oh_shit=
 
   for i in bin boot dev etc home lib mnt proc sys tmp toolchain var usr documentation ; do
@@ -156,6 +164,8 @@ tkis_security_check_host_remove(){
 
 # make sure our global variables exist and are defined, otherwise generate an error so that unsafe transactions do not occur
 tkis_confirm_global_settings(){
+  local IFS=$' \t\n' # Prevent IFS exploits by overriding with a local scope.
+
   if [[ $tkis_path == "" ]] ; then
     error "$color_reset${color_notice}tkis_path$color_reset$color_error is not and should be defined by the install program"
   fi
index a57357fdf79b1f78b21cc7598f9207628038bac5..7cdacaa0fdaaac8f58b5e9940743fd934c432f08 100755 (executable)
@@ -1,6 +1,8 @@
 #!/bin/bash
 
 tkis_single_execution(){
+  local IFS=$' \t\n' # Prevent IFS exploits by overriding with a local scope.
+
   local program_name=$1
   local rule_name=$2
 
@@ -39,7 +41,7 @@ tkis_single_execution(){
   fi
 
   if ! [ -f $RU$tkis_process/$program_name ] ; then
-    error "tkis_single_execution(): The rule $color_reset$color_notice$RU$tkis_process/$program_name$color_error is missing or cannot be accessed" 
+    error "tkis_single_execution(): The rule $color_reset$color_notice$RU$tkis_process/$program_name$color_error is missing or cannot be accessed"
   fi
 
   if [ -f $system_version_file ] ; then
index 82c695b6dcfa2b6818b6151056735dd5e877f2b0..1362c9bc2ec39e91adceb209f7bf2b809f116741 100755 (executable)
@@ -1,6 +1,7 @@
 #!/bin/bash
 
 tkis_prepare(){
+  local IFS=$' \t\n' # Prevent IFS exploits by overriding with a local scope.
 
   if [[ $tkis_command != "wipe" && $tkis_command != "complete-clean" ]] ; then
     if [[ $tkis_process == "" ]] ; then
@@ -94,6 +95,8 @@ tkis_prepare(){
 }
 
 tkis_install_system(){
+  local IFS=$' \t\n' # Prevent IFS exploits by overriding with a local scope.
+
   debug "Processing preparation commands"
   tkis_prepare
 
@@ -138,6 +141,8 @@ tkis_install_system(){
 }
 
 tkis_system(){
+  local IFS=$' \t\n' # Prevent IFS exploits by overriding with a local scope.
+
   local start_time_day=
   local start_time_hour=
   local start_time_minute=
index db538fa176fefef27995f432aed55e03dff4c666..f50594130ed3fea280bf21a96a7ad6ef7188ae41 100755 (executable)
@@ -3,10 +3,14 @@
 
 # tkis_local_pop will do nothing for a user by hand
 tkis_local_pop(){
+  local IFS=$' \t\n' # Prevent IFS exploits by overriding with a local scope.
+
   echo
 }
 
 tkis_local_push(){
+  local IFS=$' \t\n' # Prevent IFS exploits by overriding with a local scope.
+
   if [[ $1 == "" ]] ; then
     echo "tkis_local_push(): first parameter is empty and should be either absolute, program, or work"
     sleep 2
@@ -36,6 +40,8 @@ tkis_local_push(){
 }
 
 tkis_local_get_version(){
+  local IFS=$' \t\n' # Prevent IFS exploits by overriding with a local scope.
+
   echo "tkis_local_get_version(): Please export LOCAL_VERSION=VERSION_OF_THE_PROGRAM, where the program is '$1' and VERSION_F_THE_PROGRAM is the version of '$1' to be used"
   sleep 2
   return 1
@@ -44,6 +50,8 @@ tkis_local_get_version(){
 
 # If a script requires the use of certain non-standard parameters that may or may not be defined, make sure they get defined
 tkis_local_require(){
+  local IFS=$' \t\n' # Prevent IFS exploits by overriding with a local scope.
+
   for i in $* ; do
     if [[ $(eval "echo \$$i") == "" ]] ; then
       echo "The variable $i is not defined, define it now:"
index 7ee68016a198d488935eaa382bde3bd023d72cf5..b9727c7c7b081372e3b48781826a18061de1d581 100755 (executable)
@@ -1,6 +1,8 @@
 #!/bin/bash
 
 tkis_upgrade(){
+  local IFS=$' \t\n' # Prevent IFS exploits by overriding with a local scope.
+
   local program_name=$1
   local version=$2
   local rule_name=$3
@@ -48,7 +50,7 @@ tkis_upgrade(){
   fi
 
   if ! [ -f $RU$list_filename/$program_name ] ; then
-    error "tkis_upgrade(): The rule $color_reset$color_notice$RU$list_filename/$program_name$color_error is missing or cannot be accessed" 
+    error "tkis_upgrade(): The rule $color_reset$color_notice$RU$list_filename/$program_name$color_error is missing or cannot be accessed"
   fi
 
   if [[ $(grep -s "^[[:space:]]*$version:[[:space:]]*$" $RU$list_filename/$program_name) != "" ]] ; then