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:
parent
1607344613
commit
27eb8c7f45
1 changed files with 4 additions and 1 deletions
|
@ -475,6 +475,9 @@ func updateRemote(ctx context.Context, name string, keyValues rc.Params, opt Upd
|
||||||
// Set the config
|
// Set the config
|
||||||
for k, v := range keyValues {
|
for k, v := range keyValues {
|
||||||
vStr := fmt.Sprint(v)
|
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
|
// Obscure parameter if necessary
|
||||||
if _, ok := needsObscure[k]; ok {
|
if _, ok := needsObscure[k]; ok {
|
||||||
_, err := obscure.Reveal(vStr)
|
_, 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
|
// or we are forced to obscure
|
||||||
vStr, err = obscure.Obscure(vStr)
|
vStr, err = obscure.Obscure(vStr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("UpdateRemote: obscure failed: %w", err)
|
return nil, fmt.Errorf("update remote: obscure failed: %w", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue