From 0096e7efce67ac00c8139bb73c2b5f771541c1c8 Mon Sep 17 00:00:00 2001 From: abraunegg Date: Mon, 25 May 2020 10:51:57 +1000 Subject: [PATCH] Add file validation for moved / renamed files (#929) * When renaming a file locally, ensure that the target filename is valid before attempting to upload to OneDrive --- src/sync.d | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/sync.d b/src/sync.d index e14ad13a..96b71b05 100644 --- a/src/sync.d +++ b/src/sync.d @@ -4026,6 +4026,41 @@ final class SyncEngine void uploadMoveItem(string from, string to) { log.log("Moving ", from, " to ", to); + + // 'to' file validation .. is the 'to' file valid for upload? + if (isSymlink(to)) { + // if config says so we skip all symlinked items + if (cfg.getValueBool("skip_symlinks")) { + log.vlog("Skipping item - skip symbolic links configured: ", to); + return; + + } + // skip unexisting symbolic links + else if (!exists(readLink(to))) { + log.log("Skipping item - invalid symbolic link: ", to); + return; + } + } + + // Restriction and limitations about windows naming files + if (!isValidName(to)) { + log.log("Skipping item - invalid name (Microsoft Naming Convention): ", to); + return; + } + + // Check for bad whitespace items + if (!containsBadWhiteSpace(to)) { + log.log("Skipping item - invalid name (Contains an invalid whitespace item): ", to); + return; + } + + // Check for HTML ASCII Codes as part of file name + if (!containsASCIIHTMLCodes(to)) { + log.log("Skipping item - invalid name (Contains HTML ASCII Code): ", to); + return; + } + + // 'to' file has passed file validation Item fromItem, toItem, parentItem; if (!itemdb.selectByPath(from, defaultDriveId, fromItem)) { if (cfg.getValueBool("skip_dotfiles") && isDotFile(to)){