Skip to content

Commit

Permalink
COPY: Check that target drive exists and if not return the proper err…
Browse files Browse the repository at this point in the history
…or code
  • Loading branch information
andrewbird authored and PerditionC committed Nov 6, 2022
1 parent ed05d18 commit 6f764c2
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion cmd/copy.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 6f764c2

Please # to comment.