[v2,1/7] dts: escape single quotes

Message ID 20250314131857.1298247-2-luca.vizzarro@arm.com (mailing list archive)
State New
Delegated to: Paul Szczepanek
Headers
Series dts: shell improvements |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/loongarch-compilation warning apply patch failure

Commit Message

Luca Vizzarro March 14, 2025, 1:18 p.m. UTC
When making any command a privileged one in a LinuxSession, there
currently is no consideration whether this command already includes single
quotes. Therefore escape the existing single quotes before making the
command.

Signed-off-by: Luca Vizzarro <luca.vizzarro@arm.com>
Reviewed-by: Paul Szczepanek <paul.szczepanek@arm.com>
---
 dts/framework/testbed_model/linux_session.py | 1 +
 1 file changed, 1 insertion(+)
  

Comments

Dean Marx April 24, 2025, 5:55 p.m. UTC | #1
Reviewed-by: Dean Marx <dmarx@iol.unh.edu>
  
Patrick Robb April 25, 2025, 2:20 a.m. UTC | #2
Reviewed-by: Patrick Robb <probb@iol.unh.edu>
  
Nicholas Pratte April 25, 2025, 4:15 p.m. UTC | #3
Reviewed-by: Nicholas Pratte <npratte@iol.unh.edu>

On Fri, Mar 14, 2025 at 9:19 AM Luca Vizzarro <luca.vizzarro@arm.com> wrote:
>
> When making any command a privileged one in a LinuxSession, there
> currently is no consideration whether this command already includes single
> quotes. Therefore escape the existing single quotes before making the
> command.
>
> Signed-off-by: Luca Vizzarro <luca.vizzarro@arm.com>
> Reviewed-by: Paul Szczepanek <paul.szczepanek@arm.com>
> ---
>  dts/framework/testbed_model/linux_session.py | 1 +
>  1 file changed, 1 insertion(+)
>
> diff --git a/dts/framework/testbed_model/linux_session.py b/dts/framework/testbed_model/linux_session.py
> index 7c2b110c99..6c6a4b608d 100644
> --- a/dts/framework/testbed_model/linux_session.py
> +++ b/dts/framework/testbed_model/linux_session.py
> @@ -67,6 +67,7 @@ class LinuxSession(PosixSession):
>
>      @staticmethod
>      def _get_privileged_command(command: str) -> str:
> +        command = command.replace(r"'", r"\'")
>          return f"sudo -- sh -c '{command}'"
>
>      def get_remote_cpus(self) -> list[LogicalCore]:
> --
> 2.43.0
>
  

Patch

diff --git a/dts/framework/testbed_model/linux_session.py b/dts/framework/testbed_model/linux_session.py
index 7c2b110c99..6c6a4b608d 100644
--- a/dts/framework/testbed_model/linux_session.py
+++ b/dts/framework/testbed_model/linux_session.py
@@ -67,6 +67,7 @@  class LinuxSession(PosixSession):
 
     @staticmethod
     def _get_privileged_command(command: str) -> str:
+        command = command.replace(r"'", r"\'")
         return f"sudo -- sh -c '{command}'"
 
     def get_remote_cpus(self) -> list[LogicalCore]: