Enquote file path for shell execution.

Also, fix json of 500 response.
This commit is contained in:
Maximilian Paß
2022-08-21 12:35:13 +02:00
parent 152b77afe5
commit fc77f11d4d
4 changed files with 16 additions and 6 deletions

View File

@ -95,7 +95,11 @@ func (r *RunnerController) listFileSystem(writer http.ResponseWriter, request *h
}
writer.Header().Set("Content-Type", "application/json")
if err := targetRunner.ListFileSystem(path, recursive, writer, request.Context()); err != nil {
err = targetRunner.ListFileSystem(path, recursive, writer, request.Context())
if errors.Is(err, runner.ErrFileNotFound) {
writeNotFound(writer, err)
return
} else if err != nil {
log.WithError(err).Error("Could not perform the requested listFileSystem.")
writeInternalServerError(writer, err, dto.ErrorUnknown)
return

View File

@ -127,7 +127,7 @@ func (r *NomadJob) ListFileSystem(path string, recursive bool, content io.Writer
ls2json := &nullio.Ls2JsonWriter{Target: content}
defer ls2json.Close()
retrieveCommand := (&dto.ExecutionRequest{Command: fmt.Sprintf("%s %s", command, path)}).FullCommand()
retrieveCommand := (&dto.ExecutionRequest{Command: fmt.Sprintf("%s %q", command, path)}).FullCommand()
exitCode, err := r.api.ExecuteCommand(r.id, ctx, retrieveCommand, false, &nullio.Reader{}, ls2json, io.Discard)
if err != nil {
return fmt.Errorf("%w: nomad error during retrieve file headers: %v",
@ -175,7 +175,7 @@ func (r *NomadJob) UpdateFileSystem(copyRequest *dto.UpdateFileSystemRequest) er
func (r *NomadJob) GetFileContent(path string, content io.Writer, ctx context.Context) error {
r.ResetTimeout()
retrieveCommand := (&dto.ExecutionRequest{Command: fmt.Sprintf("cat %s", path)}).FullCommand()
retrieveCommand := (&dto.ExecutionRequest{Command: fmt.Sprintf("cat %q", path)}).FullCommand()
// Improve: Instead of using io.Discard use a **fixed-sized** buffer. With that we could improve the error message.
exitCode, err := r.api.ExecuteCommand(r.id, ctx, retrieveCommand, false, &nullio.Reader{}, content, io.Discard)