From 27eb8c7f4580d6436efa16bcda5b1f4ee143340a Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Thu, 27 Apr 2023 12:46:43 +0100 Subject: [PATCH] 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 --- fs/config/config.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/fs/config/config.go b/fs/config/config.go index b2a354037..145f2a2df 100644 --- a/fs/config/config.go +++ b/fs/config/config.go @@ -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) } } }