commit:     ded20c5e676c093c592ebadb1d83d41989a4ef5d
Author:     Kerin Millar <kfm <AT> plushkava <DOT> net>
AuthorDate: Thu Feb 16 14:15:36 2023 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Fri Feb 17 01:33:28 2023 +0000
URL:        
https://gitweb.gentoo.org/proj/gentoo-functions.git/commit/?id=ded20c5e

Explicitly define IFS for invocations of the read builtin

This is appropriate for library code because there is no telling what
the value of IFS will be at any given moment. Also, POSIX does not
forbid implementations of sh(1) from inheriting the value of IFS from
the parent process, though this defect will be addressed by Issue 8. See
https://austingroupbugs.net/view.php?id=884 for further details.

Signed-off-by: Kerin Millar <kfm <AT> plushkava.net>
Signed-off-by: Sam James <sam <AT> gentoo.org>

 functions.sh | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/functions.sh b/functions.sh
index 22e6ef9..df72d4a 100644
--- a/functions.sh
+++ b/functions.sh
@@ -379,6 +379,9 @@ get_bootparam()
        # Similarly, the empty string must not be allowed to match.
        case $1 in ''|*,*) return 1 ;; esac
 
+       # Reset the value of IFS because there is no telling what it may be.
+       IFS=$(printf ' \n\t')
+
        if [ "${TEST_GENFUNCS}" = 1 ]; then
                read -r cmdline
        else
@@ -505,7 +508,7 @@ else
        # size operand is not portable.
        genfun_cols=$(
                stty size 2>/dev/null | {
-                       if read -r _ cols _; then
+                       if IFS=' ' read -r _ cols _; then
                                printf '%s\n' "${cols}"
                        fi
                }

Reply via email to