1
0
mirror of https://github.com/Interlisp/maiko.git synced 2026-01-11 23:43:19 +00:00

Updates unixpathname() signature to include output string length, replace strcpy with strlcpy

This commit is contained in:
Nick Briggs 2025-02-25 12:48:03 -08:00
parent d1f7361429
commit 9557ae8f5b
5 changed files with 48 additions and 49 deletions

View File

@ -6,9 +6,9 @@ LispPTR UFS_deletefile(LispPTR *args);
LispPTR UFS_renamefile(LispPTR *args);
LispPTR UFS_directorynamep(LispPTR *args);
#ifdef DOS
int unixpathname(char *src, char *dst, int versionp, int genp, char *drive, int *extlenptr, char *rawname);
int unixpathname(char *src, char *dst, int dstlen, int versionp, int genp, char *drive, int *extlenptr, char *rawname);
#else
int unixpathname(char *src, char *dst, int versionp, int genp);
int unixpathname(char *src, char *dst, size_t dstlen, int versionp, int genp);
#endif
int lisppathname(char *fullname, char *lispname, int dirp, int versionp);
int quote_fname(char *file);

View File

@ -2034,9 +2034,9 @@ LispPTR COM_gen_files(LispPTR *args)
*/
#ifdef DOS
if (!unixpathname(fbuf, pattern, 1, 1, drive, 0, 0)) {
if (!unixpathname(fbuf, pattern, sizeof(pattern), 1, 1, drive, 0, 0)) {
#else
if (!unixpathname(fbuf, pattern, 1, 1)) {
if (!unixpathname(fbuf, pattern, sizeof(pattern), 1, 1)) {
#endif /* DOS */
/* Yes, always dskp is on */
return (SMALLP_MINUSONE);

View File

@ -14,7 +14,7 @@
#include <stdio.h> // for NULL, sprintf, size_t, rename, SEEK_SET
#include <stddef.h> // for ptrdiff_t
#include <stdlib.h> // for strtoul, qsort
#include <string.h> // for strcpy, strcmp, strlen, strncpy, strchr
#include <string.h> // for strlcpy, strcmp, strlen, strncpy, strchr
#include <sys/stat.h> // for stat, fstat, mkdir, S_ISREG, st_atime, chmod
#include <sys/types.h> // for ino_t, time_t, off_t
#include <unistd.h> // for unlink, close, link, lseek, access, chdir
@ -264,9 +264,9 @@ LispPTR COM_openfile(LispPTR *args)
* convert a version field.
*/
#ifdef DOS
unixpathname(lfname, file, dskp, 0, drive, &extlen, rawname);
unixpathname(lfname, file, sizeof(file), dskp, 0, drive, &extlen, rawname);
#else
unixpathname(lfname, file, dskp, 0);
unixpathname(lfname, file, sizeof(file), dskp, 0);
#endif
/*
@ -598,8 +598,7 @@ LispPTR COM_closefile(LispPTR *args)
* Convert a Lisp file name to UNIX one. If host is DSK, we also have to
* convert a version field.
*/
dskp ? unixpathname(lfname, file, 1, 0, drive, &extlen, rawname)
: unixpathname(lfname, file, 0, 0, drive, &extlen, rawname);
unixpathname(lfname, file, sizeof(file), dskp, drive, &extlen, rawname);
fd = LispNumToCInt(args[1]);
cdate = (time_t)LispNumToCInt(args[2]);
if (!dskp) {
@ -721,8 +720,7 @@ LispPTR COM_closefile(LispPTR *args)
* Convert a Lisp file name to UNIX one. If host is DSK, we also have to
* convert a version field.
*/
dskp ? unixpathname(lfname, file, 1, 0) : unixpathname(lfname, file, 0, 0);
unixpathname(lfname, file, sizeof(file), dskp, 0);
fd = LispNumToCInt(args[1]);
cdate = (time_t)LispNumToCInt(args[2]);
@ -849,9 +847,9 @@ LispPTR DSK_getfilename(LispPTR *args)
* unixpathname specifies it.
*/
#ifdef DOS
if (unixpathname(lfname, file, 1, 0, drive, &extlen, rawname) == 0) return (NIL);
if (unixpathname(lfname, file, sizeof(file), 1, 0, drive, &extlen, rawname) == 0) return (NIL);
#else
if (unixpathname(lfname, file, 1, 0) == 0) return (NIL);
if (unixpathname(lfname, file, sizeof(file), 1, 0) == 0) return (NIL);
#endif
if (unpack_filename(file, dir, name, ver, 1) == 0) return (NIL);
@ -1120,9 +1118,9 @@ LispPTR DSK_deletefile(LispPTR *args)
LispStringToCString(args[0], fbuf, MAXPATHLEN);
#ifdef DOS
separate_drive(fbuf, drive);
unixpathname(fbuf, file, 1, 0, drive, &extlen, rawname);
unixpathname(fbuf, file, sizeof(file), 1, 0, drive, &extlen, rawname);
#else
unixpathname(fbuf, file, 1, 0);
unixpathname(fbuf, file, sizeof(file), 1, 0);
#endif
if (unpack_filename(file, dir, fbuf, ver, 1) == 0) return (NIL);
@ -1271,17 +1269,17 @@ LispPTR DSK_renamefile(LispPTR *args)
LispStringToCString(args[0], fbuf, MAXPATHLEN);
#ifdef DOS
separate_drive(fbuf, drive1);
unixpathname(fbuf, src, 1, 0, drive1, &extlen1, rawname1);
unixpathname(fbuf, src, sizeof(src), 1, 0, drive1, &extlen1, rawname1);
#else /* DOS */
unixpathname(fbuf, src, 1, 0);
unixpathname(fbuf, src, sizeof(src), 1, 0);
#endif /* DOS */
LispStringToCString(args[1], fbuf, MAXPATHLEN);
#ifdef DOS
separate_drive(fbuf, drive2);
unixpathname(fbuf, dst, 1, 0, drive2, &extlen2, rawname2);
unixpathname(fbuf, dst, sizeof(dst), 1, 0, drive2, &extlen2, rawname2);
#else /* DOS */
unixpathname(fbuf, dst, 1, 0);
unixpathname(fbuf, dst, sizeof(dst), 1, 0);
#endif /* DOS */
if (unpack_filename(dst, dir, fbuf, ver, 1) == 0) return (NIL);
@ -1492,9 +1490,9 @@ LispPTR DSK_directorynamep(LispPTR *args)
/* Convert Xerox Lisp file naming convention to Unix one. */
#ifdef DOS
separate_drive(dirname, drive);
if (unixpathname(dirname, fullname, 1, 0, drive, 0, 0) == 0) return (NIL);
if (unixpathname(dirname, fullname, sizeof(fullname), 1, 0, drive, 0, 0) == 0) return (NIL);
#else /* DOS*/
if (unixpathname(dirname, fullname, 1, 0) == 0) return (NIL);
if (unixpathname(dirname, fullname, sizeof(fullname), 1, 0) == 0) return (NIL);
#endif /* DOS */
if (true_name(fullname) != -1) return (NIL);
@ -1599,9 +1597,9 @@ LispPTR COM_getfileinfo(LispPTR *args)
* convert a version field.
*/
#ifdef DOS
unixpathname(lfname, file, dskp, 0, drive, &extlen, rawname);
unixpathname(lfname, file, sizeof(file), dskp, 0, drive, &extlen, rawname);
#else /* DOS */
unixpathname(lfname, file, dskp, 0);
unixpathname(lfname, file, sizeof(file), dskp, 0);
#endif /* DOS */
/*
@ -1794,9 +1792,9 @@ LispPTR COM_setfileinfo(LispPTR *args)
* convert a version field.
*/
#ifdef DOS
unixpathname(lfname, file, dskp, 0, drive, &extlen, rawname);
unixpathname(lfname, file, sizeof(file), dskp, 0, drive, &extlen, rawname);
#else /* DOS */
unixpathname(lfname, file, dskp, 0);
unixpathname(lfname, file, sizeof(file), dskp, 0);
#endif /* DOS */
/*
@ -2141,9 +2139,9 @@ LispPTR COM_changedir(LispPTR *args)
return (NIL);
#ifdef DOS
if (!unixpathname(lfname, dir, 0, 0, drive, 0, 0)) return (NIL);
if (!unixpathname(lfname, dir, sizeof(dir), 0, 0, drive, 0, 0)) return (NIL);
#else /* DOS */
if (!unixpathname(lfname, dir, 0, 0)) return (NIL);
if (!unixpathname(lfname, dir, sizeof(dir), 0, 0)) return (NIL);
#endif /* DOS */
if (dskp) {
@ -2241,9 +2239,9 @@ LispPTR COM_getfreeblock(LispPTR *args)
return (NIL);
#ifdef DOS
if (!unixpathname(lfname, file, 0, 0, drive, 0, 0)) return (NIL);
if (!unixpathname(lfname, file, sizeof(file), 0, 0, drive, 0, 0)) return (NIL);
#else /* DOS */
if (!unixpathname(lfname, file, 0, 0)) return (NIL);
if (!unixpathname(lfname, file, sizeof(file), 0, 0)) return (NIL);
#endif /* DOS */
if (!unpack_filename(file, dir, name, ver, 0)) return (NIL);

View File

@ -176,9 +176,9 @@ LispPTR UFS_getfilename(LispPTR *args)
* unixpathname specifies it.
*/
#ifdef DOS
if (unixpathname(lfname, file, 0, 0, 0, 0, 0) == 0) return (NIL);
if (unixpathname(lfname, file, sizeof(file), 0, 0, 0, 0, 0) == 0) return (NIL);
#else
if (unixpathname(lfname, file, 0, 0) == 0) return (NIL);
if (unixpathname(lfname, file, sizeof(file), 0, 0) == 0) return (NIL);
#endif /* DOS */
switch (args[1]) {
@ -259,9 +259,9 @@ LispPTR UFS_deletefile(LispPTR *args)
LispStringToCString(args[0], fbuf, MAXPATHLEN);
#ifdef DOS
if (unixpathname(fbuf, file, 0, 0, 0, 0, 0) == 0) return (NIL);
if (unixpathname(fbuf, file, sizeof(file), 0, 0, 0, 0, 0) == 0) return (NIL);
#else
if (unixpathname(fbuf, file, 0, 0) == 0) return (NIL);
if (unixpathname(fbuf, file, sizeof(file), 0, 0) == 0) return (NIL);
#endif /* DOS */
/* check if we're operating on directory or file */
TIMEOUT(rval = stat(file, &sbuf));
@ -327,15 +327,15 @@ LispPTR UFS_renamefile(LispPTR *args)
LispStringToCString(args[0], fbuf, MAXPATHLEN);
#ifdef DOS
if (unixpathname(fbuf, src, 0, 0, 0, 0, 0) == 0) return (NIL);
if (unixpathname(fbuf, src, sizeof(src), 0, 0, 0, 0, 0) == 0) return (NIL);
#else
if (unixpathname(fbuf, src, 0, 0) == 0) return (NIL);
if (unixpathname(fbuf, src, sizeof(src), 0, 0) == 0) return (NIL);
#endif /* DOS */
LispStringToCString(args[1], fbuf, MAXPATHLEN);
#ifdef DOS
if (unixpathname(fbuf, dst, 0, 0, 0, 0, 0) == 0) return (NIL);
if (unixpathname(fbuf, dst, sizeof(dst), 0, 0, 0, 0, 0) == 0) return (NIL);
#else
if (unixpathname(fbuf, dst, 0, 0) == 0) return (NIL);
if (unixpathname(fbuf, dst, sizeof(dst), 0, 0) == 0) return (NIL);
#endif /* DOS */
TIMEOUT(rval = rename(src, dst));
@ -400,9 +400,9 @@ LispPTR UFS_directorynamep(LispPTR *args)
/* Convert Xerox Lisp file naming convention to Unix one. */
#ifdef DOS
if (unixpathname(dirname, fullname, 0, 0, 0, 0, 0) == 0) return (NIL);
if (unixpathname(dirname, fullname, sizeof(fullname), 0, 0, 0, 0, 0) == 0) return (NIL);
#else
if (unixpathname(dirname, fullname, 0, 0) == 0) return (NIL);
if (unixpathname(dirname, fullname, sizeof(fullname), 0, 0) == 0) return (NIL);
#endif /* DOS */
TIMEOUT(rval = stat(fullname, &sbuf));
@ -437,6 +437,7 @@ LispPTR UFS_directorynamep(LispPTR *args)
* if the pathname is passed as a directory, the
* tail delimiter may be included.
* char *dst The buffer to which the converted pathname is stored.
* int dstlen The size of the dst buffer
* int versionp
* If 1, version field in src is converted to UNIX
* version form. {DSK} device invokes unixpathname
@ -463,9 +464,9 @@ LispPTR UFS_directorynamep(LispPTR *args)
*
*/
#ifdef DOS
int unixpathname(char *src, char *dst, int versionp, int genp, char *drive, int *extlenptr, char *rawname)
int unixpathname(char *src, char *dst, int dstlen, int versionp, int genp, char *drive, int *extlenptr, char *rawname)
#else
int unixpathname(char *src, char *dst, int versionp, int genp)
int unixpathname(char *src, char *dst, size_t dstlen, int versionp, int genp)
#endif /* DOS */
{
char *cp, *dp, *np;
@ -495,12 +496,12 @@ int unixpathname(char *src, char *dst, int versionp, int genp)
* file system code.
*/
if (strcmp(src, "<") == 0) {
strcpy(dst, DIRSEPSTR);
strlcpy(dst, DIRSEPSTR, dstlen);
return (1);
}
/* Copy src to protect it from destructive modification. */
strcpy(lfname, src);
strlcpy(lfname, src, sizeof(lfname));
/*
* If versionp is specified, we have to deal with the version field first,
@ -582,7 +583,7 @@ int unixpathname(char *src, char *dst, int versionp, int genp)
TIMEOUT0(pwd = getpwuid(getuid()));
if (pwd == NULL) return (0);
strcpy(dst, pwd->pw_dir);
strlcpy(dst, pwd->pw_dir, dstlen);
while (*dp != '\0') dp++;
if (*(dp - 1) != DIRSEP) {
/*
@ -606,7 +607,7 @@ int unixpathname(char *src, char *dst, int versionp, int genp)
TIMEOUT0(pwd = getpwnam(name));
if (pwd == NULL) return (0);
strcpy(dst, pwd->pw_dir);
strlcpy(dst, pwd->pw_dir, dstlen);
while (*dp != '\0') dp++;
if (*(dp - 1) != DIRSEP) {
/*
@ -807,8 +808,8 @@ int unixpathname(char *src, char *dst, int versionp, int genp)
* for the convenience of the pattern matching routines, we don't
* care about the last period character.
*/
strcpy(fbuf1, lfname);
strcpy(fbuf2, dst);
strlcpy(fbuf1, lfname, sizeof(fbuf1));
strlcpy(fbuf2, dst, sizeof(fbuf2));
separate_version(fbuf1, ver1, 1);
separate_version(fbuf2, ver2, 1);
for (cp = fbuf1; *cp; cp++) {}

View File

@ -156,9 +156,9 @@ LispPTR vmem_save0(LispPTR *args)
LispStringToCString(args[0], pathname, MAXPATHLEN);
separate_host(pathname, host);
#ifdef DOS
if (!unixpathname(pathname, sysout, 0, 0, drive, 0, 0)) return (BADFILENAME);
if (!unixpathname(pathname, sysout, sizeof(sysout), 0, 0, drive, 0, 0)) return (BADFILENAME);
#else
if (!unixpathname(pathname, sysout, 0, 0)) return (BADFILENAME);
if (!unixpathname(pathname, sysout, sizeof(sysout), 0, 0)) return (BADFILENAME);
#endif /* DOS */
return (vmem_save(sysout));
} else {