Prevent recursive aliases

This commit is contained in:
Mickaël Menu 2021-02-13 21:07:06 +01:00
parent 9f0b5dc7d4
commit e12d7cca42
No known key found for this signature in database
GPG Key ID: 53D73664CD359895

View File

@ -106,12 +106,16 @@ func indexZk(container *cmd.Container) {
// runAlias will execute a user alias if the command is one of them.
func runAlias(container *cmd.Container, args []string) (bool, error) {
runningAlias := os.Getenv("ZK_RUNNING_ALIAS")
if zk, err := container.OpenZk(); err == nil && len(args) >= 1 {
for alias, cmdStr := range zk.Config.Aliases {
if alias != args[0] {
if alias == runningAlias || alias != args[0] {
continue
}
// Prevent infinite loop if an alias calls itself.
os.Setenv("ZK_RUNNING_ALIAS", alias)
cmd := executil.CommandFromString(cmdStr, args[1:]...)
cmd.Stdin = os.Stdin
cmd.Stdout = os.Stdout