Skip to content

Commit

Permalink
iss-4535
Browse files Browse the repository at this point in the history
Single quotes in folder or file names were causing corruption of the shell command.
The fix changes the ' character to '"'"'
For example a folder called te'st would now get shellQuoted to 'te'"'"'st'
1. ' ends the first quote,
2. " starts second quote,
3. ' is valid character in double quotes
4. " ends the second quote
5. ' starts the third quote
6. The end result when fed into the shell, is as we desired: te'st

fabric8io#4535
  • Loading branch information
BrianDevC committed Oct 27, 2022
1 parent 4bb7778 commit 8f5c7aa
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
### 6.2.0 (2022-10-20)

#### Bugs
* Fix #4535: The shell command string will now have single quotes sanitized
* Fix #3733: The authentication command from the .kube/config won't be discarded if no arguments are specified
* Fix #4312: fix timestamp can't be deserialized for IstioCondition
* Fix #4369: Informers will retry with a backoff on list/watch failure as they did in 5.12 and prior.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,7 @@ public BytesLimitTerminateTimeTailPrettyLoggable usingTimestamps() {
}

public static String shellQuote(String value) {
return "'" + value.replace("'", "'\\\\''") + "'";
return "'" + value.replace("'", "\'\"\'\"\'") + "'";
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,26 @@ void createExecCommandForUpload_withNormalFile_shouldCreateValidExecCommandForUp
assertThat(result, equalTo("mkdir -p '/tmp/foo' && base64 -d - > '/tmp/foo/cp.log'"));
}

@Test
void createExecCommandForUpload_withSingleQuoteInPath()
{
// When
String result = PodUpload.createExecCommandForUpload("/tmp/fo'o/cp.log");

// Then
assertThat(result, equalTo("mkdir -p '/tmp/fo\'\"\'\"\'o' && base64 -d - > '/tmp/fo\'\"\'\"\'o/cp.log'"));
}

@Test
void createExecCommandForUpload_withMultipleSingleQuotesInPath()
{
// When
String result = PodUpload.createExecCommandForUpload("/tmp/f'o'o/c'p.log");

// Then
assertThat(result, equalTo("mkdir -p '/tmp/f\'\"\'\"\'o\'\"\'\"\'o' && base64 -d - > '/tmp/f\'\"\'\"\'o\'\"\'\"\'o/c\'\"\'\"\'p.log'"));
}

void uploadFileAndVerify(PodUploadTester<Boolean> fileUploadMethodToTest) throws IOException, InterruptedException {
this.operation = operation.file("/mock/dir/file");
WebSocket.Builder builder = Mockito.mock(WebSocket.Builder.class, Mockito.RETURNS_SELF);
Expand Down

0 comments on commit 8f5c7aa

Please sign in to comment.