From e9b9cac2321654a8b62c1e6e798eee11b6d3c1b8 Mon Sep 17 00:00:00 2001 From: Melissa LeBlanc-Williams Date: Fri, 9 Sep 2022 15:11:35 -0700 Subject: [PATCH] Prevent folder from trying to move inside itself --- supervisor/shared/web_workflow/web_workflow.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/supervisor/shared/web_workflow/web_workflow.c b/supervisor/shared/web_workflow/web_workflow.c index e09c87f624..3f2c924923 100644 --- a/supervisor/shared/web_workflow/web_workflow.c +++ b/supervisor/shared/web_workflow/web_workflow.c @@ -1080,7 +1080,19 @@ static bool _reply(socketpool_socket_obj_t *socket, _request *request) { destination[destinationlen - 1] = '\0'; } - FRESULT result = f_rename(fs, path, destination); + // Check to see if we're moving a directory into itself. + FILINFO file; + FRESULT result = f_stat(fs, path, &file); + if (result == FR_OK) { + if ((file.fattrib & AM_DIR) != 0 && + strlen(destination) > strlen(path) && + destination[strlen(path)] == '/' && + strncmp(path, destination, strlen(path)) == 0) { + result = FR_NO_PATH; + } else { + result = f_rename(fs, path, destination); + } + } #if CIRCUITPY_USB_MSC usb_msc_unlock(); #endif