Skip to content

Commit 6902279

Browse files
committed
nit: address code review comments
Signed-off-by: Nate Bracy <[email protected]>
1 parent a568372 commit 6902279

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

internal/oci/runtime_syscall_exec.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import (
2929
// properly handled.
3030
//
3131
// These metacharacters include: | & ; ( ) < > \t \n $ \ `
32-
const shellMetachars = "|&;()<> \t\n$\\`"
32+
const shellMetachars = "|&;()<> \t\n$\\`'\""
3333

3434
// metacharRegex matches any shell metacharcter.
3535
var metacharRegex = regexp.MustCompile(`([` + regexp.QuoteMeta(shellMetachars) + `])`)
@@ -54,11 +54,10 @@ func (r syscallExec) String() string {
5454
return "exec"
5555
}
5656

57-
// Escape1 escapes shell metacharacters in a single command-line argument.
58-
func Escape1(arg string) string {
57+
// escapeArg escapes shell metacharacters in a single command-line argument.
58+
func escapeArg(arg string) string {
5959
if strings.ContainsAny(arg, shellMetachars) {
60-
e := metacharRegex.ReplaceAllString(arg, `\$1`)
61-
return fmt.Sprintf(`"%s"`, e)
60+
return metacharRegex.ReplaceAllString(arg, `\$1`)
6261
}
6362
return arg
6463
}
@@ -68,7 +67,7 @@ func Escape1(arg string) string {
6867
func Escape(args []string) []string {
6968
escaped := make([]string, len(args))
7069
for i := range args {
71-
escaped[i] = Escape1(args[i])
70+
escaped[i] = escapeArg(args[i])
7271
}
7372
return escaped
7473
}

internal/oci/runtime_syscall_exec_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
# Copyright (c) 2021, NVIDIA CORPORATION. All rights reserved.
2+
# Copyright (c) 2025, NVIDIA CORPORATION. All rights reserved.
33
#
44
# Licensed under the Apache License, Version 2.0 (the "License");
55
# you may not use this file except in compliance with the License.

0 commit comments

Comments
 (0)