Bug or feature? Handling of $var is different to ${var}
Mantenedores costumam responder em até 1 dia
Ninguém assumiu esta issue ainda.
Avaliação
- Dificuldade
- 4/5
- Tempo estimado
- 3-5 dias
- Facilidade para iniciantes
- 35/100
- Tipo de issue
- Bug
- Clareza
- Razoavelmente clara
- Status de atividade
- Estagnada
- Stack de tecnologia
- bash, c
- Domínio
- cli, operating-systems
Direção de pesquisa
Start with the parse_args escape handling in src/parse_args.c around lines 626–634, then compare the arguments passed to the shell for $var and ${var} using the reproductions in the issue. Check the relevant sudo tests for argument escaping and add coverage that captures the intended behavior. Done means the behavior is defined and tested so upgrades do not unexpectedly change how these forms are passed to the shell.
Escrita pelo modelo de indexação a partir do texto da issue.
Descrição
I'm not sure if it is bug or a feature, but if you try to execute a command in a login shell, then the behavior when using $var and ${var} is different (which is unusual).
To replicate execute:
$ sudo -i bash -c '(export var=/etc; cd $var; pwd)'
/root
$ sudo -i bash -c '(export var=/etc; cd ${var}; pwd)'
/etc
In our case we are glad that ${var} is working as expected, i.e. is is NOT expanded before, so that cd would change into /etc in this example.
I guess the reason is the escape handling in parse_args in src/parse_args.c:
As the $ is not being escaped but the { and } (is not alnum), the resulting arguments passed to the shell are different, which can also be verified in the debug log:
Sep 20 14:48:40 sudo[9839] -> sudo_execve @ ./exec_common.c:184
Sep 20 14:48:40 sudo[9839] exec /bin/bash [-bash --login -c bash -c \(export\ var\=\/etc\;\ cd\ $\{var\}\;\ pwd\;\ env\|grep\ SUDO_C\)] [HOSTNAME=
...
Sep 20 14:51:08 sudo[10689] -> sudo_execve @ ./exec_common.c:184
Sep 20 14:51:08 sudo[10689] exec /bin/bash [-bash --login -c bash -c \(export\ var\=\/etc\;\ cd\ $var\;\ pwd\;\ env\|grep\ SUDO_C\)] [HOSTNAME=
The main question here is, is this a bug or a feature? We are using the ${var} variant in tons of productive workflow environments and we don't want to fall into a trap, once the behavior get changed and we are updating to a newer version.
Environment details:
- sudo version: 1.8.23
- OS: RHEL 7.9 running in AWS (same behavior can be seen in ubuntu 22.04 and others)
Thanks, Christian
- Linguagem predominante
- C
- Estrelas
- 1.7k
- Forks
- 306
- Merge médio
- 1d 2h
- PRs com merge (30d)
- 22
Preparar o ambiente
Este projeto não oferece contêiner de desenvolvimento, Dockerfile nem guia de contribuição, então a configuração fica por sua conta: comece pelo README e veja nosso guia da primeira contribuição para os passos gerais.
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Mais de sudo-project/sudo
-
Dificuldade 4/5 3-5 dias Facilidade para iniciantes 42/100
sudo-project/sudo#583 ·
Mantenedores costumam responder em até 1 dia
-
Dificuldade 4/5 3-5 dias Facilidade para iniciantes 45/100
sudo-project/sudo#581 · 4 comentários ·
Mantenedores costumam responder em até 1 dia
-
Signal forwarded to the command is lost when it arrives between fork() and execve() of the commandAberta
Dificuldade 4/5 3-5 dias Facilidade para iniciantes 35/100
sudo-project/sudo#566 ·
Mantenedores costumam responder em até 1 dia
-
Dificuldade 3/5 1-2 dias Facilidade para iniciantes 52/100
sudo-project/sudo#553 ·
Mantenedores costumam responder em até 1 dia
-
Dificuldade 4/5 3-5 dias Facilidade para iniciantes 48/100
sudo-project/sudo#552 ·
Mantenedores costumam responder em até 1 dia
Todas as issues de sudo-project/sudo
Issues semelhantes
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 78/100
InukaAsith/TwinDesk#84 ·
Mantenedores costumam responder em até 2 dias
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 78/100
CanadaHonk/porffor#426 ·
-
Dificuldade 1/5 Menos de uma hora Facilidade para iniciantes 77/100
raysan5/raylib.com#132 ·
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 72/100
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 76/100