1
mirror of https://github.com/rclone/rclone synced 2024-10-08 16:31:32 +02:00

config: stop config create making invalid config files

If config create was passed a parameter with an embedded \n it wrote
it straight to the config file which made it invalid and caused a
fatal error reloading it.

This stops keys and values with \r and \n being added to the config
file.

See: https://forum.rclone.org/t/how-to-control-bad-remote-creation-which-takes-rclone-down/37856
This commit is contained in:
Nick Craig-Wood 2023-04-27 12:46:43 +01:00
parent 1607344613
commit 27eb8c7f45

View File

@ -475,6 +475,9 @@ func updateRemote(ctx context.Context, name string, keyValues rc.Params, opt Upd
// Set the config
for k, v := range keyValues {
vStr := fmt.Sprint(v)
if strings.ContainsAny(k, "\n\r") || strings.ContainsAny(vStr, "\n\r") {
return nil, fmt.Errorf("update remote: invalid key or value contains \\n or \\r")
}
// Obscure parameter if necessary
if _, ok := needsObscure[k]; ok {
_, err := obscure.Reveal(vStr)
@ -483,7 +486,7 @@ func updateRemote(ctx context.Context, name string, keyValues rc.Params, opt Upd
// or we are forced to obscure
vStr, err = obscure.Obscure(vStr)
if err != nil {
return nil, fmt.Errorf("UpdateRemote: obscure failed: %w", err)
return nil, fmt.Errorf("update remote: obscure failed: %w", err)
}
}
}