Skip to content

Commit c86190b

Browse files
committed
Adds size of output parameter to lisppathname() and replaces various strcpy() with strlcpy()
1 parent 2525316 commit c86190b

File tree

3 files changed

+15
-14
lines changed

3 files changed

+15
-14
lines changed

inc/ufsdefs.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ int unixpathname(char *src, char *dst, int dstlen, int versionp, int genp, char
1010
#else
1111
int unixpathname(char *src, char *dst, size_t dstlen, int versionp, int genp);
1212
#endif
13-
int lisppathname(char *fullname, char *lispname, int dirp, int versionp);
13+
int lisppathname(char *fullname, char *lispname, size_t lispnamesize, int dirp, int versionp);
1414
int quote_fname(char *file);
1515
int quote_fname_ufs(char *file);
1616
int quote_dname(char *dir);

src/dsk.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1024,7 +1024,7 @@ LispPTR DSK_getfilename(LispPTR *args)
10241024
} else {
10251025
dirp = 0;
10261026
}
1027-
if (lisppathname(vname, lfname, dirp, 0) == 0) return (NIL);
1027+
if (lisppathname(vname, lfname, sizeof(lfname), dirp, 0) == 0) return (NIL);
10281028
STRING_BASE(args[2], base);
10291029
len = strlen(lfname);
10301030

@@ -1046,7 +1046,7 @@ LispPTR DSK_getfilename(LispPTR *args)
10461046
/*
10471047
* Now, vname holds the "versioned" full name of the recognized file in UNIX
10481048
* format. We have to convert it back to Lisp format. The version field
1049-
* have to be converted. The fourth argument for lisppathname specifies it.
1049+
* have to be converted. The fifth argument for lisppathname specifies it.
10501050
*/
10511051
#ifdef DOS
10521052
/* For DOS, have to assure we use the name asked for, not the */
@@ -1059,7 +1059,7 @@ LispPTR DSK_getfilename(LispPTR *args)
10591059
}
10601060
#endif /* DOS */
10611061

1062-
if (lisppathname(vname, lfname, dirp, (dirp ? 0 : 1)) == 0) return (NIL);
1062+
if (lisppathname(vname, lfname, sizeof(lfname), dirp, (dirp ? 0 : 1)) == 0) return (NIL);
10631063

10641064
STRING_BASE(args[2], base);
10651065
len = strlen(lfname);
@@ -1498,7 +1498,7 @@ LispPTR DSK_directorynamep(LispPTR *args)
14981498
if (true_name(fullname) != -1) return (NIL);
14991499

15001500
/* Convert Unix file naming convention to Xerox Lisp one. */
1501-
if (lisppathname(fullname, dirname, 1, 0) == 0) return (NIL);
1501+
if (lisppathname(fullname, dirname, sizeof(dirname), 1, 0) == 0) return (NIL);
15021502

15031503
len = strlen(dirname);
15041504
STRING_BASE(args[1], base);

src/ufs.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ LispPTR UFS_getfilename(LispPTR *args)
210210
* Now, we convert a file name back to Lisp format. The version field have not
211211
* to be converted. The fourth argument for lisppathname specifies it.
212212
*/
213-
if (lisppathname(file, lfname, 0, 0) == 0) return (NIL);
213+
if (lisppathname(file, lfname, sizeof(lfname), 0, 0) == 0) return (NIL);
214214

215215
STRING_BASE(args[2], base);
216216
len = strlen(lfname);
@@ -414,7 +414,7 @@ LispPTR UFS_directorynamep(LispPTR *args)
414414
if (!S_ISDIR(sbuf.st_mode)) return (NIL);
415415

416416
/* Convert Unix file naming convention to Xerox Lisp one. */
417-
if (lisppathname(fullname, dirname, 1, 0) == 0) return (NIL);
417+
if (lisppathname(fullname, dirname, sizeof(dirname), 1, 0) == 0) return (NIL);
418418

419419
len = strlen(dirname);
420420
STRING_BASE(args[1], base);
@@ -846,6 +846,7 @@ int unixpathname(char *src, char *dst, size_t dstlen, int versionp, int genp)
846846
* The lispname is used to determine which
847847
* character should be quoted in the result
848848
* Xerox Lisp pathname representation.
849+
* size_t lispnamesize size of storage available for lispname
849850
* int dirp If 1, fullname is a directory. If 0,
850851
* fullname is a file.
851852
* int versionp If 1, version field is also converted
@@ -872,7 +873,7 @@ int unixpathname(char *src, char *dst, size_t dstlen, int versionp, int genp)
872873
*
873874
*/
874875

875-
int lisppathname(char *fullname, char *lispname, int dirp, int versionp)
876+
int lisppathname(char *fullname, char *lispname, size_t lispnamesize, int dirp, int versionp)
876877
{
877878
char *cp, *dp, *lnamep, *cnamep;
878879
char namebuf[MAXPATHLEN], fbuf[MAXPATHLEN], ver[VERSIONLEN];
@@ -983,7 +984,7 @@ int lisppathname(char *fullname, char *lispname, int dirp, int versionp)
983984
if (dirp) {
984985
if (*(dp - 1) != '>' || *(dp - 2) == '\'') *dp++ = '>';
985986
*dp = '\0';
986-
strcpy(lispname, namebuf);
987+
strlcpy(lispname, namebuf, lispnamesize);
987988
return (1);
988989
}
989990

@@ -1047,7 +1048,7 @@ int lisppathname(char *fullname, char *lispname, int dirp, int versionp)
10471048
* or not. If extension field is not included, we have to add a period
10481049
* to specify empty extension field.
10491050
*/
1050-
strcpy(fbuf, namebuf);
1051+
strlcpy(fbuf, namebuf, sizeof(fbuf));
10511052
dp = cp = fbuf;
10521053
while (*cp) {
10531054
switch (*cp) {
@@ -1090,15 +1091,15 @@ int lisppathname(char *fullname, char *lispname, int dirp, int versionp)
10901091
if (versionp && *ver != '\0') {
10911092
conc_name_and_version(fbuf, ver, namebuf, MAXPATHLEN);
10921093
} else {
1093-
strcpy(namebuf, fbuf);
1094+
strlcpy(namebuf, fbuf, sizeof(namebuf));
10941095
}
10951096

10961097
/*
10971098
* Now, it's time to convert the version field.
10981099
*/
10991100
if (!dirp && versionp) UnixVersionToLispVersion(namebuf, 0);
11001101

1101-
strcpy(lispname, namebuf);
1102+
strlcpy(lispname, namebuf, lispnamesize);
11021103
return (1);
11031104
}
11041105

@@ -1189,10 +1190,10 @@ int quote_fname(char *file)
11891190
if (*ver != '\0') {
11901191
conc_name_and_version(fbuf, ver, namebuf, sizeof(namebuf));
11911192
} else {
1192-
strcpy(namebuf, fbuf);
1193+
strlcpy(namebuf, fbuf, sizeof(namebuf));
11931194
}
11941195
UnixVersionToLispVersion(namebuf, 1);
1195-
strcpy(file, namebuf);
1196+
strlcpy(file, namebuf, sizeof(file));
11961197
return (1);
11971198
}
11981199

0 commit comments

Comments
 (0)