Skip to content

Commit d791b1d

Browse files
authored
Merge pull request #533 from Interlisp/nhb-rewrite-version-parser-v2
Extensive rewrite of various parts of the file name/version handling code. Converts a lot of unsafe string handling functions to safer variants. Passes buffer sizes in various places to enable overflow checks. Removes some unused variable declarations. Updates comments. Improves performance with alarm timeout setting when sequences of alarm set/cancel operations are performed. Adds GETFILEINFO processing for INODE_LO and INODE_HI attributes.
2 parents 853d133 + 3d09555 commit d791b1d

File tree

17 files changed

+986
-1118
lines changed

17 files changed

+986
-1118
lines changed

CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,6 @@ SET(MAIKO_HDRS
364364
inc/lispemul.h
365365
inc/lispmap.h
366366
inc/lispver1.h
367-
inc/lispver2.h
368367
inc/llcolordefs.h
369368
inc/lldsp.h
370369
inc/llstkdefs.h

bin/makefile-dos

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ SRCFILES = conspage.c gcoflow.c shift.c dbgtool.c gcr.c gcrcell.c llstk.
1818
OFILES = conspage.obj gcoflow.obj shift.obj dbgtool.obj gcr.obj gcrcell.obj llstk.obj gcscan.obj loopsops.obj storage.obj allocmds.obj dir.obj gvar2.obj lowlev1.obj subr.obj arithops.obj lowlev2.obj subr0374.obj doscomm.obj hardrtn.obj lsthandl.obj sxhash.obj draw.obj main.obj testtool.obj array.obj dsk.obj inet.obj misc7.obj timer.obj array2.obj dspif.obj initdsp.obj miscn.obj typeof.obj array3.obj initkbd.obj ubf1.obj array4.obj dspsubrs.obj initsout.obj mkatom.obj ubf2.obj array5.obj eqf.obj intcall.obj mkcell.obj ubf3.obj array6.obj ether.obj ufn.obj atom.obj findkey.obj kbdsubrs.obj mouseif.obj ufs.obj bbtsub.obj foreign.obj keyevent.obj unixcomm.obj bin.obj fp.obj binds.obj fvar.obj mvs.obj unwind.obj bitblt.obj gc.obj uraid.obj blt.obj gc2.obj kprint.obj osmsg.obj usrsubr.obj byteswap.obj gcarray.obj perrno.obj uutils.obj carcdr.obj asmbbt.obj gccode.obj vars3.obj gcfinal.obj ldsout.obj return.obj vmemsave.obj chardev.obj gchtfind.obj lineblt8.obj rpc.obj xc.obj common.obj gcmain3.obj lisp2c.obj rplcons.obj z2.obj vdate.obj $(COLORFILES) $(ARCHFILES) $(LPFILES)
1919

2020

21-
HFILES = address.h adr68k.h arithopsdefs.h arith.h cell.h dbprint.h display.h dspif.h ifpage.h iopage.h lispemul.h lispmap.h lsptypes.h miscstat.h lspglob.h array.h bb.h bbtmacro.h debug.h devconf.h dspdata.h fast_dsp.h gcdata.h initatms.h inlinec.h keyboard.h lispver1.h lispver2.h lldsp.h locfile.h medleyfp.h mouseif.h my.h opcodes.h osmsgprint.h pilotbbt.h print.h retmacro.h stack.h stream.h subrs.h timeout.h tos1defs.h tosfns.h tosret.h xdefs.h xbitmaps.h xkeymap.h
21+
HFILES = address.h adr68k.h arithopsdefs.h arith.h cell.h dbprint.h display.h dspif.h ifpage.h iopage.h lispemul.h lispmap.h lsptypes.h miscstat.h lspglob.h array.h bb.h bbtmacro.h debug.h devconf.h dspdata.h fast_dsp.h gcdata.h initatms.h inlinec.h keyboard.h lispver1.h lldsp.h locfile.h medleyfp.h mouseif.h my.h opcodes.h osmsgprint.h pilotbbt.h print.h retmacro.h stack.h stream.h subrs.h timeout.h tos1defs.h tosfns.h tosret.h xdefs.h xbitmaps.h xkeymap.h
2222

2323

2424

bin/makefile-tail

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ $(OBJECTDIR)car-cdr.o: $(SRCDIR)car-cdr.c $(REQUIRED-INCS) \
340340
$(OBJECTDIR)chardev.o: $(SRCDIR)chardev.c $(REQUIRED-INCS) \
341341
$(INCDIR)lispemul.h $(INCDIR)lispmap.h \
342342
$(INCDIR)adr68k.h $(INCDIR)lsptypes.h $(INCDIR)arith.h $(INCDIR)timeout.h \
343-
$(INCDIR)locfile.h $(INCDIR)lispver2.h $(INCDIR)dbprint.h \
343+
$(INCDIR)locfile.h $(INCDIR)dbprint.h \
344344
$(INCDIR)chardevdefs.h $(INCDIR)byteswapdefs.h $(INCDIR)commondefs.h \
345345
$(INCDIR)perrnodefs.h
346346
$(CC) $(RFLAGS) $(SRCDIR)chardev.c -o $(OBJECTDIR)chardev.o
@@ -505,7 +505,7 @@ $(OBJECTDIR)dsk.o: $(SRCDIR)dsk.c $(REQUIRED-INCS) \
505505
$(INCDIR)lispemul.h $(INCDIR)lispmap.h \
506506
$(INCDIR)adr68k.h $(INCDIR)lsptypes.h $(INCDIR)lspglob.h $(INCDIR)ifpage.h \
507507
$(INCDIR)iopage.h $(INCDIR)miscstat.h $(INCDIR)arith.h $(INCDIR)stream.h \
508-
$(INCDIR)timeout.h $(INCDIR)locfile.h $(INCDIR)lispver2.h \
508+
$(INCDIR)timeout.h $(INCDIR)locfile.h \
509509
$(INCDIR)dbprint.h $(INCDIR)dskdefs.h $(INCDIR)byteswapdefs.h \
510510
$(INCDIR)car-cdrdefs.h $(INCDIR)cell.h $(INCDIR)commondefs.h \
511511
$(INCDIR)ufsdefs.h
@@ -515,15 +515,15 @@ $(OBJECTDIR)ufs.o: $(SRCDIR)ufs.c $(REQUIRED-INCS) \
515515
$(INCDIR)lispemul.h $(INCDIR)lispmap.h \
516516
$(INCDIR)adr68k.h $(INCDIR)lsptypes.h $(INCDIR)lspglob.h $(INCDIR)ifpage.h \
517517
$(INCDIR)iopage.h $(INCDIR)miscstat.h $(INCDIR)arith.h $(INCDIR)stream.h \
518-
$(INCDIR)timeout.h $(INCDIR)locfile.h $(INCDIR)lispver2.h $(INCDIR)dbprint.h \
518+
$(INCDIR)timeout.h $(INCDIR)locfile.h $(INCDIR)dbprint.h \
519519
$(INCDIR)ufsdefs.h $(INCDIR)commondefs.h $(INCDIR)dskdefs.h
520520
$(CC) $(RFLAGS) $(SRCDIR)ufs.c -o $(OBJECTDIR)ufs.o
521521

522522
$(OBJECTDIR)dir.o: $(SRCDIR)dir.c $(REQUIRED-INCS) \
523523
$(INCDIR)lispemul.h $(INCDIR)lispmap.h \
524524
$(INCDIR)adr68k.h $(INCDIR)lsptypes.h $(INCDIR)arith.h $(INCDIR)lspglob.h \
525525
$(INCDIR)ifpage.h $(INCDIR)iopage.h $(INCDIR)miscstat.h $(INCDIR)timeout.h \
526-
$(INCDIR)locfile.h $(INCDIR)lispver2.h $(INCDIR)dirdefs.h \
526+
$(INCDIR)locfile.h $(INCDIR)dirdefs.h \
527527
$(INCDIR)commondefs.h $(INCDIR)dskdefs.h $(INCDIR)ufsdefs.h
528528
$(CC) $(RFLAGS) $(SRCDIR)dir.c -o $(OBJECTDIR)dir.o
529529

@@ -640,7 +640,7 @@ $(OBJECTDIR)inet.o: $(SRCDIR)inet.c $(REQUIRED-INCS) \
640640
$(INCDIR)lispemul.h $(INCDIR)lispmap.h \
641641
$(INCDIR)lsptypes.h $(INCDIR)arith.h $(INCDIR)emlglob.h $(INCDIR)lspglob.h \
642642
$(INCDIR)ifpage.h $(INCDIR)iopage.h $(INCDIR)miscstat.h $(INCDIR)adr68k.h \
643-
$(INCDIR)dbprint.h $(INCDIR)locfile.h $(INCDIR)lispver2.h \
643+
$(INCDIR)dbprint.h $(INCDIR)locfile.h \
644644
$(INCDIR)inetdefs.h $(INCDIR)byteswapdefs.h $(INCDIR)commondefs.h \
645645
$(INCDIR)mkcelldefs.h
646646
$(CC) $(RFLAGS) $(SRCDIR)inet.c -o $(OBJECTDIR)inet.o
@@ -758,7 +758,7 @@ $(OBJECTDIR)osmsg.o: $(SRCDIR)osmsg.c $(REQUIRED-INCS) \
758758
$(INCDIR)lispemul.h $(INCDIR)lispmap.h \
759759
$(INCDIR)adr68k.h $(INCDIR)lsptypes.h $(INCDIR)arith.h $(INCDIR)stream.h \
760760
$(INCDIR)lspglob.h $(INCDIR)ifpage.h $(INCDIR)iopage.h $(INCDIR)miscstat.h \
761-
$(INCDIR)timeout.h $(INCDIR)locfile.h $(INCDIR)lispver2.h $(INCDIR)osmsgprint.h \
761+
$(INCDIR)timeout.h $(INCDIR)locfile.h $(INCDIR)osmsgprint.h \
762762
$(INCDIR)dbprint.h $(INCDIR)commondefs.h $(INCDIR)osmsgdefs.h
763763
$(CC) $(RFLAGS) $(SRCDIR)osmsg.c -o $(OBJECTDIR)osmsg.o
764764

@@ -865,7 +865,7 @@ $(OBJECTDIR)unixcomm.o: $(SRCDIR)unixcomm.c $(REQUIRED-INCS) \
865865
$(INCDIR)lspglob.h $(INCDIR)ifpage.h $(INCDIR)iopage.h $(INCDIR)miscstat.h \
866866
$(INCDIR)cell.h $(INCDIR)stack.h $(INCDIR)arith.h $(INCDIR)dbprint.h \
867867
$(INCDIR)timeout.h $(INCDIR)unixcommdefs.h $(INCDIR)byteswapdefs.h \
868-
$(INCDIR)commondefs.h $(INCDIR)locfile.h $(INCDIR)lispver2.h
868+
$(INCDIR)commondefs.h $(INCDIR)locfile.h
869869
$(CC) $(RFLAGS) $(SRCDIR)unixcomm.c -o $(OBJECTDIR)unixcomm.o
870870

871871
$(OBJECTDIR)unixfork.o: $(SRCDIR)unixfork.c $(REQUIRED-INCS) \
@@ -888,7 +888,7 @@ $(OBJECTDIR)rpc.o: $(SRCDIR)rpc.c $(REQUIRED-INCS) \
888888
$(INCDIR)lispemul.h $(INCDIR)lispmap.h \
889889
$(INCDIR)lsptypes.h $(INCDIR)lspglob.h $(INCDIR)ifpage.h $(INCDIR)iopage.h \
890890
$(INCDIR)miscstat.h $(INCDIR)emlglob.h $(INCDIR)adr68k.h $(INCDIR)arith.h \
891-
$(INCDIR)locfile.h $(INCDIR)lispver2.h $(INCDIR)rpcdefs.h \
891+
$(INCDIR)locfile.h $(INCDIR)rpcdefs.h \
892892
$(INCDIR)commondefs.h
893893
$(CC) $(RFLAGS) $(SRCDIR)rpc.c -o $(OBJECTDIR)rpc.o
894894

@@ -909,7 +909,7 @@ $(OBJECTDIR)vmemsave.o: $(SRCDIR)vmemsave.c $(REQUIRED-INCS) \
909909
$(INCDIR)lispemul.h \
910910
$(INCDIR)lispmap.h $(INCDIR)lspglob.h $(INCDIR)ifpage.h $(INCDIR)iopage.h \
911911
$(INCDIR)miscstat.h $(INCDIR)timeout.h $(INCDIR)adr68k.h \
912-
$(INCDIR)lsptypes.h $(INCDIR)locfile.h $(INCDIR)lispver2.h $(INCDIR)dbprint.h \
912+
$(INCDIR)lsptypes.h $(INCDIR)locfile.h $(INCDIR)dbprint.h \
913913
$(INCDIR)devif.h $(INCDIR)vmemsavedefs.h $(INCDIR)byteswapdefs.h $(INCDIR)commondefs.h \
914914
$(INCDIR)dskdefs.h $(INCDIR)initkbddefs.h $(INCDIR)perrnodefs.h \
915915
$(INCDIR)ufsdefs.h

inc/dirdefs.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ typedef struct dfinfo {
5858
} DFINFO;
5959

6060
#ifdef DOS
61-
int make_old_version(char *old, char *file);
61+
int make_old_version(char *old, size_t oldsize, char *file);
6262
#endif
6363
#ifdef FSDEBUG
6464
void print_finfo(FINFO *fp);

inc/dskdefs.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ LispPTR COM_writepage(LispPTR *args);
1919
LispPTR COM_truncatefile(LispPTR *args);
2020
LispPTR COM_changedir(LispPTR *args);
2121
LispPTR COM_getfreeblock(LispPTR *args);
22-
void separate_version(char *name, char *ver, int checkp);
22+
void conc_dir_and_name(char *dir, char *name, char *fname, size_t fname_size);
23+
void conc_name_and_version(char *name, char *ver, char *rname, size_t rname_size);
24+
void separate_version(char *name, size_t namesize, char *ver, size_t versize, int checkp);
2325
int unpack_filename(char *file, char *dir, char *name, char *ver, int checkp);
24-
int true_name(char *path);
26+
int true_name(char *path, size_t pathsize);
2527
#endif

inc/lispver2.h

Lines changed: 0 additions & 74 deletions
This file was deleted.

inc/locfile.h

Lines changed: 4 additions & 170 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
#define PROTECTION (S_POSITIVE | 6)
3636
#define EOL (S_POSITIVE | 7)
3737
#define ALL (S_POSITIVE | 8)
38+
#define INODE_LO (S_POSITIVE | 9)
39+
#define INODE_HI (S_POSITIVE | 10)
3840

3941
#define ToLispTime(x) ((int)(x) + 29969152)
4042
/* For getfileinfo. For WDATE&RDATE */
@@ -310,178 +312,10 @@ do { \
310312
/* * * * * it gave "Too many characters in a character constant" errors! */
311313
#include "lispver1.h"
312314
#else /* DOS */
313-
/* NON-DOS version of the macro LispVersionToUnixVersion */
314-
#include "lispver2.h"
315+
/* NON-DOS version is inline in ufs.c */
315316
#endif /* DOS */
316317

317-
318-
/*
319-
* Name: UnixVersionToLispVersion
320-
*
321-
* Argument: char *pathname
322-
* UNIX syntax pathname.
323-
* int vlessp
324-
* If 0, versionless file is converted to version 1.
325-
* Otherwise, remains as versionless.
326-
*
327-
* Value: On success returns 1, otherwise 0.
328-
*
329-
* Side Effect: The version part of pathname is destructively modified.
330-
*
331-
* Description:
332-
*
333-
* Destructively modifies the version part of pathname which is following the
334-
* UNIX file naming convention to Xerox Lisp one.
335-
* This macro should be called, in the routines which convert the UNIX pathname
336-
* to Lisp one, just before it returns the result to Lisp, because converting
337-
* version field will append a semicolon which may confuse the routine
338-
* The file which does not have a valid version field, that is ".~##~" form, is
339-
* dealt with as version 1.
340-
*/
341-
342-
#define UnixVersionToLispVersion(pathname, vlessp) do { \
343-
\
344-
char *start; \
345-
char *end; \
346-
char *lf_cp; \
347-
int ver_no; \
348-
size_t len; \
349-
char ver_buf[VERSIONLEN]; \
350-
\
351-
if ((start = strchr(pathname, '~')) != NULL) { \
352-
/* First of all, find the version field in pathname. */ \
353-
end = start; \
354-
lf_cp = start + 1; \
355-
while (*lf_cp) { \
356-
if (*lf_cp == '~') { \
357-
start = end; \
358-
end = lf_cp; \
359-
lf_cp++; \
360-
} else { \
361-
lf_cp++; \
362-
} \
363-
} \
364-
\
365-
if (start != end && *(start - 1) == '.' && end == (lf_cp - 1)) { \
366-
/* \
367-
* pathname ends in the form ".~###~". But we \
368-
* check ### is a valid number or not. \
369-
*/ \
370-
len = (end - start) - 1; \
371-
strncpy(ver_buf, start + 1, len); \
372-
ver_buf[len] = '\0'; \
373-
NumericStringP(ver_buf, YES, NO); \
374-
YES: \
375-
*(start - 1) = ';'; \
376-
*start = '\0'; \
377-
*end = '\0'; \
378-
/* call strtoul() to eliminate leading 0s. */ \
379-
ver_no = strtoul(start + 1, (char **)NULL, 10); \
380-
sprintf(ver_buf, "%u", ver_no); \
381-
strcat(pathname, ver_buf); \
382-
goto CONT; \
383-
\
384-
NO: \
385-
/* Dealt with as version 1 unless vlessp */ \
386-
if (!(vlessp)) strcat(pathname, ";1"); \
387-
CONT: \
388-
lf_cp--; /* Just for label */ \
389-
} else { \
390-
/* Dealt with as version 1 unless vlessp. */ \
391-
if (!(vlessp)) strcat(pathname, ";1"); \
392-
} \
393-
} else { \
394-
/* Dealt with as version 1 unless vlessp. */ \
395-
if (!(vlessp)) strcat(pathname, ";1"); \
396-
} \
397-
} while (0)
398-
399-
/*
400-
* Name: ConcDirAndName
401-
*
402-
* Argument: char *dir The name of the directory.
403-
* char *name The name of a file.
404-
* char *fname The place where the full file name should be
405-
* stored.
406-
* Value: N/A
407-
*
408-
* Side Effect: fname is replaced with the full file name.
409-
*
410-
* Description:
411-
*
412-
* Concatenate the directory name and root file name. Checks if dir contains
413-
* the trail directory delimiter or not.
414-
*
415-
*/
416-
417-
#define ConcDirAndName(dir, name, fname) do { \
418-
\
419-
char *lf_cp1, *lf_cp2; \
420-
\
421-
lf_cp1 = dir; \
422-
lf_cp2 = dir; \
423-
\
424-
while (*lf_cp2 != '\0') { \
425-
switch (*lf_cp2) { \
426-
\
427-
case '/': \
428-
lf_cp1 = lf_cp2; \
429-
lf_cp2++; \
430-
break; \
431-
\
432-
default: \
433-
lf_cp2++; \
434-
break; \
435-
} \
436-
} \
437-
if (lf_cp1 == (lf_cp2 - 1)) { \
438-
if (lf_cp1 == (dir)) { \
439-
/* dir is a root directory. */ \
440-
strcpy(fname, "/"); \
441-
strcat(fname, name); \
442-
} else { \
443-
/* The trail directory is included. */ \
444-
strcpy(fname, dir); \
445-
strcat(fname, name); \
446-
} \
447-
} else { \
448-
/* The trail directory is not included */ \
449-
strcpy(fname, dir); \
450-
strcat(fname, "/"); \
451-
strcat(fname, name); \
452-
} \
453-
} while (0)
454-
455-
/*
456-
* Name: ConcNameAndVersion
457-
*
458-
* Argument: char *name The root file name.
459-
* char *ver The file version.
460-
* char *rname The place where the concatenated file name will be
461-
* stored.
462-
* Value: N/A
463-
*
464-
* Side Effect: rname is replaced with the concatenated file name.
465-
*
466-
* Description:
467-
*
468-
* Concatenate the root file name and its version in UNIX format.
469-
*
470-
*/
471-
472-
#define ConcNameAndVersion(name, ver, rname) do { \
473-
if (*(ver) != '\0') { \
474-
strcpy(rname, name); \
475-
strcat(rname, ".~"); \
476-
strcat(rname, ver); \
477-
strcat(rname, "~"); \
478-
} else { \
479-
strcpy(rname, name); \
480-
} \
481-
} while (0)
482-
483-
#define VERSIONLEN 16
484-
318+
#define VERSIONLEN 24
485319
#define MAXVERSION 999999999
486320

487321
#define LASTVERSIONARRAY ((unsigned) -1)

0 commit comments

Comments
 (0)