Skip to content

Commit e9b9cac

Browse files
committed
Prevent folder from trying to move inside itself
1 parent 45ee130 commit e9b9cac

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

supervisor/shared/web_workflow/web_workflow.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1080,7 +1080,19 @@ static bool _reply(socketpool_socket_obj_t *socket, _request *request) {
10801080
destination[destinationlen - 1] = '\0';
10811081
}
10821082

1083-
FRESULT result = f_rename(fs, path, destination);
1083+
// Check to see if we're moving a directory into itself.
1084+
FILINFO file;
1085+
FRESULT result = f_stat(fs, path, &file);
1086+
if (result == FR_OK) {
1087+
if ((file.fattrib & AM_DIR) != 0 &&
1088+
strlen(destination) > strlen(path) &&
1089+
destination[strlen(path)] == '/' &&
1090+
strncmp(path, destination, strlen(path)) == 0) {
1091+
result = FR_NO_PATH;
1092+
} else {
1093+
result = f_rename(fs, path, destination);
1094+
}
1095+
}
10841096
#if CIRCUITPY_USB_MSC
10851097
usb_msc_unlock();
10861098
#endif

0 commit comments

Comments
 (0)