Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!

Bug 937538

Summary: app-alternatives/sh: consider package.use.masking lksh
Product: Gentoo Linux Reporter: kfm <kfm>
Component: Current packagesAssignee: Gentoo's Team for Core System packages <base-system>
Status: RESOLVED INVALID    
Severity: normal CC: kfm
Priority: Normal    
Version: unspecified   
Hardware: All   
OS: Linux   
Whiteboard:
Package list:
Runtime testing required: ---

Description kfm 2024-08-07 21:39:55 UTC
Consider the following, as executed in the loksh shell.

# printf '%s\n' '#!/bin/sh' > cmd1
# chmod +x cmd1
# cmd2() { :; }
# unset LEAKED
# LEAKED=1 ./cmd1; echo "LEAKED = $LEAKED"
LEAKED =
# LEAKED=1   cmd2; echo "LEAKED = $LEAKED"
LEAKED = 1

This shows a variable assignment incorporated by a simple command being allowed to persist beyond the execution environment established for said simple command, provided that it is charged with calling a function. I discovered this with the aid of the unit tests for sys-apps/gentoo-functions.

Strictly speaking, such behaviour is permitted. The Shell Command Language specification states:

"""
If the command name is a function that is not a standard utility implemented as a function, variable assignments shall affect the current execution environment during the execution of the function. It is unspecified:

- Whether or not the variable assignments persist after the completion of the function

- Whether or not the variables gain the export attribute during the execution of the function

- Whether or not export attributes gained as a result of the variable assignments persist after the completion of the function (if variable assignments persist after the completion of the function)
"""

Unfortunately, loksh elects not to be aligned with the practices of the overwhelming majority of implementations in this regard. I can state with confidence that this makes it very risky to have it as the /bin/sh implementation. That is, it *will* break scripts in the wild.

I don't think that this is necessarily a reason to drop loksh as a potential target but I do think that it may be a reason to prevent hapless users from being able to casually select it. As such, I wonder whether it should be package.use.masked.
Comment 1 kfm 2024-08-07 21:43:57 UTC
I would also suggest considering the same question of "ksh", albeit for different technical reasons. However, I'll file a distinct issue for that.
Comment 2 kfm 2024-08-07 21:52:25 UTC
Never mind. I conflated the loksh shell with the purpose of the lksh flag. Closing and please excuse the noise.