From f28c014c6f545a447b7a5a66ac5ee333c17b7ddc Mon Sep 17 00:00:00 2001 From: Nick Briggs Date: Mon, 3 Feb 2025 18:55:53 -0800 Subject: [PATCH 1/4] Replaces ConcNameAndVersion and ConcDirAndName macros with functions Replaces ConcNameAndVersion and ConcDirAndName macros with conc_name_and_version and conc_dir_and_name functions respectively, moves the definitions from locfile.h to dsk.c, and adds them to dskdefs.h for use by other source files. --- inc/dskdefs.h | 2 + inc/locfile.h | 84 ---------------- src/dsk.c | 269 +++++++++++++++++++++++++++++++++----------------- src/ufs.c | 6 +- 4 files changed, 183 insertions(+), 178 deletions(-) diff --git a/inc/dskdefs.h b/inc/dskdefs.h index f5cfa94c..3fd2e792 100644 --- a/inc/dskdefs.h +++ b/inc/dskdefs.h @@ -19,6 +19,8 @@ LispPTR COM_writepage(LispPTR *args); LispPTR COM_truncatefile(LispPTR *args); LispPTR COM_changedir(LispPTR *args); LispPTR COM_getfreeblock(LispPTR *args); +void conc_dir_and_name(char *dir, char *name, char *fname); +void conc_name_and_version(char *name, char *ver, char *rname); void separate_version(char *name, char *ver, int checkp); int unpack_filename(char *file, char *dir, char *name, char *ver, int checkp); int true_name(char *path); diff --git a/inc/locfile.h b/inc/locfile.h index 856c23d6..58d7fc59 100644 --- a/inc/locfile.h +++ b/inc/locfile.h @@ -410,90 +410,6 @@ do { \ } \ } while (0) -/* - * Name: ConcDirAndName - * - * Argument: char *dir The name of the directory. - * char *name The name of a file. - * char *fname The place where the full file name should be - * stored. - * Value: N/A - * - * Side Effect: fname is replaced with the full file name. - * - * Description: - * - * Concatenate the directory name and root file name. Checks if dir contains - * the trail directory delimiter or not. - * - */ - -#define ConcDirAndName(dir, name, fname) do { \ - \ - char *lf_cp1, *lf_cp2; \ - \ - lf_cp1 = dir; \ - lf_cp2 = dir; \ - \ - while (*lf_cp2 != '\0') { \ - switch (*lf_cp2) { \ - \ - case '/': \ - lf_cp1 = lf_cp2; \ - lf_cp2++; \ - break; \ - \ - default: \ - lf_cp2++; \ - break; \ - } \ - } \ - if (lf_cp1 == (lf_cp2 - 1)) { \ - if (lf_cp1 == (dir)) { \ - /* dir is a root directory. */ \ - strcpy(fname, "/"); \ - strcat(fname, name); \ - } else { \ - /* The trail directory is included. */ \ - strcpy(fname, dir); \ - strcat(fname, name); \ - } \ - } else { \ - /* The trail directory is not included */ \ - strcpy(fname, dir); \ - strcat(fname, "/"); \ - strcat(fname, name); \ - } \ - } while (0) - -/* - * Name: ConcNameAndVersion - * - * Argument: char *name The root file name. - * char *ver The file version. - * char *rname The place where the concatenated file name will be - * stored. - * Value: N/A - * - * Side Effect: rname is replaced with the concatenated file name. - * - * Description: - * - * Concatenate the root file name and its version in UNIX format. - * - */ - -#define ConcNameAndVersion(name, ver, rname) do { \ - if (*(ver) != '\0') { \ - strcpy(rname, name); \ - strcat(rname, ".~"); \ - strcat(rname, ver); \ - strcat(rname, "~"); \ - } else { \ - strcpy(rname, name); \ - } \ -} while (0) - #define VERSIONLEN 16 #define MAXVERSION 999999999 diff --git a/src/dsk.c b/src/dsk.c index a96a0f43..cb27760e 100644 --- a/src/dsk.c +++ b/src/dsk.c @@ -27,7 +27,7 @@ #include "car-cdrdefs.h" // for cdr, car #include "dskdefs.h" // for COM_changedir, COM_closefile, COM_getfile... #include "lispemul.h" // for NIL, LispPTR, ATOM_T -#include "locfile.h" // for ConcDirAndName, LASTVERSIONARRAY, ConcNam... +#include "locfile.h" // for LASTVERSIONARRAY #include "lspglob.h" #include "lsptypes.h" #include "timeout.h" // for TIMEOUT, ERRSETJMP, S_TOUT, TIMEOUT0 @@ -84,7 +84,6 @@ static int get_oldest(char *dir, FileName *varray, char *afile, char *vfile); static int get_new(char *dir, FileName *varray, char *afile, char *vfile); static int get_old_new(char *dir, FileName *varray, char *afile, char *vfile); static int get_version_array(char *dir, char *file); - #ifdef DOS static void separate_drive(char *lfname, char *drive) { @@ -376,7 +375,7 @@ LispPTR COM_openfile(LispPTR *args) if (unpack_filename(file, dir, name, ver, 1) == 0) return (NIL); if (true_name(dir) != -1) return (0); if (get_version_array(dir, name) == 0) return (NIL); - ConcNameAndVersion(name, ver, file); + conc_name_and_version(name, ver, file); switch (args[1]) { case RECOG_OLD: @@ -888,7 +887,7 @@ LispPTR DSK_getfilename(LispPTR *args) */ if (get_version_array(dir, name) == 0) return (NIL); - ConcNameAndVersion(name, ver, aname); + conc_name_and_version(name, ver, aname); if (get_old(dir, VA.files, aname, vname) == 0) return (NIL); if ((rval = true_name(aname)) == 0) return (NIL); @@ -928,7 +927,7 @@ LispPTR DSK_getfilename(LispPTR *args) } else { if (get_version_array(dir, name) == 0) return (NIL); - ConcNameAndVersion(name, ver, aname); + conc_name_and_version(name, ver, aname); if (get_oldest(dir, VA.files, aname, vname) == 0) return (NIL); if ((rval = true_name(aname)) == 0) return (NIL); @@ -966,7 +965,7 @@ LispPTR DSK_getfilename(LispPTR *args) strcpy(vname, dir); dirp = 1; } else { - ConcDirAndName(dir, name, aname); + conc_dir_and_name(dir, name, aname); if ((rval = true_name(aname)) == -1) { strcpy(vname, aname); dirp = 1; @@ -977,7 +976,7 @@ LispPTR DSK_getfilename(LispPTR *args) */ if (get_version_array(dir, name) == 0) return (NIL); - ConcNameAndVersion(name, ver, aname); + conc_name_and_version(name, ver, aname); if (get_new(dir, VA.files, aname, vname) == 0) return (NIL); dirp = 0; } @@ -996,14 +995,14 @@ LispPTR DSK_getfilename(LispPTR *args) strcpy(vname, file); dirp = 0; } else { - ConcDirAndName(dir, name, aname); + conc_dir_and_name(dir, name, aname); if ((rval = true_name(aname)) == -1) { strcpy(vname, aname); dirp = 1; } else { if (get_version_array(dir, name) == 0) return (NIL); - ConcNameAndVersion(name, ver, aname); + conc_name_and_version(name, ver, aname); if (get_old_new(dir, VA.files, aname, vname) == 0) return (NIL); dirp = 0; } @@ -1019,7 +1018,7 @@ LispPTR DSK_getfilename(LispPTR *args) * directories. The file name itself is recognized as if. */ if (true_name(dir) != -1) return (NIL); - ConcDirAndName(dir, name, vname); + conc_dir_and_name(dir, name, vname); strcpy(aname, vname); if (true_name(aname) == -1) { strcpy(vname, aname); @@ -1057,8 +1056,8 @@ LispPTR DSK_getfilename(LispPTR *args) { char dver[VERSIONLEN]; separate_version(vname, dver, 0); - ConcDirAndName(dir, name, aname); - ConcNameAndVersion(aname, dver, vname); + conc_dir_and_name(dir, name, aname); + conc_name_and_version(aname, dver, vname); } #endif /* DOS */ @@ -1143,7 +1142,7 @@ LispPTR DSK_deletefile(LispPTR *args) * of it. */ - ConcNameAndVersion(fbuf, ver, file); + conc_name_and_version(fbuf, ver, file); if (get_oldest(dir, VA.files, file, fbuf) == 0) return (NIL); if (get_versionless(VA.files, vless, dir) == 0) { @@ -1295,7 +1294,7 @@ LispPTR DSK_renamefile(LispPTR *args) /* * We maintain the destination to handle the link damaged case correctly. */ - ConcDirAndName(dir, fbuf, dst); + conc_dir_and_name(dir, fbuf, dst); if (maintain_version(dst, 0) == 0) return (NIL); if (get_version_array(dir, fbuf) == 0) return (NIL); @@ -1306,7 +1305,7 @@ LispPTR DSK_renamefile(LispPTR *args) * of it. */ - ConcNameAndVersion(fbuf, ver, dst); + conc_name_and_version(fbuf, ver, dst); if (get_new(dir, VA.files, dst, fbuf) == 0) return (NIL); /* @@ -1321,7 +1320,7 @@ LispPTR DSK_renamefile(LispPTR *args) if (OnlyVersionlessP(VA.files)) { get_versionless(VA.files, vless, dir); if (strcmp(dst, vless) != 0) { - ConcNameAndVersion(vless, "1", fbuf); + conc_name_and_version(vless, "1", fbuf); TIMEOUT(rval = rename(vless, fbuf)); if (rval == -1) { *Lisp_errno = errno; @@ -1361,7 +1360,7 @@ LispPTR DSK_renamefile(LispPTR *args) * code, we have to recognize it again to know the "real" accessible name * of it. */ - ConcNameAndVersion(fbuf, ver, src); + conc_name_and_version(fbuf, ver, src); if (get_old(dir, VA.files, src, fbuf) == 0) return (NIL); if (get_versionless(VA.files, vless, dir) == 0) { @@ -1623,7 +1622,7 @@ LispPTR COM_getfileinfo(LispPTR *args) strcpy(file, dir); } else { if (get_version_array(dir, name) == 0) return (NIL); - ConcNameAndVersion(name, ver, file); + conc_name_and_version(name, ver, file); if (get_old(dir, VA.files, file, name) == 0) return (NIL); } } @@ -1812,7 +1811,7 @@ LispPTR COM_setfileinfo(LispPTR *args) if (unpack_filename(file, dir, name, ver, 1) == 0) return (NIL); if (true_name(dir) != -1) return (0); if (get_version_array(dir, name) == 0) return (NIL); - ConcNameAndVersion(name, ver, file); + conc_name_and_version(name, ver, file); if (get_old(dir, VA.files, file, name) == 0) return (NIL); } @@ -2524,6 +2523,94 @@ int true_name(char *path) return (type); } +/* + * Name: conc_dir_and_name + * + * Argument: char *dir The name of the directory. + * char *name The name of a file. + * char *fname The place where the full file name should be + * stored. + * Value: N/A + * + * Side Effect: fname is replaced with the full file name. + * + * Description: + * + * Concatenate the directory name and root file name. Checks if dir contains + * the trail directory delimiter or not. + * + */ + +void conc_dir_and_name(char *dir, char *name, char *fname) +{ + char *lf_cp1, *lf_cp2; + + lf_cp1 = dir; + lf_cp2 = dir; + + while (*lf_cp2 != '\0') { + switch (*lf_cp2) { + + case '/': + lf_cp1 = lf_cp2; + lf_cp2++; + break; + + default: + lf_cp2++; + break; + } + } + if (lf_cp1 == (lf_cp2 - 1)) { + if (lf_cp1 == (dir)) { + /* dir is a root directory. */ + strcpy(fname, "/"); + strcat(fname, name); + } else { + /* The trail directory is included. */ + strcpy(fname, dir); + strcat(fname, name); + } + } else { + /* The trail directory is not included */ + strcpy(fname, dir); + strcat(fname, "/"); + strcat(fname, name); + } +} + +/* + * Name: conc_name_and_version + * + * Argument: char *name The root file name. + * char *ver The file version. + * char *rname The place where the concatenated file name will be + * stored. + * Value: N/A + * + * Side Effect: rname is replaced with the concatenated file name. + * + * Description: + * + * Concatenate the root file name and its version in UNIX format. + * + * XXX: this code is unsafe and could result in memory smashes if the + * sizes of the arguments are not correctly specified + * + */ + +void conc_name_and_version(char *name, char *ver, char *rname) +{ + if (*ver != '\0') { + strcpy(rname, name); + strcat(rname, ".~"); + strcat(rname, ver); + strcat(rname, "~"); + } else { + strcpy(rname, name); + } +} + /* * Name: locate_file * @@ -3196,7 +3283,7 @@ static int maintain_version(char *file, int forcep) */ #ifndef DOS get_versionless(VA.files, vless, dir); - ConcNameAndVersion(vless, "1", fname); + conc_name_and_version(vless, "1", fname); TIMEOUT(rval = link(vless, fname)); if (rval == -1) { *Lisp_errno = errno; @@ -3219,7 +3306,7 @@ static int maintain_version(char *file, int forcep) * to the existing highest versioned file. */ FindHighestVersion(VA.files, entry, max_no); - ConcDirAndName(dir, entry->name, old_file); + conc_dir_and_name(dir, entry->name, old_file); /* * The versionless file should have the same case name as the old * file. @@ -3227,7 +3314,7 @@ static int maintain_version(char *file, int forcep) #ifndef DOS strcpy(fname, entry->name); separate_version(fname, ver, 1); - ConcDirAndName(dir, fname, vless); + conc_dir_and_name(dir, fname, vless); TIMEOUT(rval = link(old_file, vless)); if (rval == -1) { *Lisp_errno = errno; @@ -3252,7 +3339,7 @@ static int maintain_version(char *file, int forcep) * file. */ #ifndef DOS - ConcNameAndVersion(vless, ver, old_file); + conc_name_and_version(vless, ver, old_file); TIMEOUT(rval = link(vless, old_file)); if (rval == -1) { *Lisp_errno = errno; @@ -3281,7 +3368,7 @@ static int maintain_version(char *file, int forcep) return (0); } FindHighestVersion(VA.files, entry, max_no); - ConcDirAndName(dir, entry->name, old_file); + conc_dir_and_name(dir, entry->name, old_file); /* * The versionless file should have the same case name as the old * file. @@ -3289,7 +3376,7 @@ static int maintain_version(char *file, int forcep) #ifndef DOS strcpy(fname, entry->name); separate_version(fname, ver, 1); - ConcDirAndName(dir, fname, vless); + conc_dir_and_name(dir, fname, vless); TIMEOUT(rval = link(old_file, vless)); if (rval == -1) { *Lisp_errno = errno; @@ -3332,7 +3419,7 @@ static int get_versionless(FileName *varray, char *file, char *dir) while (varray->version_no != LASTVERSIONARRAY) { if (varray->version_no == 0) { - ConcDirAndName(dir, varray->name, file); + conc_dir_and_name(dir, varray->name, file); return (1); } else varray++; @@ -3411,7 +3498,7 @@ static int check_vless_link(char *vless, FileName *varray, char *to_file, int *h max_entry = varray; } if (!found && varray->version_no != 0) { - ConcDirAndName(dir, varray->name, name); + conc_dir_and_name(dir, varray->name, name); TIMEOUT(rval = stat(name, &sbuf)); if (rval != 0) { *Lisp_errno = errno; @@ -3503,7 +3590,7 @@ static int get_old(char *dir, FileName *varray, char *afile, char *vfile) * is an old file. */ FindHighestVersion(varray, entry, max_no); - ConcDirAndName(dir, entry->name, afile); + conc_dir_and_name(dir, entry->name, afile); strcpy(vfile, afile); return (1); } else { @@ -3515,7 +3602,7 @@ static int get_old(char *dir, FileName *varray, char *afile, char *vfile) ver_no = strtoul(ver, (char **)NULL, 10); FindSpecifiedVersion(varray, entry, ver_no); if (entry != NULL) { - ConcDirAndName(dir, entry->name, afile); + conc_dir_and_name(dir, entry->name, afile); strcpy(vfile, afile); return (1); } else @@ -3532,7 +3619,7 @@ static int get_old(char *dir, FileName *varray, char *afile, char *vfile) * No version is specified. The versionless file is dealt * with as version 1. */ - ConcNameAndVersion(vless, "1", vfile); + conc_name_and_version(vless, "1", vfile); strcpy(afile, vless); return (1); } else { @@ -3542,8 +3629,8 @@ static int get_old(char *dir, FileName *varray, char *afile, char *vfile) * Version 1 is specified. The versionless file is * dealt with as a version 1 file. */ - ConcNameAndVersion(name, "1", afile); - ConcDirAndName(dir, afile, vfile); + conc_name_and_version(name, "1", afile); + conc_dir_and_name(dir, afile, vfile); strcpy(afile, vless); return (1); } else { @@ -3571,7 +3658,7 @@ static int get_old(char *dir, FileName *varray, char *afile, char *vfile) */ FindHighestVersion(varray, entry, max_no); sprintf(vbuf, "%u", max_no + 1); - ConcNameAndVersion(vless, vbuf, vfile); + conc_name_and_version(vless, vbuf, vfile); strcpy(afile, vless); return (1); } else { @@ -3586,7 +3673,7 @@ static int get_old(char *dir, FileName *varray, char *afile, char *vfile) * missing versionless file. */ sprintf(vbuf, "%u", ver_no); - ConcNameAndVersion(vless, vbuf, vfile); + conc_name_and_version(vless, vbuf, vfile); strcpy(afile, vless); return (1); } else { @@ -3596,7 +3683,7 @@ static int get_old(char *dir, FileName *varray, char *afile, char *vfile) */ FindSpecifiedVersion(varray, entry, ver_no); if (entry != NULL) { - ConcDirAndName(dir, entry->name, afile); + conc_dir_and_name(dir, entry->name, afile); strcpy(vfile, afile); return (1); } else @@ -3615,7 +3702,7 @@ static int get_old(char *dir, FileName *varray, char *afile, char *vfile) * in varray is an old file. */ FindHighestVersion(varray, entry, max_no); - ConcDirAndName(dir, entry->name, afile); + conc_dir_and_name(dir, entry->name, afile); strcpy(vfile, afile); return (1); } else { @@ -3627,7 +3714,7 @@ static int get_old(char *dir, FileName *varray, char *afile, char *vfile) ver_no = strtoul(ver, (char **)NULL, 10); FindSpecifiedVersion(varray, entry, ver_no); if (entry != NULL) { - ConcDirAndName(dir, entry->name, afile); + conc_dir_and_name(dir, entry->name, afile); strcpy(vfile, afile); return (1); } else @@ -3702,7 +3789,7 @@ static int get_oldest(char *dir, FileName *varray, char *afile, char *vfile) * is an oldest file. */ FindLowestVersion(varray, entry, min_no); - ConcDirAndName(dir, entry->name, afile); + conc_dir_and_name(dir, entry->name, afile); strcpy(vfile, afile); return (1); } else { @@ -3714,7 +3801,7 @@ static int get_oldest(char *dir, FileName *varray, char *afile, char *vfile) ver_no = strtoul(ver, (char **)NULL, 10); FindSpecifiedVersion(varray, entry, ver_no); if (entry != NULL) { - ConcDirAndName(dir, entry->name, afile); + conc_dir_and_name(dir, entry->name, afile); strcpy(vfile, afile); return (1); } else @@ -3731,7 +3818,7 @@ static int get_oldest(char *dir, FileName *varray, char *afile, char *vfile) * No version is specified. The versionless file is dealt * with as version 1. */ - ConcNameAndVersion(vless, "1", vfile); + conc_name_and_version(vless, "1", vfile); strcpy(afile, vless); return (1); } else { @@ -3741,8 +3828,8 @@ static int get_oldest(char *dir, FileName *varray, char *afile, char *vfile) * Version 1 is specified. The versionless file is * dealt with as a version 1 file. */ - ConcNameAndVersion(name, "1", afile); - ConcDirAndName(dir, afile, vfile); + conc_name_and_version(name, "1", afile); + conc_dir_and_name(dir, afile, vfile); strcpy(afile, vless); return (1); } else { @@ -3767,7 +3854,7 @@ static int get_oldest(char *dir, FileName *varray, char *afile, char *vfile) * dealt with as the oldest version. */ FindLowestVersion(varray, entry, min_no); - ConcDirAndName(dir, entry->name, afile); + conc_dir_and_name(dir, entry->name, afile); strcpy(vfile, afile); return (1); } else { @@ -3782,7 +3869,7 @@ static int get_oldest(char *dir, FileName *varray, char *afile, char *vfile) * missing versionless file. */ sprintf(vbuf, "%u", ver_no); - ConcNameAndVersion(vless, vbuf, vfile); + conc_name_and_version(vless, vbuf, vfile); strcpy(afile, vless); return (1); } else { @@ -3792,7 +3879,7 @@ static int get_oldest(char *dir, FileName *varray, char *afile, char *vfile) */ FindSpecifiedVersion(varray, entry, ver_no); if (entry != NULL) { - ConcDirAndName(dir, entry->name, afile); + conc_dir_and_name(dir, entry->name, afile); strcpy(vfile, afile); return (1); } else @@ -3811,7 +3898,7 @@ static int get_oldest(char *dir, FileName *varray, char *afile, char *vfile) * in varray is an old file. */ FindLowestVersion(varray, entry, min_no); - ConcDirAndName(dir, entry->name, afile); + conc_dir_and_name(dir, entry->name, afile); strcpy(vfile, afile); return (1); } else { @@ -3823,7 +3910,7 @@ static int get_oldest(char *dir, FileName *varray, char *afile, char *vfile) ver_no = strtoul(ver, (char **)NULL, 10); FindSpecifiedVersion(varray, entry, ver_no); if (entry != NULL) { - ConcDirAndName(dir, entry->name, afile); + conc_dir_and_name(dir, entry->name, afile); strcpy(vfile, afile); return (1); } else @@ -3898,9 +3985,9 @@ static int get_new(char *dir, FileName *varray, char *afile, char *vfile) * If version is not specified or 1 is specified, * we can return versionless file as afile. */ - ConcNameAndVersion(name, "1", afile); - ConcDirAndName(dir, afile, vfile); - ConcDirAndName(dir, name, afile); + conc_name_and_version(name, "1", afile); + conc_dir_and_name(dir, afile, vfile); + conc_dir_and_name(dir, name, afile); return (1); } #ifndef DOS @@ -3909,7 +3996,7 @@ static int get_new(char *dir, FileName *varray, char *afile, char *vfile) * A version other than 1 is specified. "New" file * is recognized as if. */ - ConcDirAndName(dir, afile, vfile); + conc_dir_and_name(dir, afile, vfile); strcpy(afile, vfile); return (1); } @@ -3934,8 +4021,8 @@ static int get_new(char *dir, FileName *varray, char *afile, char *vfile) */ strcpy(name, entry->name); separate_version(name, ver, 1); - ConcDirAndName(dir, name, afile); - ConcNameAndVersion(afile, vbuf, vfile); + conc_dir_and_name(dir, name, afile); + conc_name_and_version(afile, vbuf, vfile); strcpy(afile, vfile); return (1); } else { @@ -3947,7 +4034,7 @@ static int get_new(char *dir, FileName *varray, char *afile, char *vfile) ver_no = strtoul(ver, (char **)NULL, 10); FindSpecifiedVersion(varray, entry, ver_no); if (entry != NULL) { - ConcDirAndName(dir, entry->name, afile); + conc_dir_and_name(dir, entry->name, afile); strcpy(vfile, afile); return (1); } @@ -3962,8 +4049,8 @@ static int get_new(char *dir, FileName *varray, char *afile, char *vfile) * files has the name in same case. */ while (varray->version_no != LASTVERSIONARRAY) varray++; - ConcNameAndVersion(varray->name, ver, afile); - ConcDirAndName(dir, afile, vfile); + conc_name_and_version(varray->name, ver, afile); + conc_dir_and_name(dir, afile, vfile); strcpy(afile, vfile); return (1); } @@ -3978,7 +4065,7 @@ static int get_new(char *dir, FileName *varray, char *afile, char *vfile) * No version is specified. The versionless file is dealt * with as version 1. Thus new version is 2. */ - ConcNameAndVersion(vless, "2", vfile); + conc_name_and_version(vless, "2", vfile); strcpy(afile, vfile); return (1); } else { @@ -3988,15 +4075,15 @@ static int get_new(char *dir, FileName *varray, char *afile, char *vfile) * Version 1 is specified. The versionless file is * dealt with as a version 1 file. */ - ConcNameAndVersion(name, "1", afile); - ConcDirAndName(dir, afile, vfile); + conc_name_and_version(name, "1", afile); + conc_dir_and_name(dir, afile, vfile); strcpy(afile, vless); return (1); } else { /* * Other versions than 1 are recognized as if. */ - ConcDirAndName(dir, afile, vfile); + conc_dir_and_name(dir, afile, vfile); strcpy(afile, vfile); return (1); } @@ -4019,7 +4106,7 @@ static int get_new(char *dir, FileName *varray, char *afile, char *vfile) */ FindHighestVersion(varray, entry, max_no); sprintf(vbuf, "%u", max_no + 2); - ConcNameAndVersion(vless, vbuf, vfile); + conc_name_and_version(vless, vbuf, vfile); strcpy(afile, vfile); return (1); } else { @@ -4034,7 +4121,7 @@ static int get_new(char *dir, FileName *varray, char *afile, char *vfile) * missing versionless file. */ sprintf(vbuf, "%u", ver_no); - ConcNameAndVersion(vless, vbuf, vfile); + conc_name_and_version(vless, vbuf, vfile); strcpy(afile, vless); return (1); } else { @@ -4044,7 +4131,7 @@ static int get_new(char *dir, FileName *varray, char *afile, char *vfile) */ FindSpecifiedVersion(varray, entry, ver_no); if (entry != NULL) { - ConcDirAndName(dir, entry->name, afile); + conc_dir_and_name(dir, entry->name, afile); strcpy(vfile, afile); return (1); } @@ -4062,8 +4149,8 @@ static int get_new(char *dir, FileName *varray, char *afile, char *vfile) * case. */ while (varray->version_no != LASTVERSIONARRAY) varray++; - ConcNameAndVersion(varray->name, ver, afile); - ConcDirAndName(dir, afile, vfile); + conc_name_and_version(varray->name, ver, afile); + conc_dir_and_name(dir, afile, vfile); strcpy(afile, vfile); return (1); } @@ -4088,8 +4175,8 @@ static int get_new(char *dir, FileName *varray, char *afile, char *vfile) */ strcpy(vless, entry->name); separate_version(vless, ver, 1); - ConcDirAndName(dir, vless, afile); - ConcNameAndVersion(afile, vbuf, vfile); + conc_dir_and_name(dir, vless, afile); + conc_name_and_version(afile, vbuf, vfile); strcpy(afile, vfile); return (1); } else { @@ -4101,7 +4188,7 @@ static int get_new(char *dir, FileName *varray, char *afile, char *vfile) ver_no = strtoul(ver, (char **)NULL, 10); FindSpecifiedVersion(varray, entry, ver_no); if (entry != NULL) { - ConcDirAndName(dir, entry->name, afile); + conc_dir_and_name(dir, entry->name, afile); strcpy(vfile, afile); return (1); } @@ -4117,8 +4204,8 @@ static int get_new(char *dir, FileName *varray, char *afile, char *vfile) FindHighestVersion(varray, entry, max_no); strcpy(vless, entry->name); separate_version(vless, vbuf, 1); - ConcDirAndName(dir, vless, afile); - ConcNameAndVersion(afile, ver, vfile); + conc_dir_and_name(dir, vless, afile); + conc_name_and_version(afile, ver, vfile); strcpy(afile, vfile); return (1); } @@ -4189,16 +4276,16 @@ static int get_old_new(char *dir, FileName *varray, char *afile, char *vfile) * If version is not specified or 1 is specified, * we can return versionless file as afile. */ - ConcNameAndVersion(name, "1", afile); - ConcDirAndName(dir, afile, vfile); - ConcDirAndName(dir, name, afile); + conc_name_and_version(name, "1", afile); + conc_dir_and_name(dir, afile, vfile); + conc_dir_and_name(dir, name, afile); return (1); } else { /* * A version other than 1 is specified. "New" file * is recognized as if. */ - ConcDirAndName(dir, afile, vfile); + conc_dir_and_name(dir, afile, vfile); strcpy(afile, vfile); return (1); } @@ -4215,7 +4302,7 @@ static int get_old_new(char *dir, FileName *varray, char *afile, char *vfile) * is an old file. */ FindHighestVersion(varray, entry, max_no); - ConcDirAndName(dir, entry->name, afile); + conc_dir_and_name(dir, entry->name, afile); strcpy(vfile, afile); return (1); } else { @@ -4227,7 +4314,7 @@ static int get_old_new(char *dir, FileName *varray, char *afile, char *vfile) ver_no = strtoul(ver, (char **)NULL, 10); FindSpecifiedVersion(varray, entry, ver_no); if (entry != NULL) { - ConcDirAndName(dir, entry->name, afile); + conc_dir_and_name(dir, entry->name, afile); strcpy(vfile, afile); return (1); } @@ -4242,8 +4329,8 @@ static int get_old_new(char *dir, FileName *varray, char *afile, char *vfile) * files has the name in same case. */ while (varray->version_no != LASTVERSIONARRAY) varray++; - ConcNameAndVersion(varray->name, ver, afile); - ConcDirAndName(dir, afile, vfile); + conc_name_and_version(varray->name, ver, afile); + conc_dir_and_name(dir, afile, vfile); strcpy(afile, vfile); return (1); } @@ -4258,7 +4345,7 @@ static int get_old_new(char *dir, FileName *varray, char *afile, char *vfile) * No version is specified. The versionless file is dealt * with as version 1. */ - ConcNameAndVersion(vless, "1", vfile); + conc_name_and_version(vless, "1", vfile); strcpy(afile, vless); return (1); } else { @@ -4268,15 +4355,15 @@ static int get_old_new(char *dir, FileName *varray, char *afile, char *vfile) * Version 1 is specified. The versionless file is * dealt with as a version 1 file. */ - ConcNameAndVersion(name, "1", afile); - ConcDirAndName(dir, afile, vfile); + conc_name_and_version(name, "1", afile); + conc_dir_and_name(dir, afile, vfile); strcpy(afile, vless); return (1); } else { /* * Other versions than 1 are recognized as if. */ - ConcDirAndName(dir, afile, vfile); + conc_dir_and_name(dir, afile, vfile); strcpy(afile, vfile); return (1); } @@ -4298,7 +4385,7 @@ static int get_old_new(char *dir, FileName *varray, char *afile, char *vfile) */ FindHighestVersion(varray, entry, max_no); sprintf(vbuf, "%u", max_no + 1); - ConcNameAndVersion(vless, vbuf, vfile); + conc_name_and_version(vless, vbuf, vfile); strcpy(afile, vless); return (1); } else { @@ -4313,7 +4400,7 @@ static int get_old_new(char *dir, FileName *varray, char *afile, char *vfile) * missing versionless file. */ sprintf(vbuf, "%u", ver_no); - ConcNameAndVersion(vless, vbuf, vfile); + conc_name_and_version(vless, vbuf, vfile); strcpy(afile, vless); return (1); } else { @@ -4323,7 +4410,7 @@ static int get_old_new(char *dir, FileName *varray, char *afile, char *vfile) */ FindSpecifiedVersion(varray, entry, ver_no); if (entry != NULL) { - ConcDirAndName(dir, entry->name, afile); + conc_dir_and_name(dir, entry->name, afile); strcpy(vfile, afile); return (1); } @@ -4341,8 +4428,8 @@ static int get_old_new(char *dir, FileName *varray, char *afile, char *vfile) * case. */ while (varray->version_no != LASTVERSIONARRAY) varray++; - ConcNameAndVersion(varray->name, ver, afile); - ConcDirAndName(dir, afile, vfile); + conc_name_and_version(varray->name, ver, afile); + conc_dir_and_name(dir, afile, vfile); strcpy(afile, vfile); return (1); } @@ -4359,7 +4446,7 @@ static int get_old_new(char *dir, FileName *varray, char *afile, char *vfile) * in varray is an old file. */ FindHighestVersion(varray, entry, max_no); - ConcDirAndName(dir, entry->name, afile); + conc_dir_and_name(dir, entry->name, afile); strcpy(vfile, afile); return (1); } else { @@ -4371,7 +4458,7 @@ static int get_old_new(char *dir, FileName *varray, char *afile, char *vfile) ver_no = strtoul(ver, (char **)NULL, 10); FindSpecifiedVersion(varray, entry, ver_no); if (entry != NULL) { - ConcDirAndName(dir, entry->name, afile); + conc_dir_and_name(dir, entry->name, afile); strcpy(vfile, afile); return (1); } @@ -4387,8 +4474,8 @@ static int get_old_new(char *dir, FileName *varray, char *afile, char *vfile) FindHighestVersion(varray, entry, max_no); strcpy(vless, entry->name); separate_version(vless, vbuf, 1); - ConcDirAndName(dir, vless, afile); - ConcNameAndVersion(afile, ver, vfile); + conc_dir_and_name(dir, vless, afile); + conc_name_and_version(afile, ver, vfile); strcpy(afile, vfile); return (1); } diff --git a/src/ufs.c b/src/ufs.c index b5173cd4..f3083822 100644 --- a/src/ufs.c +++ b/src/ufs.c @@ -829,7 +829,7 @@ int unixpathname(char *src, char *dst, int versionp, int genp) else *ver2 = '\0'; #endif /* DOS */ - ConcNameAndVersion(fbuf2, ver2, dst); + conc_name_and_version(fbuf2, ver2, dst); } return (1); } @@ -1087,7 +1087,7 @@ int lisppathname(char *fullname, char *lispname, int dirp, int versionp) *cp = '\0'; } if (versionp && *ver != '\0') { - ConcNameAndVersion(fbuf, ver, namebuf); + conc_name_and_version(fbuf, ver, namebuf); } else { strcpy(namebuf, fbuf); } @@ -1186,7 +1186,7 @@ int quote_fname(char *file) *cp = '\0'; } if (*ver != '\0') { - ConcNameAndVersion(fbuf, ver, namebuf); + conc_name_and_version(fbuf, ver, namebuf); } else { strcpy(namebuf, fbuf); } From d4843681f67d8722e531d9c612c102db99e0f5a6 Mon Sep 17 00:00:00 2001 From: Nick Briggs Date: Tue, 25 Feb 2025 09:36:43 -0800 Subject: [PATCH 2/4] Adds destination size to conc_... functions and switch to strlcpy/strlcat --- inc/dskdefs.h | 4 +- src/dsk.c | 193 +++++++++++++++++++++++++------------------------- src/ufs.c | 6 +- 3 files changed, 102 insertions(+), 101 deletions(-) diff --git a/inc/dskdefs.h b/inc/dskdefs.h index 3fd2e792..6e6ed25b 100644 --- a/inc/dskdefs.h +++ b/inc/dskdefs.h @@ -19,8 +19,8 @@ LispPTR COM_writepage(LispPTR *args); LispPTR COM_truncatefile(LispPTR *args); LispPTR COM_changedir(LispPTR *args); LispPTR COM_getfreeblock(LispPTR *args); -void conc_dir_and_name(char *dir, char *name, char *fname); -void conc_name_and_version(char *name, char *ver, char *rname); +void conc_dir_and_name(char *dir, char *name, char *fname, size_t fname_size); +void conc_name_and_version(char *name, char *ver, char *rname, size_t rname_size); void separate_version(char *name, char *ver, int checkp); int unpack_filename(char *file, char *dir, char *name, char *ver, int checkp); int true_name(char *path); diff --git a/src/dsk.c b/src/dsk.c index cb27760e..5ba3518a 100644 --- a/src/dsk.c +++ b/src/dsk.c @@ -375,7 +375,7 @@ LispPTR COM_openfile(LispPTR *args) if (unpack_filename(file, dir, name, ver, 1) == 0) return (NIL); if (true_name(dir) != -1) return (0); if (get_version_array(dir, name) == 0) return (NIL); - conc_name_and_version(name, ver, file); + conc_name_and_version(name, ver, file, sizeof(file)); switch (args[1]) { case RECOG_OLD: @@ -887,7 +887,7 @@ LispPTR DSK_getfilename(LispPTR *args) */ if (get_version_array(dir, name) == 0) return (NIL); - conc_name_and_version(name, ver, aname); + conc_name_and_version(name, ver, aname, sizeof(aname)); if (get_old(dir, VA.files, aname, vname) == 0) return (NIL); if ((rval = true_name(aname)) == 0) return (NIL); @@ -927,7 +927,7 @@ LispPTR DSK_getfilename(LispPTR *args) } else { if (get_version_array(dir, name) == 0) return (NIL); - conc_name_and_version(name, ver, aname); + conc_name_and_version(name, ver, aname, sizeof(aname)); if (get_oldest(dir, VA.files, aname, vname) == 0) return (NIL); if ((rval = true_name(aname)) == 0) return (NIL); @@ -965,7 +965,7 @@ LispPTR DSK_getfilename(LispPTR *args) strcpy(vname, dir); dirp = 1; } else { - conc_dir_and_name(dir, name, aname); + conc_dir_and_name(dir, name, aname, sizeof(aname)); if ((rval = true_name(aname)) == -1) { strcpy(vname, aname); dirp = 1; @@ -976,7 +976,7 @@ LispPTR DSK_getfilename(LispPTR *args) */ if (get_version_array(dir, name) == 0) return (NIL); - conc_name_and_version(name, ver, aname); + conc_name_and_version(name, ver, aname, sizeof(aname)); if (get_new(dir, VA.files, aname, vname) == 0) return (NIL); dirp = 0; } @@ -995,14 +995,14 @@ LispPTR DSK_getfilename(LispPTR *args) strcpy(vname, file); dirp = 0; } else { - conc_dir_and_name(dir, name, aname); + conc_dir_and_name(dir, name, aname, sizeof(aname)); if ((rval = true_name(aname)) == -1) { strcpy(vname, aname); dirp = 1; } else { if (get_version_array(dir, name) == 0) return (NIL); - conc_name_and_version(name, ver, aname); + conc_name_and_version(name, ver, aname, sizeof(aname)); if (get_old_new(dir, VA.files, aname, vname) == 0) return (NIL); dirp = 0; } @@ -1018,7 +1018,7 @@ LispPTR DSK_getfilename(LispPTR *args) * directories. The file name itself is recognized as if. */ if (true_name(dir) != -1) return (NIL); - conc_dir_and_name(dir, name, vname); + conc_dir_and_name(dir, name, vname, sizeof(vname)); strcpy(aname, vname); if (true_name(aname) == -1) { strcpy(vname, aname); @@ -1056,8 +1056,8 @@ LispPTR DSK_getfilename(LispPTR *args) { char dver[VERSIONLEN]; separate_version(vname, dver, 0); - conc_dir_and_name(dir, name, aname); - conc_name_and_version(aname, dver, vname); + conc_dir_and_name(dir, name, aname, sizeof(aname)); + conc_name_and_version(aname, dver, vname, sizeof(vname)); } #endif /* DOS */ @@ -1142,7 +1142,7 @@ LispPTR DSK_deletefile(LispPTR *args) * of it. */ - conc_name_and_version(fbuf, ver, file); + conc_name_and_version(fbuf, ver, file, sizeof(file)); if (get_oldest(dir, VA.files, file, fbuf) == 0) return (NIL); if (get_versionless(VA.files, vless, dir) == 0) { @@ -1294,7 +1294,7 @@ LispPTR DSK_renamefile(LispPTR *args) /* * We maintain the destination to handle the link damaged case correctly. */ - conc_dir_and_name(dir, fbuf, dst); + conc_dir_and_name(dir, fbuf, dst, sizeof(dst)); if (maintain_version(dst, 0) == 0) return (NIL); if (get_version_array(dir, fbuf) == 0) return (NIL); @@ -1305,7 +1305,7 @@ LispPTR DSK_renamefile(LispPTR *args) * of it. */ - conc_name_and_version(fbuf, ver, dst); + conc_name_and_version(fbuf, ver, dst, sizeof(dst)); if (get_new(dir, VA.files, dst, fbuf) == 0) return (NIL); /* @@ -1320,7 +1320,7 @@ LispPTR DSK_renamefile(LispPTR *args) if (OnlyVersionlessP(VA.files)) { get_versionless(VA.files, vless, dir); if (strcmp(dst, vless) != 0) { - conc_name_and_version(vless, "1", fbuf); + conc_name_and_version(vless, "1", fbuf, sizeof(fbuf)); TIMEOUT(rval = rename(vless, fbuf)); if (rval == -1) { *Lisp_errno = errno; @@ -1360,7 +1360,7 @@ LispPTR DSK_renamefile(LispPTR *args) * code, we have to recognize it again to know the "real" accessible name * of it. */ - conc_name_and_version(fbuf, ver, src); + conc_name_and_version(fbuf, ver, src, sizeof(src)); if (get_old(dir, VA.files, src, fbuf) == 0) return (NIL); if (get_versionless(VA.files, vless, dir) == 0) { @@ -1622,7 +1622,7 @@ LispPTR COM_getfileinfo(LispPTR *args) strcpy(file, dir); } else { if (get_version_array(dir, name) == 0) return (NIL); - conc_name_and_version(name, ver, file); + conc_name_and_version(name, ver, file, sizeof(file)); if (get_old(dir, VA.files, file, name) == 0) return (NIL); } } @@ -1811,7 +1811,7 @@ LispPTR COM_setfileinfo(LispPTR *args) if (unpack_filename(file, dir, name, ver, 1) == 0) return (NIL); if (true_name(dir) != -1) return (0); if (get_version_array(dir, name) == 0) return (NIL); - conc_name_and_version(name, ver, file); + conc_name_and_version(name, ver, file, sizeof(file)); if (get_old(dir, VA.files, file, name) == 0) return (NIL); } @@ -2541,7 +2541,7 @@ int true_name(char *path) * */ -void conc_dir_and_name(char *dir, char *name, char *fname) +void conc_dir_and_name(char *dir, char *name, char *fname, size_t fname_size) { char *lf_cp1, *lf_cp2; @@ -2586,6 +2586,7 @@ void conc_dir_and_name(char *dir, char *name, char *fname) * char *ver The file version. * char *rname The place where the concatenated file name will be * stored. + * size_t rname_size The size of the storage allocated for rname * Value: N/A * * Side Effect: rname is replaced with the concatenated file name. @@ -2599,15 +2600,15 @@ void conc_dir_and_name(char *dir, char *name, char *fname) * */ -void conc_name_and_version(char *name, char *ver, char *rname) +void conc_name_and_version(char *name, char *ver, char *rname, size_t rname_size) { if (*ver != '\0') { - strcpy(rname, name); - strcat(rname, ".~"); - strcat(rname, ver); - strcat(rname, "~"); + strlcpy(rname, name, rname_size); + strlcat(rname, ".~", rname_size); + strlcat(rname, ver, rname_size); + strlcat(rname, "~", rname_size); } else { - strcpy(rname, name); + strlcpy(rname, name, rname_size); } } @@ -3283,7 +3284,7 @@ static int maintain_version(char *file, int forcep) */ #ifndef DOS get_versionless(VA.files, vless, dir); - conc_name_and_version(vless, "1", fname); + conc_name_and_version(vless, "1", fname, sizeof(fname)); TIMEOUT(rval = link(vless, fname)); if (rval == -1) { *Lisp_errno = errno; @@ -3306,7 +3307,7 @@ static int maintain_version(char *file, int forcep) * to the existing highest versioned file. */ FindHighestVersion(VA.files, entry, max_no); - conc_dir_and_name(dir, entry->name, old_file); + conc_dir_and_name(dir, entry->name, old_file, sizeof(old_file)); /* * The versionless file should have the same case name as the old * file. @@ -3314,7 +3315,7 @@ static int maintain_version(char *file, int forcep) #ifndef DOS strcpy(fname, entry->name); separate_version(fname, ver, 1); - conc_dir_and_name(dir, fname, vless); + conc_dir_and_name(dir, fname, vless, sizeof(vless)); TIMEOUT(rval = link(old_file, vless)); if (rval == -1) { *Lisp_errno = errno; @@ -3339,7 +3340,7 @@ static int maintain_version(char *file, int forcep) * file. */ #ifndef DOS - conc_name_and_version(vless, ver, old_file); + conc_name_and_version(vless, ver, old_file, sizeof(old_file)); TIMEOUT(rval = link(vless, old_file)); if (rval == -1) { *Lisp_errno = errno; @@ -3368,7 +3369,7 @@ static int maintain_version(char *file, int forcep) return (0); } FindHighestVersion(VA.files, entry, max_no); - conc_dir_and_name(dir, entry->name, old_file); + conc_dir_and_name(dir, entry->name, old_file, sizeof(old_file)); /* * The versionless file should have the same case name as the old * file. @@ -3376,7 +3377,7 @@ static int maintain_version(char *file, int forcep) #ifndef DOS strcpy(fname, entry->name); separate_version(fname, ver, 1); - conc_dir_and_name(dir, fname, vless); + conc_dir_and_name(dir, fname, vless, sizeof(vless)); TIMEOUT(rval = link(old_file, vless)); if (rval == -1) { *Lisp_errno = errno; @@ -3419,7 +3420,7 @@ static int get_versionless(FileName *varray, char *file, char *dir) while (varray->version_no != LASTVERSIONARRAY) { if (varray->version_no == 0) { - conc_dir_and_name(dir, varray->name, file); + conc_dir_and_name(dir, varray->name, file, sizeof(file)); return (1); } else varray++; @@ -3498,7 +3499,7 @@ static int check_vless_link(char *vless, FileName *varray, char *to_file, int *h max_entry = varray; } if (!found && varray->version_no != 0) { - conc_dir_and_name(dir, varray->name, name); + conc_dir_and_name(dir, varray->name, name, sizeof(name)); TIMEOUT(rval = stat(name, &sbuf)); if (rval != 0) { *Lisp_errno = errno; @@ -3590,7 +3591,7 @@ static int get_old(char *dir, FileName *varray, char *afile, char *vfile) * is an old file. */ FindHighestVersion(varray, entry, max_no); - conc_dir_and_name(dir, entry->name, afile); + conc_dir_and_name(dir, entry->name, afile, sizeof(afile)); strcpy(vfile, afile); return (1); } else { @@ -3602,7 +3603,7 @@ static int get_old(char *dir, FileName *varray, char *afile, char *vfile) ver_no = strtoul(ver, (char **)NULL, 10); FindSpecifiedVersion(varray, entry, ver_no); if (entry != NULL) { - conc_dir_and_name(dir, entry->name, afile); + conc_dir_and_name(dir, entry->name, afile, sizeof(afile)); strcpy(vfile, afile); return (1); } else @@ -3619,7 +3620,7 @@ static int get_old(char *dir, FileName *varray, char *afile, char *vfile) * No version is specified. The versionless file is dealt * with as version 1. */ - conc_name_and_version(vless, "1", vfile); + conc_name_and_version(vless, "1", vfile, sizeof(vfile)); strcpy(afile, vless); return (1); } else { @@ -3629,8 +3630,8 @@ static int get_old(char *dir, FileName *varray, char *afile, char *vfile) * Version 1 is specified. The versionless file is * dealt with as a version 1 file. */ - conc_name_and_version(name, "1", afile); - conc_dir_and_name(dir, afile, vfile); + conc_name_and_version(name, "1", afile, sizeof(afile)); + conc_dir_and_name(dir, afile, vfile, sizeof(vfile)); strcpy(afile, vless); return (1); } else { @@ -3658,7 +3659,7 @@ static int get_old(char *dir, FileName *varray, char *afile, char *vfile) */ FindHighestVersion(varray, entry, max_no); sprintf(vbuf, "%u", max_no + 1); - conc_name_and_version(vless, vbuf, vfile); + conc_name_and_version(vless, vbuf, vfile, sizeof(vfile)); strcpy(afile, vless); return (1); } else { @@ -3673,7 +3674,7 @@ static int get_old(char *dir, FileName *varray, char *afile, char *vfile) * missing versionless file. */ sprintf(vbuf, "%u", ver_no); - conc_name_and_version(vless, vbuf, vfile); + conc_name_and_version(vless, vbuf, vfile, sizeof(vfile)); strcpy(afile, vless); return (1); } else { @@ -3683,7 +3684,7 @@ static int get_old(char *dir, FileName *varray, char *afile, char *vfile) */ FindSpecifiedVersion(varray, entry, ver_no); if (entry != NULL) { - conc_dir_and_name(dir, entry->name, afile); + conc_dir_and_name(dir, entry->name, afile, sizeof(afile)); strcpy(vfile, afile); return (1); } else @@ -3702,7 +3703,7 @@ static int get_old(char *dir, FileName *varray, char *afile, char *vfile) * in varray is an old file. */ FindHighestVersion(varray, entry, max_no); - conc_dir_and_name(dir, entry->name, afile); + conc_dir_and_name(dir, entry->name, afile, sizeof(afile)); strcpy(vfile, afile); return (1); } else { @@ -3714,7 +3715,7 @@ static int get_old(char *dir, FileName *varray, char *afile, char *vfile) ver_no = strtoul(ver, (char **)NULL, 10); FindSpecifiedVersion(varray, entry, ver_no); if (entry != NULL) { - conc_dir_and_name(dir, entry->name, afile); + conc_dir_and_name(dir, entry->name, afile, sizeof(afile)); strcpy(vfile, afile); return (1); } else @@ -3789,7 +3790,7 @@ static int get_oldest(char *dir, FileName *varray, char *afile, char *vfile) * is an oldest file. */ FindLowestVersion(varray, entry, min_no); - conc_dir_and_name(dir, entry->name, afile); + conc_dir_and_name(dir, entry->name, afile, sizeof(afile)); strcpy(vfile, afile); return (1); } else { @@ -3801,7 +3802,7 @@ static int get_oldest(char *dir, FileName *varray, char *afile, char *vfile) ver_no = strtoul(ver, (char **)NULL, 10); FindSpecifiedVersion(varray, entry, ver_no); if (entry != NULL) { - conc_dir_and_name(dir, entry->name, afile); + conc_dir_and_name(dir, entry->name, afile, sizeof(afile)); strcpy(vfile, afile); return (1); } else @@ -3818,7 +3819,7 @@ static int get_oldest(char *dir, FileName *varray, char *afile, char *vfile) * No version is specified. The versionless file is dealt * with as version 1. */ - conc_name_and_version(vless, "1", vfile); + conc_name_and_version(vless, "1", vfile, sizeof(vfile)); strcpy(afile, vless); return (1); } else { @@ -3828,8 +3829,8 @@ static int get_oldest(char *dir, FileName *varray, char *afile, char *vfile) * Version 1 is specified. The versionless file is * dealt with as a version 1 file. */ - conc_name_and_version(name, "1", afile); - conc_dir_and_name(dir, afile, vfile); + conc_name_and_version(name, "1", afile, sizeof(afile)); + conc_dir_and_name(dir, afile, vfile, sizeof(vfile)); strcpy(afile, vless); return (1); } else { @@ -3854,7 +3855,7 @@ static int get_oldest(char *dir, FileName *varray, char *afile, char *vfile) * dealt with as the oldest version. */ FindLowestVersion(varray, entry, min_no); - conc_dir_and_name(dir, entry->name, afile); + conc_dir_and_name(dir, entry->name, afile, sizeof(afile)); strcpy(vfile, afile); return (1); } else { @@ -3869,7 +3870,7 @@ static int get_oldest(char *dir, FileName *varray, char *afile, char *vfile) * missing versionless file. */ sprintf(vbuf, "%u", ver_no); - conc_name_and_version(vless, vbuf, vfile); + conc_name_and_version(vless, vbuf, vfile, sizeof(vfile)); strcpy(afile, vless); return (1); } else { @@ -3879,7 +3880,7 @@ static int get_oldest(char *dir, FileName *varray, char *afile, char *vfile) */ FindSpecifiedVersion(varray, entry, ver_no); if (entry != NULL) { - conc_dir_and_name(dir, entry->name, afile); + conc_dir_and_name(dir, entry->name, afile, sizeof(afile)); strcpy(vfile, afile); return (1); } else @@ -3898,7 +3899,7 @@ static int get_oldest(char *dir, FileName *varray, char *afile, char *vfile) * in varray is an old file. */ FindLowestVersion(varray, entry, min_no); - conc_dir_and_name(dir, entry->name, afile); + conc_dir_and_name(dir, entry->name, afile, sizeof(afile)); strcpy(vfile, afile); return (1); } else { @@ -3910,7 +3911,7 @@ static int get_oldest(char *dir, FileName *varray, char *afile, char *vfile) ver_no = strtoul(ver, (char **)NULL, 10); FindSpecifiedVersion(varray, entry, ver_no); if (entry != NULL) { - conc_dir_and_name(dir, entry->name, afile); + conc_dir_and_name(dir, entry->name, afile, sizeof(afile)); strcpy(vfile, afile); return (1); } else @@ -3985,9 +3986,9 @@ static int get_new(char *dir, FileName *varray, char *afile, char *vfile) * If version is not specified or 1 is specified, * we can return versionless file as afile. */ - conc_name_and_version(name, "1", afile); - conc_dir_and_name(dir, afile, vfile); - conc_dir_and_name(dir, name, afile); + conc_name_and_version(name, "1", afile, sizeof(afile)); + conc_dir_and_name(dir, afile, vfile, sizeof(vfile)); + conc_dir_and_name(dir, name, afile, sizeof(afile)); return (1); } #ifndef DOS @@ -3996,7 +3997,7 @@ static int get_new(char *dir, FileName *varray, char *afile, char *vfile) * A version other than 1 is specified. "New" file * is recognized as if. */ - conc_dir_and_name(dir, afile, vfile); + conc_dir_and_name(dir, afile, vfile, sizeof(vfile)); strcpy(afile, vfile); return (1); } @@ -4021,8 +4022,8 @@ static int get_new(char *dir, FileName *varray, char *afile, char *vfile) */ strcpy(name, entry->name); separate_version(name, ver, 1); - conc_dir_and_name(dir, name, afile); - conc_name_and_version(afile, vbuf, vfile); + conc_dir_and_name(dir, name, afile, sizeof(afile)); + conc_name_and_version(afile, vbuf, vfile, sizeof(vfile)); strcpy(afile, vfile); return (1); } else { @@ -4034,7 +4035,7 @@ static int get_new(char *dir, FileName *varray, char *afile, char *vfile) ver_no = strtoul(ver, (char **)NULL, 10); FindSpecifiedVersion(varray, entry, ver_no); if (entry != NULL) { - conc_dir_and_name(dir, entry->name, afile); + conc_dir_and_name(dir, entry->name, afile, sizeof(afile)); strcpy(vfile, afile); return (1); } @@ -4049,8 +4050,8 @@ static int get_new(char *dir, FileName *varray, char *afile, char *vfile) * files has the name in same case. */ while (varray->version_no != LASTVERSIONARRAY) varray++; - conc_name_and_version(varray->name, ver, afile); - conc_dir_and_name(dir, afile, vfile); + conc_name_and_version(varray->name, ver, afile, sizeof(afile)); + conc_dir_and_name(dir, afile, vfile, sizeof(vfile)); strcpy(afile, vfile); return (1); } @@ -4065,7 +4066,7 @@ static int get_new(char *dir, FileName *varray, char *afile, char *vfile) * No version is specified. The versionless file is dealt * with as version 1. Thus new version is 2. */ - conc_name_and_version(vless, "2", vfile); + conc_name_and_version(vless, "2", vfile, sizeof(vfile)); strcpy(afile, vfile); return (1); } else { @@ -4075,15 +4076,15 @@ static int get_new(char *dir, FileName *varray, char *afile, char *vfile) * Version 1 is specified. The versionless file is * dealt with as a version 1 file. */ - conc_name_and_version(name, "1", afile); - conc_dir_and_name(dir, afile, vfile); + conc_name_and_version(name, "1", afile, sizeof(afile)); + conc_dir_and_name(dir, afile, vfile, sizeof(vfile)); strcpy(afile, vless); return (1); } else { /* * Other versions than 1 are recognized as if. */ - conc_dir_and_name(dir, afile, vfile); + conc_dir_and_name(dir, afile, vfile, sizeof(vfile)); strcpy(afile, vfile); return (1); } @@ -4106,7 +4107,7 @@ static int get_new(char *dir, FileName *varray, char *afile, char *vfile) */ FindHighestVersion(varray, entry, max_no); sprintf(vbuf, "%u", max_no + 2); - conc_name_and_version(vless, vbuf, vfile); + conc_name_and_version(vless, vbuf, vfile, sizeof(vfile)); strcpy(afile, vfile); return (1); } else { @@ -4121,7 +4122,7 @@ static int get_new(char *dir, FileName *varray, char *afile, char *vfile) * missing versionless file. */ sprintf(vbuf, "%u", ver_no); - conc_name_and_version(vless, vbuf, vfile); + conc_name_and_version(vless, vbuf, vfile, sizeof(vfile)); strcpy(afile, vless); return (1); } else { @@ -4131,7 +4132,7 @@ static int get_new(char *dir, FileName *varray, char *afile, char *vfile) */ FindSpecifiedVersion(varray, entry, ver_no); if (entry != NULL) { - conc_dir_and_name(dir, entry->name, afile); + conc_dir_and_name(dir, entry->name, afile, sizeof(afile)); strcpy(vfile, afile); return (1); } @@ -4149,8 +4150,8 @@ static int get_new(char *dir, FileName *varray, char *afile, char *vfile) * case. */ while (varray->version_no != LASTVERSIONARRAY) varray++; - conc_name_and_version(varray->name, ver, afile); - conc_dir_and_name(dir, afile, vfile); + conc_name_and_version(varray->name, ver, afile, sizeof(afile)); + conc_dir_and_name(dir, afile, vfile, sizeof(vfile)); strcpy(afile, vfile); return (1); } @@ -4175,8 +4176,8 @@ static int get_new(char *dir, FileName *varray, char *afile, char *vfile) */ strcpy(vless, entry->name); separate_version(vless, ver, 1); - conc_dir_and_name(dir, vless, afile); - conc_name_and_version(afile, vbuf, vfile); + conc_dir_and_name(dir, vless, afile, sizeof(afile)); + conc_name_and_version(afile, vbuf, vfile, sizeof(vfile)); strcpy(afile, vfile); return (1); } else { @@ -4188,7 +4189,7 @@ static int get_new(char *dir, FileName *varray, char *afile, char *vfile) ver_no = strtoul(ver, (char **)NULL, 10); FindSpecifiedVersion(varray, entry, ver_no); if (entry != NULL) { - conc_dir_and_name(dir, entry->name, afile); + conc_dir_and_name(dir, entry->name, afile, sizeof(afile)); strcpy(vfile, afile); return (1); } @@ -4204,8 +4205,8 @@ static int get_new(char *dir, FileName *varray, char *afile, char *vfile) FindHighestVersion(varray, entry, max_no); strcpy(vless, entry->name); separate_version(vless, vbuf, 1); - conc_dir_and_name(dir, vless, afile); - conc_name_and_version(afile, ver, vfile); + conc_dir_and_name(dir, vless, afile, sizeof(afile)); + conc_name_and_version(afile, ver, vfile, sizeof(vfile)); strcpy(afile, vfile); return (1); } @@ -4276,16 +4277,16 @@ static int get_old_new(char *dir, FileName *varray, char *afile, char *vfile) * If version is not specified or 1 is specified, * we can return versionless file as afile. */ - conc_name_and_version(name, "1", afile); - conc_dir_and_name(dir, afile, vfile); - conc_dir_and_name(dir, name, afile); + conc_name_and_version(name, "1", afile, sizeof(afile)); + conc_dir_and_name(dir, afile, vfile, sizeof(vfile)); + conc_dir_and_name(dir, name, afile, sizeof(afile)); return (1); } else { /* * A version other than 1 is specified. "New" file * is recognized as if. */ - conc_dir_and_name(dir, afile, vfile); + conc_dir_and_name(dir, afile, vfile, sizeof(vfile)); strcpy(afile, vfile); return (1); } @@ -4302,7 +4303,7 @@ static int get_old_new(char *dir, FileName *varray, char *afile, char *vfile) * is an old file. */ FindHighestVersion(varray, entry, max_no); - conc_dir_and_name(dir, entry->name, afile); + conc_dir_and_name(dir, entry->name, afile, sizeof(afile)); strcpy(vfile, afile); return (1); } else { @@ -4314,7 +4315,7 @@ static int get_old_new(char *dir, FileName *varray, char *afile, char *vfile) ver_no = strtoul(ver, (char **)NULL, 10); FindSpecifiedVersion(varray, entry, ver_no); if (entry != NULL) { - conc_dir_and_name(dir, entry->name, afile); + conc_dir_and_name(dir, entry->name, afile, sizeof(afile)); strcpy(vfile, afile); return (1); } @@ -4329,8 +4330,8 @@ static int get_old_new(char *dir, FileName *varray, char *afile, char *vfile) * files has the name in same case. */ while (varray->version_no != LASTVERSIONARRAY) varray++; - conc_name_and_version(varray->name, ver, afile); - conc_dir_and_name(dir, afile, vfile); + conc_name_and_version(varray->name, ver, afile, sizeof(afile)); + conc_dir_and_name(dir, afile, vfile, sizeof(vfile)); strcpy(afile, vfile); return (1); } @@ -4345,7 +4346,7 @@ static int get_old_new(char *dir, FileName *varray, char *afile, char *vfile) * No version is specified. The versionless file is dealt * with as version 1. */ - conc_name_and_version(vless, "1", vfile); + conc_name_and_version(vless, "1", vfile, sizeof(vfile)); strcpy(afile, vless); return (1); } else { @@ -4355,15 +4356,15 @@ static int get_old_new(char *dir, FileName *varray, char *afile, char *vfile) * Version 1 is specified. The versionless file is * dealt with as a version 1 file. */ - conc_name_and_version(name, "1", afile); - conc_dir_and_name(dir, afile, vfile); + conc_name_and_version(name, "1", afile, sizeof(afile)); + conc_dir_and_name(dir, afile, vfile, sizeof(vfile)); strcpy(afile, vless); return (1); } else { /* * Other versions than 1 are recognized as if. */ - conc_dir_and_name(dir, afile, vfile); + conc_dir_and_name(dir, afile, vfile, sizeof(vfile)); strcpy(afile, vfile); return (1); } @@ -4385,7 +4386,7 @@ static int get_old_new(char *dir, FileName *varray, char *afile, char *vfile) */ FindHighestVersion(varray, entry, max_no); sprintf(vbuf, "%u", max_no + 1); - conc_name_and_version(vless, vbuf, vfile); + conc_name_and_version(vless, vbuf, vfile, sizeof(vfile)); strcpy(afile, vless); return (1); } else { @@ -4400,7 +4401,7 @@ static int get_old_new(char *dir, FileName *varray, char *afile, char *vfile) * missing versionless file. */ sprintf(vbuf, "%u", ver_no); - conc_name_and_version(vless, vbuf, vfile); + conc_name_and_version(vless, vbuf, vfile, sizeof(vfile)); strcpy(afile, vless); return (1); } else { @@ -4410,7 +4411,7 @@ static int get_old_new(char *dir, FileName *varray, char *afile, char *vfile) */ FindSpecifiedVersion(varray, entry, ver_no); if (entry != NULL) { - conc_dir_and_name(dir, entry->name, afile); + conc_dir_and_name(dir, entry->name, afile, sizeof(afile)); strcpy(vfile, afile); return (1); } @@ -4428,8 +4429,8 @@ static int get_old_new(char *dir, FileName *varray, char *afile, char *vfile) * case. */ while (varray->version_no != LASTVERSIONARRAY) varray++; - conc_name_and_version(varray->name, ver, afile); - conc_dir_and_name(dir, afile, vfile); + conc_name_and_version(varray->name, ver, afile, sizeof(afile)); + conc_dir_and_name(dir, afile, vfile, sizeof(vfile)); strcpy(afile, vfile); return (1); } @@ -4446,7 +4447,7 @@ static int get_old_new(char *dir, FileName *varray, char *afile, char *vfile) * in varray is an old file. */ FindHighestVersion(varray, entry, max_no); - conc_dir_and_name(dir, entry->name, afile); + conc_dir_and_name(dir, entry->name, afile, sizeof(afile)); strcpy(vfile, afile); return (1); } else { @@ -4458,7 +4459,7 @@ static int get_old_new(char *dir, FileName *varray, char *afile, char *vfile) ver_no = strtoul(ver, (char **)NULL, 10); FindSpecifiedVersion(varray, entry, ver_no); if (entry != NULL) { - conc_dir_and_name(dir, entry->name, afile); + conc_dir_and_name(dir, entry->name, afile, sizeof(afile)); strcpy(vfile, afile); return (1); } @@ -4474,8 +4475,8 @@ static int get_old_new(char *dir, FileName *varray, char *afile, char *vfile) FindHighestVersion(varray, entry, max_no); strcpy(vless, entry->name); separate_version(vless, vbuf, 1); - conc_dir_and_name(dir, vless, afile); - conc_name_and_version(afile, ver, vfile); + conc_dir_and_name(dir, vless, afile, sizeof(afile)); + conc_name_and_version(afile, ver, vfile, sizeof(vfile)); strcpy(afile, vfile); return (1); } diff --git a/src/ufs.c b/src/ufs.c index f3083822..e50f6e47 100644 --- a/src/ufs.c +++ b/src/ufs.c @@ -829,7 +829,7 @@ int unixpathname(char *src, char *dst, int versionp, int genp) else *ver2 = '\0'; #endif /* DOS */ - conc_name_and_version(fbuf2, ver2, dst); + conc_name_and_version(fbuf2, ver2, dst, MAXPATHLEN); } return (1); } @@ -1087,7 +1087,7 @@ int lisppathname(char *fullname, char *lispname, int dirp, int versionp) *cp = '\0'; } if (versionp && *ver != '\0') { - conc_name_and_version(fbuf, ver, namebuf); + conc_name_and_version(fbuf, ver, namebuf, MAXPATHLEN); } else { strcpy(namebuf, fbuf); } @@ -1186,7 +1186,7 @@ int quote_fname(char *file) *cp = '\0'; } if (*ver != '\0') { - conc_name_and_version(fbuf, ver, namebuf); + conc_name_and_version(fbuf, ver, namebuf, sizeof(namebuf)); } else { strcpy(namebuf, fbuf); } From 63e21fd289ddd47698ab53d9804f0faf368fc435 Mon Sep 17 00:00:00 2001 From: Nick Briggs Date: Tue, 25 Feb 2025 09:54:13 -0800 Subject: [PATCH 3/4] Replaces all strcpy() by strlcpy() in dsk.c --- src/dsk.c | 215 +++++++++++++++++++++++++++--------------------------- 1 file changed, 106 insertions(+), 109 deletions(-) diff --git a/src/dsk.c b/src/dsk.c index 5ba3518a..53ac5770 100644 --- a/src/dsk.c +++ b/src/dsk.c @@ -877,8 +877,8 @@ LispPTR DSK_getfilename(LispPTR *args) * The file name is specified with a trail directory delimiter. * We should recognize it as a directory. */ - strcpy(aname, dir); - strcpy(vname, dir); + strlcpy(aname, dir, sizeof(aname)); + strlcpy(vname, dir, sizeof(vname)); dirp = 1; } else { /* @@ -895,11 +895,11 @@ LispPTR DSK_getfilename(LispPTR *args) /* * The specified file is a directory file. */ - strcpy(vname, aname); + strlcpy(vname, aname, sizeof(vname)); dirp = 1; } else { #ifdef DOS - strcpy(vname, aname); + strlcpy(vname, aname, sizeof(vname)); #endif dirp = 0; } @@ -921,8 +921,8 @@ LispPTR DSK_getfilename(LispPTR *args) * The file name is specified with a trail directory delimiter. * We should recognize it as a directory. */ - strcpy(aname, dir); - strcpy(vname, dir); + strlcpy(aname, dir, sizeof(aname)); + strlcpy(vname, dir, sizeof(vname)); dirp = 1; } else { if (get_version_array(dir, name) == 0) return (NIL); @@ -935,11 +935,11 @@ LispPTR DSK_getfilename(LispPTR *args) /* * The specified file is a directory file. */ - strcpy(vname, aname); + strlcpy(vname, aname, sizeof(vname)); dirp = 1; } else { #ifdef DOS - strcpy(vname, aname); + strlcpy(vname, aname, sizeof(vname)); #endif dirp = 0; } @@ -954,20 +954,20 @@ LispPTR DSK_getfilename(LispPTR *args) * as if, the subsequent OPENFILE will find the truth. */ if (true_name(dir) != -1) { - strcpy(vname, file); + strlcpy(vname, file, sizeof(vname)); dirp = 0; } else if (strcmp(name, "") == 0) { /* * The file name is specified with a trail directory delimiter. * We should recognize it as a directory. */ - strcpy(aname, dir); - strcpy(vname, dir); + strlcpy(aname, dir, sizeof(aname)); + strlcpy(vname, dir, sizeof(vname)); dirp = 1; } else { conc_dir_and_name(dir, name, aname, sizeof(aname)); if ((rval = true_name(aname)) == -1) { - strcpy(vname, aname); + strlcpy(vname, aname, sizeof(vname)); dirp = 1; } else { /* @@ -992,12 +992,12 @@ LispPTR DSK_getfilename(LispPTR *args) * fails, we try "new" recognition. */ if (true_name(dir) != -1) { - strcpy(vname, file); + strlcpy(vname, file, sizeof(vname)); dirp = 0; } else { conc_dir_and_name(dir, name, aname, sizeof(aname)); if ((rval = true_name(aname)) == -1) { - strcpy(vname, aname); + strlcpy(vname, aname, sizeof(vname)); dirp = 1; } else { if (get_version_array(dir, name) == 0) return (NIL); @@ -1019,9 +1019,9 @@ LispPTR DSK_getfilename(LispPTR *args) */ if (true_name(dir) != -1) return (NIL); conc_dir_and_name(dir, name, vname, sizeof(vname)); - strcpy(aname, vname); + strlcpy(aname, vname, sizeof(aname)); if (true_name(aname) == -1) { - strcpy(vname, aname); + strlcpy(vname, aname, sizeof(vname)); dirp = 1; } else { dirp = 0; @@ -1400,7 +1400,7 @@ LispPTR DSK_renamefile(LispPTR *args) } else { need_maintain_flg = 0; } - strcpy(svless, vless); + strlcpy(svless, vless, sizeof(svless)); } /* @@ -1619,7 +1619,7 @@ LispPTR COM_getfileinfo(LispPTR *args) /* * The directory is specified. */ - strcpy(file, dir); + strlcpy(file, dir, sizeof(file)); } else { if (get_version_array(dir, name) == 0) return (NIL); conc_name_and_version(name, ver, file, sizeof(file)); @@ -2361,16 +2361,16 @@ void separate_version(char *name, char *ver, int checkp) */ ver_no = strtoul(start + 1, (char **)NULL, 10); sprintf(ver_buf, "%u", ver_no); - strcpy(ver, ver_buf); + strlcpy(ver, ver_buf, sizeof(ver)); return; } else { *(start - 1) = '\0'; - strcpy(ver, ver_buf); + strlcpy(ver, ver_buf, sizeof(ver)); return; } } } else if (strchr(name, '%')) { - strcpy(ver, "0"); + strlcpy(ver, "0", sizeof(ver)); return; } NO: @@ -2429,7 +2429,7 @@ int unpack_filename(char *file, char *dir, char *name, char *ver, int checkp) *dir = '\0'; } - strcpy(name, cp + 1); + strlcpy(name, cp + 1, sizeof(name)); separate_version(name, ver, checkp); return (1); } @@ -2519,7 +2519,7 @@ int true_name(char *path) * to dir by locate_file. */ } - strcpy(path, dir); + strlcpy(path, dir, sizeof(path)); return (type); } @@ -2564,16 +2564,16 @@ void conc_dir_and_name(char *dir, char *name, char *fname, size_t fname_size) if (lf_cp1 == (lf_cp2 - 1)) { if (lf_cp1 == (dir)) { /* dir is a root directory. */ - strcpy(fname, "/"); + strlcpy(fname, "/", fname_size); strcat(fname, name); } else { /* The trail directory is included. */ - strcpy(fname, dir); + strlcpy(fname, dir, fname_size); strcat(fname, name); } } else { /* The trail directory is not included */ - strcpy(fname, dir); + strlcpy(fname, dir, fname_size); strcat(fname, "/"); strcat(fname, name); } @@ -2595,9 +2595,6 @@ void conc_dir_and_name(char *dir, char *name, char *fname, size_t fname_size) * * Concatenate the root file name and its version in UNIX format. * - * XXX: this code is unsafe and could result in memory smashes if the - * sizes of the arguments are not correctly specified - * */ void conc_name_and_version(char *name, char *ver, char *rname, size_t rname_size) @@ -2646,7 +2643,7 @@ static int locate_file(char *dir, char *name) sprintf(path, "%s\\%s", dir, name); DIR_OR_FILE_P(path, type); if (type != 0) { - strcpy(dir, path); + strlcpy(dir, path, sizeof(dir)); return (type); } @@ -2665,17 +2662,17 @@ static int locate_file(char *dir, char *name) sprintf(path, "%s/%s", dir, name); DIR_OR_FILE_P(path, type); if (type != 0) { - strcpy(dir, path); + strlcpy(dir, path, sizeof(dir)); return (type); } /* Next try with all lower case name. */ - strcpy(nb1, name); + strlcpy(nb1, name, sizeof(nb1)); DOWNCASE(nb1); sprintf(path, "%s/%s", dir, nb1); DIR_OR_FILE_P(path, type); if (type != 0) { - strcpy(dir, path); + strlcpy(dir, path, sizeof(dir)); return (type); } @@ -2684,7 +2681,7 @@ static int locate_file(char *dir, char *name) sprintf(path, "%s/%s", dir, nb1); DIR_OR_FILE_P(path, type); if (type != 0) { - strcpy(dir, path); + strlcpy(dir, path, sizeof(dir)); return (type); } @@ -2700,13 +2697,13 @@ static int locate_file(char *dir, char *name) errno = 0, S_TOUT(dp = readdir(dirp))) if (dp) { if (strlen(dp->d_name) == len) { - strcpy(nb2, dp->d_name); + strlcpy(nb2, dp->d_name, sizeof(nb2)); UPCASE(nb2); if (strcmp(nb1, nb2) == 0) { sprintf(path, "%s/%s", dir, dp->d_name); DIR_OR_FILE_P(path, type); if (type != 0) { - strcpy(dir, path); + strlcpy(dir, path, sizeof(dir)); TIMEOUT(closedir(dirp)); return (type); } @@ -2783,7 +2780,7 @@ static int make_directory(char *dir) return (0); } if (*cp == '\0') { - strcpy(dir, dir_buf); + strlcpy(dir, dir_buf, sizeof(dir)); return (1); } *dp++ = DIRSEP; @@ -2793,7 +2790,7 @@ static int make_directory(char *dir) case -1: /* Directory */ if (*cp == '\0') { /* Every subdirectories are examined. */ - strcpy(dir, dir_buf); + strlcpy(dir, dir_buf, sizeof(dir)); return (1); } else { dp = dir_buf; @@ -3021,7 +3018,7 @@ static int get_version_array(char *dir, char *file) isslash = 1; if (!isslash) - strcpy(lcased_file, dir); /* Only add the dir if it's real */ + strlcpy(lcased_file, dir, sizeof(lcased_file)); /* Only add the dir if it's real */ else if (drive) { lcased_file[0] = drive; lcased_file[1] = DRIVESEP; @@ -3029,7 +3026,7 @@ static int get_version_array(char *dir, char *file) } else *lcased_file = '\0'; - /* strcpy(lcased_file, dir); removed when above code added 3/4/93 */ + /* strlcpy(lcased_file, dir, sizeof(lcased_file)); removed when above code added 3/4/93 */ strcat(lcased_file, DIRSEPSTR); strcat(lcased_file, file); separate_version(lcased_file, ver, 1); @@ -3045,8 +3042,8 @@ static int get_version_array(char *dir, char *file) TIMEOUT(res = _dos_findfirst(old_file, _A_NORMAL | _A_SUBDIR, &dirp)); if (res == 0) { - strcpy(name, dirp.name); - strcpy(VA.files[varray_index].name, name); + strlcpy(name, dirp.name, sizeof(name)); + strlcpy(VA.files[varray_index].name, name, sizeof(VA.files[0].name)); VA.files[varray_index].version_no = 0; varray_index++; } @@ -3063,11 +3060,11 @@ static int get_version_array(char *dir, char *file) } */ for (; res == 0; S_TOUT(res = _dos_findnext(&dirp))) { - strcpy(name, dirp.name); + strlcpy(name, dirp.name, sizeof(name)); separate_version(name, ver, 1); DOWNCASE(name); - strcpy(VA.files[varray_index].name, dirp.name); + strlcpy(VA.files[varray_index].name, dirp.name, sizeof(VA.files[0].name)); if (*ver == '\0') { /* Versionless file */ VA.files[varray_index].version_no = 1; @@ -3103,9 +3100,9 @@ static int get_version_array(char *dir, char *file) * untouched by the sort, which is intentional. */ if (!NoFileP(VA.files)) { - strcpy(name, VA.files[0].name); + strlcpy(name, VA.files[0].name, sizeof(name)); separate_version(name, ver, 1); - strcpy(VA.files[varray_index].name, name); + strlcpy(VA.files[varray_index].name, name, sizeof(VA.files[0].name)); if (varray_index > 1) { qsort(VA.files, varray_index, sizeof(*VA.files), compare_file_versions); } @@ -3128,7 +3125,7 @@ static int get_version_array(char *dir, char *file) * First of all, prepare a lower cased file name for the case insensitive * search. Also we have to separate file name from its version field. */ - strcpy(lcased_file, file); + strlcpy(lcased_file, file, sizeof(lcased_file)); separate_version(lcased_file, ver, 1); DOWNCASE(lcased_file); @@ -3152,7 +3149,7 @@ static int get_version_array(char *dir, char *file) } else { VA.dir_ino = sbuf.st_ino; VA.lastMTime = sbuf.st_mtim; - strcpy(VA.name, lcased_file); + strlcpy(VA.name, lcased_file, sizeof(VA.name)); } errno = 0; @@ -3171,14 +3168,14 @@ static int get_version_array(char *dir, char *file) for (S_TOUT(dp = readdir(dirp)); dp != NULL || errno == EINTR; errno = 0, S_TOUT(dp = readdir(dirp))) if (dp) { - strcpy(name, dp->d_name); + strlcpy(name, dp->d_name, sizeof(name)); separate_version(name, ver, 1); DOWNCASE(name); if (strcmp(name, lcased_file) == 0) { /* * This file can be regarded as a same file in Lisp sense. */ - strcpy(VA.files[varray_index].name, dp->d_name); + strlcpy(VA.files[varray_index].name, dp->d_name, sizeof(VA.files[0].name)); if (*ver == '\0') { /* Versionless file */ VA.files[varray_index].version_no = 0; @@ -3214,9 +3211,9 @@ static int get_version_array(char *dir, char *file) * untouched by the sort, which is intentional. */ if (!NoFileP(VA.files)) { - strcpy(name, VA.files[0].name); + strlcpy(name, VA.files[0].name, sizeof(name)); separate_version(name, ver, 1); - strcpy(VA.files[varray_index].name, name); + strlcpy(VA.files[varray_index].name, name, sizeof(VA.files[0].name)); if (varray_index > 1) { qsort(VA.files, varray_index, sizeof(*VA.files), compare_file_versions); } @@ -3313,7 +3310,7 @@ static int maintain_version(char *file, int forcep) * file. */ #ifndef DOS - strcpy(fname, entry->name); + strlcpy(fname, entry->name, sizeof(fname)); separate_version(fname, ver, 1); conc_dir_and_name(dir, fname, vless, sizeof(vless)); TIMEOUT(rval = link(old_file, vless)); @@ -3375,7 +3372,7 @@ static int maintain_version(char *file, int forcep) * file. */ #ifndef DOS - strcpy(fname, entry->name); + strlcpy(fname, entry->name, sizeof(fname)); separate_version(fname, ver, 1); conc_dir_and_name(dir, fname, vless, sizeof(vless)); TIMEOUT(rval = link(old_file, vless)); @@ -3519,7 +3516,7 @@ static int check_vless_link(char *vless, FileName *varray, char *to_file, int *h } else { *highest_p = 0; } - strcpy(to_file, name); + strlcpy(to_file, name, sizeof(to_file)); } else { *to_file = '\0'; } @@ -3577,7 +3574,7 @@ static int get_old(char *dir, FileName *varray, char *afile, char *vfile) /* "Old" file have to be existing, thus varray should not be empty. */ if (NoFileP(varray)) return (0); - strcpy(name, afile); + strlcpy(name, afile, sizeof(name)); separate_version(name, ver, 1); if (get_versionless(varray, vless, dir) == 0) { @@ -3592,7 +3589,7 @@ static int get_old(char *dir, FileName *varray, char *afile, char *vfile) */ FindHighestVersion(varray, entry, max_no); conc_dir_and_name(dir, entry->name, afile, sizeof(afile)); - strcpy(vfile, afile); + strlcpy(vfile, afile, sizeof(vfile)); return (1); } else { /* @@ -3604,7 +3601,7 @@ static int get_old(char *dir, FileName *varray, char *afile, char *vfile) FindSpecifiedVersion(varray, entry, ver_no); if (entry != NULL) { conc_dir_and_name(dir, entry->name, afile, sizeof(afile)); - strcpy(vfile, afile); + strlcpy(vfile, afile, sizeof(vfile)); return (1); } else return (0); @@ -3621,7 +3618,7 @@ static int get_old(char *dir, FileName *varray, char *afile, char *vfile) * with as version 1. */ conc_name_and_version(vless, "1", vfile, sizeof(vfile)); - strcpy(afile, vless); + strlcpy(afile, vless, sizeof(afile)); return (1); } else { ver_no = strtoul(ver, (char **)NULL, 10); @@ -3632,7 +3629,7 @@ static int get_old(char *dir, FileName *varray, char *afile, char *vfile) */ conc_name_and_version(name, "1", afile, sizeof(afile)); conc_dir_and_name(dir, afile, vfile, sizeof(vfile)); - strcpy(afile, vless); + strlcpy(afile, vless, sizeof(afile)); return (1); } else { /* @@ -3660,7 +3657,7 @@ static int get_old(char *dir, FileName *varray, char *afile, char *vfile) FindHighestVersion(varray, entry, max_no); sprintf(vbuf, "%u", max_no + 1); conc_name_and_version(vless, vbuf, vfile, sizeof(vfile)); - strcpy(afile, vless); + strlcpy(afile, vless, sizeof(afile)); return (1); } else { /* A version is specified. */ @@ -3675,7 +3672,7 @@ static int get_old(char *dir, FileName *varray, char *afile, char *vfile) */ sprintf(vbuf, "%u", ver_no); conc_name_and_version(vless, vbuf, vfile, sizeof(vfile)); - strcpy(afile, vless); + strlcpy(afile, vless, sizeof(afile)); return (1); } else { /* @@ -3685,7 +3682,7 @@ static int get_old(char *dir, FileName *varray, char *afile, char *vfile) FindSpecifiedVersion(varray, entry, ver_no); if (entry != NULL) { conc_dir_and_name(dir, entry->name, afile, sizeof(afile)); - strcpy(vfile, afile); + strlcpy(vfile, afile, sizeof(vfile)); return (1); } else return (0); @@ -3704,7 +3701,7 @@ static int get_old(char *dir, FileName *varray, char *afile, char *vfile) */ FindHighestVersion(varray, entry, max_no); conc_dir_and_name(dir, entry->name, afile, sizeof(afile)); - strcpy(vfile, afile); + strlcpy(vfile, afile, sizeof(vfile)); return (1); } else { /* @@ -3716,7 +3713,7 @@ static int get_old(char *dir, FileName *varray, char *afile, char *vfile) FindSpecifiedVersion(varray, entry, ver_no); if (entry != NULL) { conc_dir_and_name(dir, entry->name, afile, sizeof(afile)); - strcpy(vfile, afile); + strlcpy(vfile, afile, sizeof(vfile)); return (1); } else return (0); @@ -3776,7 +3773,7 @@ static int get_oldest(char *dir, FileName *varray, char *afile, char *vfile) /* "Oldest" file have to be existing, thus varray should not be empty. */ if (NoFileP(varray)) return (0); - strcpy(name, afile); + strlcpy(name, afile, sizeof(name)); separate_version(name, ver, 1); if (get_versionless(varray, vless, dir) == 0) { @@ -3791,7 +3788,7 @@ static int get_oldest(char *dir, FileName *varray, char *afile, char *vfile) */ FindLowestVersion(varray, entry, min_no); conc_dir_and_name(dir, entry->name, afile, sizeof(afile)); - strcpy(vfile, afile); + strlcpy(vfile, afile, sizeof(vfile)); return (1); } else { /* @@ -3803,7 +3800,7 @@ static int get_oldest(char *dir, FileName *varray, char *afile, char *vfile) FindSpecifiedVersion(varray, entry, ver_no); if (entry != NULL) { conc_dir_and_name(dir, entry->name, afile, sizeof(afile)); - strcpy(vfile, afile); + strlcpy(vfile, afile, sizeof(vfile)); return (1); } else return (0); @@ -3820,7 +3817,7 @@ static int get_oldest(char *dir, FileName *varray, char *afile, char *vfile) * with as version 1. */ conc_name_and_version(vless, "1", vfile, sizeof(vfile)); - strcpy(afile, vless); + strlcpy(afile, vless, sizeof(afile)); return (1); } else { ver_no = strtoul(ver, (char **)NULL, 10); @@ -3831,7 +3828,7 @@ static int get_oldest(char *dir, FileName *varray, char *afile, char *vfile) */ conc_name_and_version(name, "1", afile, sizeof(afile)); conc_dir_and_name(dir, afile, vfile, sizeof(vfile)); - strcpy(afile, vless); + strlcpy(afile, vless, sizeof(afile)); return (1); } else { /* @@ -3856,7 +3853,7 @@ static int get_oldest(char *dir, FileName *varray, char *afile, char *vfile) */ FindLowestVersion(varray, entry, min_no); conc_dir_and_name(dir, entry->name, afile, sizeof(afile)); - strcpy(vfile, afile); + strlcpy(vfile, afile, sizeof(vfile)); return (1); } else { /* A version is specified. */ @@ -3871,7 +3868,7 @@ static int get_oldest(char *dir, FileName *varray, char *afile, char *vfile) */ sprintf(vbuf, "%u", ver_no); conc_name_and_version(vless, vbuf, vfile, sizeof(vfile)); - strcpy(afile, vless); + strlcpy(afile, vless, sizeof(afile)); return (1); } else { /* @@ -3881,7 +3878,7 @@ static int get_oldest(char *dir, FileName *varray, char *afile, char *vfile) FindSpecifiedVersion(varray, entry, ver_no); if (entry != NULL) { conc_dir_and_name(dir, entry->name, afile, sizeof(afile)); - strcpy(vfile, afile); + strlcpy(vfile, afile, sizeof(vfile)); return (1); } else return (0); @@ -3900,7 +3897,7 @@ static int get_oldest(char *dir, FileName *varray, char *afile, char *vfile) */ FindLowestVersion(varray, entry, min_no); conc_dir_and_name(dir, entry->name, afile, sizeof(afile)); - strcpy(vfile, afile); + strlcpy(vfile, afile, sizeof(vfile)); return (1); } else { /* @@ -3912,7 +3909,7 @@ static int get_oldest(char *dir, FileName *varray, char *afile, char *vfile) FindSpecifiedVersion(varray, entry, ver_no); if (entry != NULL) { conc_dir_and_name(dir, entry->name, afile, sizeof(afile)); - strcpy(vfile, afile); + strlcpy(vfile, afile, sizeof(vfile)); return (1); } else return (0); @@ -3970,7 +3967,7 @@ static int get_new(char *dir, FileName *varray, char *afile, char *vfile) int highest_p; FileName *entry; - strcpy(name, afile); + strlcpy(name, afile, sizeof(name)); separate_version(name, ver, 1); #ifndef DOS @@ -3998,7 +3995,7 @@ static int get_new(char *dir, FileName *varray, char *afile, char *vfile) * is recognized as if. */ conc_dir_and_name(dir, afile, vfile, sizeof(vfile)); - strcpy(afile, vfile); + strlcpy(afile, vfile, sizeof(afile)); return (1); } } @@ -4020,11 +4017,11 @@ static int get_new(char *dir, FileName *varray, char *afile, char *vfile) * versioned file as the name of the new file, so that * new file is as the same case as old. */ - strcpy(name, entry->name); + strlcpy(name, entry->name, sizeof(name)); separate_version(name, ver, 1); conc_dir_and_name(dir, name, afile, sizeof(afile)); conc_name_and_version(afile, vbuf, vfile, sizeof(vfile)); - strcpy(afile, vfile); + strlcpy(afile, vfile, sizeof(afile)); return (1); } else { /* @@ -4036,7 +4033,7 @@ static int get_new(char *dir, FileName *varray, char *afile, char *vfile) FindSpecifiedVersion(varray, entry, ver_no); if (entry != NULL) { conc_dir_and_name(dir, entry->name, afile, sizeof(afile)); - strcpy(vfile, afile); + strlcpy(vfile, afile, sizeof(vfile)); return (1); } /* @@ -4052,7 +4049,7 @@ static int get_new(char *dir, FileName *varray, char *afile, char *vfile) while (varray->version_no != LASTVERSIONARRAY) varray++; conc_name_and_version(varray->name, ver, afile, sizeof(afile)); conc_dir_and_name(dir, afile, vfile, sizeof(vfile)); - strcpy(afile, vfile); + strlcpy(afile, vfile, sizeof(afile)); return (1); } } else if (OnlyVersionlessP(varray)) { @@ -4067,7 +4064,7 @@ static int get_new(char *dir, FileName *varray, char *afile, char *vfile) * with as version 1. Thus new version is 2. */ conc_name_and_version(vless, "2", vfile, sizeof(vfile)); - strcpy(afile, vfile); + strlcpy(afile, vfile, sizeof(afile)); return (1); } else { ver_no = strtoul(ver, (char **)NULL, 10); @@ -4078,14 +4075,14 @@ static int get_new(char *dir, FileName *varray, char *afile, char *vfile) */ conc_name_and_version(name, "1", afile, sizeof(afile)); conc_dir_and_name(dir, afile, vfile, sizeof(vfile)); - strcpy(afile, vless); + strlcpy(afile, vless, sizeof(afile)); return (1); } else { /* * Other versions than 1 are recognized as if. */ conc_dir_and_name(dir, afile, vfile, sizeof(vfile)); - strcpy(afile, vfile); + strlcpy(afile, vfile, sizeof(afile)); return (1); } } @@ -4108,7 +4105,7 @@ static int get_new(char *dir, FileName *varray, char *afile, char *vfile) FindHighestVersion(varray, entry, max_no); sprintf(vbuf, "%u", max_no + 2); conc_name_and_version(vless, vbuf, vfile, sizeof(vfile)); - strcpy(afile, vfile); + strlcpy(afile, vfile, sizeof(afile)); return (1); } else { /* A version is specified. */ @@ -4123,7 +4120,7 @@ static int get_new(char *dir, FileName *varray, char *afile, char *vfile) */ sprintf(vbuf, "%u", ver_no); conc_name_and_version(vless, vbuf, vfile, sizeof(vfile)); - strcpy(afile, vless); + strlcpy(afile, vless, sizeof(afile)); return (1); } else { /* @@ -4133,7 +4130,7 @@ static int get_new(char *dir, FileName *varray, char *afile, char *vfile) FindSpecifiedVersion(varray, entry, ver_no); if (entry != NULL) { conc_dir_and_name(dir, entry->name, afile, sizeof(afile)); - strcpy(vfile, afile); + strlcpy(vfile, afile, sizeof(vfile)); return (1); } /* @@ -4152,7 +4149,7 @@ static int get_new(char *dir, FileName *varray, char *afile, char *vfile) while (varray->version_no != LASTVERSIONARRAY) varray++; conc_name_and_version(varray->name, ver, afile, sizeof(afile)); conc_dir_and_name(dir, afile, vfile, sizeof(vfile)); - strcpy(afile, vfile); + strlcpy(afile, vfile, sizeof(afile)); return (1); } } @@ -4174,11 +4171,11 @@ static int get_new(char *dir, FileName *varray, char *afile, char *vfile) * We will use the name of the highest versioned file * as the name of the new file. */ - strcpy(vless, entry->name); + strlcpy(vless, entry->name, sizeof(vless)); separate_version(vless, ver, 1); conc_dir_and_name(dir, vless, afile, sizeof(afile)); conc_name_and_version(afile, vbuf, vfile, sizeof(vfile)); - strcpy(afile, vfile); + strlcpy(afile, vfile, sizeof(afile)); return (1); } else { /* @@ -4190,7 +4187,7 @@ static int get_new(char *dir, FileName *varray, char *afile, char *vfile) FindSpecifiedVersion(varray, entry, ver_no); if (entry != NULL) { conc_dir_and_name(dir, entry->name, afile, sizeof(afile)); - strcpy(vfile, afile); + strlcpy(vfile, afile, sizeof(vfile)); return (1); } /* @@ -4203,11 +4200,11 @@ static int get_new(char *dir, FileName *varray, char *afile, char *vfile) * new file. */ FindHighestVersion(varray, entry, max_no); - strcpy(vless, entry->name); + strlcpy(vless, entry->name, sizeof(vless)); separate_version(vless, vbuf, 1); conc_dir_and_name(dir, vless, afile, sizeof(afile)); conc_name_and_version(afile, ver, vfile, sizeof(vfile)); - strcpy(afile, vfile); + strlcpy(afile, vfile, sizeof(afile)); return (1); } } @@ -4264,7 +4261,7 @@ static int get_old_new(char *dir, FileName *varray, char *afile, char *vfile) int highest_p; FileName *entry; - strcpy(name, afile); + strlcpy(name, afile, sizeof(name)); separate_version(name, ver, 1); if (NoFileP(varray)) { @@ -4287,7 +4284,7 @@ static int get_old_new(char *dir, FileName *varray, char *afile, char *vfile) * is recognized as if. */ conc_dir_and_name(dir, afile, vfile, sizeof(vfile)); - strcpy(afile, vfile); + strlcpy(afile, vfile, sizeof(afile)); return (1); } } @@ -4304,7 +4301,7 @@ static int get_old_new(char *dir, FileName *varray, char *afile, char *vfile) */ FindHighestVersion(varray, entry, max_no); conc_dir_and_name(dir, entry->name, afile, sizeof(afile)); - strcpy(vfile, afile); + strlcpy(vfile, afile, sizeof(vfile)); return (1); } else { /* @@ -4316,7 +4313,7 @@ static int get_old_new(char *dir, FileName *varray, char *afile, char *vfile) FindSpecifiedVersion(varray, entry, ver_no); if (entry != NULL) { conc_dir_and_name(dir, entry->name, afile, sizeof(afile)); - strcpy(vfile, afile); + strlcpy(vfile, afile, sizeof(vfile)); return (1); } /* @@ -4332,7 +4329,7 @@ static int get_old_new(char *dir, FileName *varray, char *afile, char *vfile) while (varray->version_no != LASTVERSIONARRAY) varray++; conc_name_and_version(varray->name, ver, afile, sizeof(afile)); conc_dir_and_name(dir, afile, vfile, sizeof(vfile)); - strcpy(afile, vfile); + strlcpy(afile, vfile, sizeof(afile)); return (1); } } else if (OnlyVersionlessP(varray)) { @@ -4347,7 +4344,7 @@ static int get_old_new(char *dir, FileName *varray, char *afile, char *vfile) * with as version 1. */ conc_name_and_version(vless, "1", vfile, sizeof(vfile)); - strcpy(afile, vless); + strlcpy(afile, vless, sizeof(afile)); return (1); } else { ver_no = strtoul(ver, (char **)NULL, 10); @@ -4358,14 +4355,14 @@ static int get_old_new(char *dir, FileName *varray, char *afile, char *vfile) */ conc_name_and_version(name, "1", afile, sizeof(afile)); conc_dir_and_name(dir, afile, vfile, sizeof(vfile)); - strcpy(afile, vless); + strlcpy(afile, vless, sizeof(afile)); return (1); } else { /* * Other versions than 1 are recognized as if. */ conc_dir_and_name(dir, afile, vfile, sizeof(vfile)); - strcpy(afile, vfile); + strlcpy(afile, vfile, sizeof(afile)); return (1); } } @@ -4387,7 +4384,7 @@ static int get_old_new(char *dir, FileName *varray, char *afile, char *vfile) FindHighestVersion(varray, entry, max_no); sprintf(vbuf, "%u", max_no + 1); conc_name_and_version(vless, vbuf, vfile, sizeof(vfile)); - strcpy(afile, vless); + strlcpy(afile, vless, sizeof(afile)); return (1); } else { /* A version is specified. */ @@ -4402,7 +4399,7 @@ static int get_old_new(char *dir, FileName *varray, char *afile, char *vfile) */ sprintf(vbuf, "%u", ver_no); conc_name_and_version(vless, vbuf, vfile, sizeof(vfile)); - strcpy(afile, vless); + strlcpy(afile, vless, sizeof(afile)); return (1); } else { /* @@ -4412,7 +4409,7 @@ static int get_old_new(char *dir, FileName *varray, char *afile, char *vfile) FindSpecifiedVersion(varray, entry, ver_no); if (entry != NULL) { conc_dir_and_name(dir, entry->name, afile, sizeof(afile)); - strcpy(vfile, afile); + strlcpy(vfile, afile, sizeof(vfile)); return (1); } /* @@ -4431,7 +4428,7 @@ static int get_old_new(char *dir, FileName *varray, char *afile, char *vfile) while (varray->version_no != LASTVERSIONARRAY) varray++; conc_name_and_version(varray->name, ver, afile, sizeof(afile)); conc_dir_and_name(dir, afile, vfile, sizeof(vfile)); - strcpy(afile, vfile); + strlcpy(afile, vfile, sizeof(afile)); return (1); } } @@ -4448,7 +4445,7 @@ static int get_old_new(char *dir, FileName *varray, char *afile, char *vfile) */ FindHighestVersion(varray, entry, max_no); conc_dir_and_name(dir, entry->name, afile, sizeof(afile)); - strcpy(vfile, afile); + strlcpy(vfile, afile, sizeof(vfile)); return (1); } else { /* @@ -4460,7 +4457,7 @@ static int get_old_new(char *dir, FileName *varray, char *afile, char *vfile) FindSpecifiedVersion(varray, entry, ver_no); if (entry != NULL) { conc_dir_and_name(dir, entry->name, afile, sizeof(afile)); - strcpy(vfile, afile); + strlcpy(vfile, afile, sizeof(vfile)); return (1); } /* @@ -4473,11 +4470,11 @@ static int get_old_new(char *dir, FileName *varray, char *afile, char *vfile) * new file. */ FindHighestVersion(varray, entry, max_no); - strcpy(vless, entry->name); + strlcpy(vless, entry->name, sizeof(vless)); separate_version(vless, vbuf, 1); conc_dir_and_name(dir, vless, afile, sizeof(afile)); conc_name_and_version(afile, ver, vfile, sizeof(vfile)); - strcpy(afile, vfile); + strlcpy(afile, vfile, sizeof(afile)); return (1); } } From 177653384052ca00476c6d96053eafe3e7a9fa7a Mon Sep 17 00:00:00 2001 From: Nick Briggs Date: Tue, 25 Feb 2025 10:04:59 -0800 Subject: [PATCH 4/4] Replaces strcat() with strlcat() in dsk.c --- src/dsk.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/dsk.c b/src/dsk.c index 53ac5770..f5e94713 100644 --- a/src/dsk.c +++ b/src/dsk.c @@ -2565,17 +2565,17 @@ void conc_dir_and_name(char *dir, char *name, char *fname, size_t fname_size) if (lf_cp1 == (dir)) { /* dir is a root directory. */ strlcpy(fname, "/", fname_size); - strcat(fname, name); + strlcat(fname, name, fname_size); } else { /* The trail directory is included. */ strlcpy(fname, dir, fname_size); - strcat(fname, name); + strlcat(fname, name, fname_size); } } else { /* The trail directory is not included */ strlcpy(fname, dir, fname_size); - strcat(fname, "/"); - strcat(fname, name); + strlcat(fname, "/", fname_size); + strlcat(fname, name, fname_size); } } @@ -3027,8 +3027,8 @@ static int get_version_array(char *dir, char *file) *lcased_file = '\0'; /* strlcpy(lcased_file, dir, sizeof(lcased_file)); removed when above code added 3/4/93 */ - strcat(lcased_file, DIRSEPSTR); - strcat(lcased_file, file); + strlcat(lcased_file, DIRSEPSTR, sizeof(lcased_file)); + strlcat(lcased_file, file, sizeof(lcased_file)); separate_version(lcased_file, ver, 1); DOWNCASE(lcased_file);