From 6f764c2065fa6ffc3cbeba18043d9a4d0e22a00c Mon Sep 17 00:00:00 2001 From: Andrew Bird Date: Sat, 5 Nov 2022 12:21:44 +0000 Subject: [PATCH] COPY: Check that target drive exists and if not return the proper error code --- cmd/copy.c | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/cmd/copy.c b/cmd/copy.c index 1c5d98d0..a8c88ff4 100644 --- a/cmd/copy.c +++ b/cmd/copy.c @@ -222,6 +222,20 @@ static int BIGcopy(int fdout, int fdin, int asc) return retval; } +static int is_valid_disk(int tstdsk) +{ + int savdsk = getdisk(); + int newdsk; + + /* Change to new disk */ + setdisk(tstdsk); + newdsk = getdisk(); + + /* Restore */ + setdisk(savdsk); + + return (newdsk == tstdsk); +} static int copy(char *dst, char *pattern, struct CopySource *src , int openMode) @@ -437,7 +451,7 @@ static int copy(char *dst, char *pattern, struct CopySource *src unlink(rDest); /* if device -> no removal, ignore error */ return 0; } - } while(wildcarded && dos_findnext(&ff) == 0); + } while (wildcarded && dos_findnext(&ff) == 0); /*} while(wildcarded && FINDNEXT(&ff) == 0 && !(isfirst = 0)); */ dos_findclose(&ff); @@ -642,6 +656,14 @@ int cmd_copy(char *rest) destFile = ".\\*.*"; } +#define dst destFile + /* If the destination specifies a drive, check that it is valid */ + if (dst[0] && dst[1] == ':' && !is_valid_disk(dst[0] - 'A')) { + error_invalid_drive(dst[0] - 'A'); + return 0; + } +#undef dst + /* Now copy the files */ h = head; while(copyFiles(h) && (h = h->nxt) != 0);