generated from kubernetes/kubernetes-template-project
-
Notifications
You must be signed in to change notification settings - Fork 962
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix JuicefsRuntime: escape customized string before constructing comm…
…ands (#3761) * add escapeBashStr Signed-off-by: xixi <hexilee@juicedata.io> * avoid bash -c in operations Signed-off-by: xixi <hexilee@juicedata.io> * fix GetUsedSpace and GetFileCount Signed-off-by: xixi <hexilee@juicedata.io> * move EscapeBashStr to pkg/utils/security Signed-off-by: xixi <hexilee@juicedata.io> * add left Signed-off-by: xixi <hexilee@juicedata.io> * resume GetFileCount Signed-off-by: xixi <hexilee@juicedata.io> * Escape value.Configs.Name Signed-off-by: trafalgarzzz <trafalgarz@outlook.com> * Fix unit tests Signed-off-by: trafalgarzzz <trafalgarz@outlook.com> * Upgrade juicefs helm chart version to 0.2.16 Signed-off-by: trafalgarzzz <trafalgarz@outlook.com> --------- Signed-off-by: xixi <hexilee@juicedata.io> Signed-off-by: trafalgarzzz <trafalgarz@outlook.com> Co-authored-by: xixi <hexilee@juicedata.io> Co-authored-by: trafalgarzzz <trafalgarz@outlook.com>
- Loading branch information
1 parent
68ea529
commit 02b7cd8
Showing
8 changed files
with
173 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
Copyright 2023 The Fluid Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package security | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
) | ||
|
||
// According to https://www.gnu.org/software/bash/manual/html_node/ANSI_002dC-Quoting.html#ANSI_002dC-Quoting | ||
// a -> a | ||
// a b -> a b | ||
// $a -> $'$a' | ||
// $'a' -> $'$\'$a'\' | ||
func EscapeBashStr(s string) string { | ||
if !containsOne(s, []rune{'$', '`', '&', ';', '>', '|', '(', ')'}) { | ||
return s | ||
} | ||
s = strings.ReplaceAll(s, `\`, `\\`) | ||
s = strings.ReplaceAll(s, `'`, `\'`) | ||
if strings.Contains(s, `\\`) { | ||
s = strings.ReplaceAll(s, `\\\\`, `\\`) | ||
s = strings.ReplaceAll(s, `\\\'`, `\'`) | ||
s = strings.ReplaceAll(s, `\\"`, `\"`) | ||
s = strings.ReplaceAll(s, `\\a`, `\a`) | ||
s = strings.ReplaceAll(s, `\\b`, `\b`) | ||
s = strings.ReplaceAll(s, `\\e`, `\e`) | ||
s = strings.ReplaceAll(s, `\\E`, `\E`) | ||
s = strings.ReplaceAll(s, `\\n`, `\n`) | ||
s = strings.ReplaceAll(s, `\\r`, `\r`) | ||
s = strings.ReplaceAll(s, `\\t`, `\t`) | ||
s = strings.ReplaceAll(s, `\\v`, `\v`) | ||
s = strings.ReplaceAll(s, `\\?`, `\?`) | ||
} | ||
return fmt.Sprintf(`$'%s'`, s) | ||
} | ||
|
||
func containsOne(target string, chars []rune) bool { | ||
charMap := make(map[rune]bool, len(chars)) | ||
for _, c := range chars { | ||
charMap[c] = true | ||
} | ||
for _, s := range target { | ||
if charMap[s] { | ||
return true | ||
} | ||
} | ||
return false | ||
} |
Oops, something went wrong.