Skip to content

Commit

Permalink
CWEB - release 4.10, 2023-08-19.
Browse files Browse the repository at this point in the history
Fixes:

* Fix issue #43: 'out_buf' overflow on malign user input
  - Handle border case from bug report
  - Discard rest of input lines exceeding 'buf_size' characters
  - Purge 'ungetc' from the TeX part as well
* Fix typo in 'examples/wordtest.w' (reported by DEK)
* 'Ilk' is of type 'eight_bits'
* Avoid over-/underflow of section depth with malicious user input

Internal changes:

* Unroll 'init_p' helper function in COMMON
  - it is used for CWEAVE only (and CTWILL downstream)
* Match 'common.w' and 'common.h'
  - Reshuffle declarations and some code sections
  - Add starred section titles
* Demote all starred sections in 'common.w' (single star)
* Code cleanup
  - Make 'pop_level' a simple macro in CWEAVE
  - Use structure assignment (as in CTANGLE)
  - More compact 'stack' handling
  - Make use of type 'mode'
  - Purge a few 'goto' statements (and add some others)
  - Replace some 'sprintf' with 'snprintf'
  - Syntactic sugar for functional macros
  - Straighten 'byte_start' arithmetic
  - Desolve former section 19 of CWEAVE with internal array sizes
  - Hide 'print_text' analytics function from C compiler with DEBUG
  - Streamline 'phase_two' of CTANGLE
  - Refurbish 'phase_three' of CWEAVE
* Insert blank line after '\ch' in TeX output (cf. CWEB 3.0)

Macro changes

* Cleanup some '\acro' macros in 'cwebmac.tex'
  • Loading branch information
ascherer committed Aug 19, 2023
1 parent 6bf6138 commit 6007f47
Show file tree
Hide file tree
Showing 30 changed files with 799 additions and 797 deletions.
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ testthings.w export-ignore
indentation.w export-ignore
if.w export-ignore
grün.w export-ignore
out_buf-overflow.w export-ignore
section_depth.w export-ignore
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This file is part of CWEB.
# It is distributed WITHOUT ANY WARRANTY, express or implied.
# Version 4.9 --- May 2023
# Version 4.10 --- August 2023

# Copyright (C) 1987,1990,1993,2000 Silvio Levy and Donald E. Knuth

Expand Down Expand Up @@ -205,6 +205,6 @@ tarball:
tar zcvhf /tmp/cweb.tgz $(ALL) examples

ctan:
git archive -o ~/cweb-4.9.zip --prefix=cweb/ cweb-4.9
git archive -o ~/cweb-4.10.zip --prefix=cweb/ cweb-4.10
make PDF=pdf usermanual
cd ..; zip -r ~/cweb-4.9.zip cweb/cwebman.pdf
cd ..; zip -r ~/cweb-4.10.zip cweb/cwebman.pdf
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# cweb 4.9
# cweb 4.10

people have been accumulating several decades of experience with
[cweb](http://www-cs-faculty.stanford.edu/~uno/cweb.html), and we know that
Expand All @@ -15,7 +15,7 @@ details in the
[releases description](https://github.com/ascherer/cweb/releases).

you can either compile these sources as directed in the
[readme file](README) or stick the recent version “cweb-4.9” into my
[readme file](README) or stick the recent version “cweb-4.10” into my
[cwebbin](https://github.com/ascherer/cwebbin), which introduces convenient
extensions and prepares cweb for inclusion in the “tex live” distribution.

Expand All @@ -27,8 +27,11 @@ incomplete – repository of original release versions of levy/knuth

## call for help

recently i spotted versions 2.7 and 2.8 in
[utah](http://ftp.math.utah.edu/pub/tex/pub/cweb/) – and there's even "the"
recently i spotted versions 0.5, 2.7, and 2.8 in
[utah](http://ftp.math.utah.edu/pub/tex/pub/cweb/),
version 2.0/2.1 in
[Fred Fish's Disk 551](https://ftp.funet.fi/pub/amiga/fish/501-600/ff551/),
– and there's even "the"
[original cweb 2.8](http://ftp.cs.stanford.edu/pub/cweb2.8) in stanford –, but
the intermediate versions 3.0 and 3.1 are still missing in my collection. i
could scrape them from
Expand Down
12 changes: 6 additions & 6 deletions comm-bs.ch
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ by using "huge" pointers.
(Update attempt by Andreas Scherer, 31 Jan 2021. Good luck!)


@x Section 9.
for section names */
@x Section 10.
@d ilk dummy.Ilk /* used by \.{CWEAVE} only */

@<Common code...@>=
typedef struct name_info {
Expand All @@ -25,7 +25,7 @@ typedef struct name_info {
union {
struct name_info *Rlink; /* right link in binary search tree for section
names */
char Ilk; /* used by identifiers in \.{CWEAVE} only */
eight_bits Ilk; /* used by identifiers in \.{CWEAVE} only */
} dummy;
void *equiv_or_xref; /* info corresponding to names */
} name_info; /* contains information about an identifier or section name */
Expand All @@ -34,7 +34,7 @@ typedef name_pointer *hash_pointer;
extern char byte_mem[]; /* characters of names */
extern char *byte_mem_end; /* end of |byte_mem| */
@y
for section names */
@d ilk dummy.Ilk /* used by \.{CWEAVE} only */

@f huge extern

Expand All @@ -45,7 +45,7 @@ typedef struct name_info {
union {
struct name_info *Rlink; /* right link in binary search tree for section
names */
char Ilk; /* used by identifiers in \.{CWEAVE} only */
eight_bits Ilk; /* used by identifiers in \.{CWEAVE} only */
} dummy;
union {
void huge* equiv_member;
Expand All @@ -59,7 +59,7 @@ extern char huge* byte_mem_end; /* end of |byte_mem| */
@z


@x Section 39.
@x Section 36.
cur_file_name[l]='/'; /* \UNIX/ pathname separator */
@y
cur_file_name[l]='/'; /* A valid {\mc MSDOS} pathname separator */
Expand Down
42 changes: 21 additions & 21 deletions comm-mac.ch
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ No changes to CTANGLE or CWEAVE are needed.
(Contributed 13 Oct 2000 by [email protected]; slightly edited by Don Knuth)
@x in limbo, change the title page document to specify Mac version
\centerline{(Version 4.9)}
\centerline{(Version 4.10)}
@y
\centerline{(Version 4.9 for MacOS)}
\centerline{(Version 4.10 for MacOS)}
@z
@x section 23: Make input_ln accept \n, \r, \n\r, or \r\n as line endings
@ In the unlikely event that your standard I/O library does not
support |feof|, |getc|, and |ungetc| you may have to change things here.
support |feof| and |getc| you may have to change things here.
@^system dependencies@>
@c
Expand All @@ -24,9 +24,9 @@ FILE *fp) /* what file to read from */
limit = k = buffer; /* beginning of buffer */
while (k<=buffer_end && (c=getc(fp)) != EOF && c!='\n')
if ((*(k++) = c) != ' ') limit = k;
if (k>buffer_end)
if ((c=getc(fp))!=EOF && c!='\n') {
ungetc(c,fp); loc=buffer; err_print("! Input line too long");
if (k>buffer_end) {
while ((c=getc(fp))!=EOF && c!='\n'); /* discard rest of line */
loc=buffer; err_print("! Input line too long");
@.Input line too long@>
}
if (c==EOF && limit==buffer) return false; /* there was nothing after
Expand Down Expand Up @@ -61,7 +61,7 @@ FILE *fp) /* what file to read from */
return true;
}
else if (k>buffer_end) {
ungetc(c,fp); loc=buffer; err_print("! Input line too long");
while ((c=getc(fp))!=EOF && c!='\n' && c!='\r'); /* discard rest of line */
return true;
@.Input line too long@>
}
Expand All @@ -81,17 +81,7 @@ FILE *fp) /* what file to read from */
@<Skip over comment lines in the change file; |return| if end of file@>@;
@z

@x section 36, don't try to open a change file if none was specified
if ((change_file=fopen(change_file_name,"r"))==NULL)
fatal("! Cannot open change file ", change_file_name);
@y
if (change_file_name[0] == '\0') /* no change file specified */
change_file = NULL; /* reset at least the |change_file| */
else if ((change_file=fopen(change_file_name,"r"))==NULL)
fatal("! Cannot open change file ", change_file_name);
@z
@x section 39, declare colon as Mac's path separator
@x section 36, declare colon as Mac's path separator
(Colon-separated paths are not supported.)
The remainder of the \.{@@i} line after the file name is ignored.
Expand All @@ -104,12 +94,22 @@ The remainder of the \.{@@i} line after the file name is ignored.
@d PATH_SEP ':' /* MacOS pathname separator */
@^system dependencies@>
@z
@x section 39, use the path separator constant
@x section 36, use the path separator constant
cur_file_name[l]='/'; /* \UNIX/ pathname separator */
@y
cur_file_name[l]=PATH_SEP; /* pathname separator */
@z
@x section 41, don't try to open a change file if none was specified
if ((change_file=fopen(change_file_name,"r"))==NULL)
fatal("! Cannot open change file ", change_file_name);
@y
if (change_file_name[0] == '\0') /* no change file specified */
change_file = NULL; /* reset at least the |change_file| */
else if ((change_file=fopen(change_file_name,"r"))==NULL)
fatal("! Cannot open change file ", change_file_name);
@z

@x section 75, explain the convention for omitted change files
An omitted change file argument means that |"/dev/null"| should be used,
@y
Expand All @@ -134,7 +134,7 @@ An omitted change file argument means that no change file should be used,
@z

@x section 85, insert an extra module before the index
@** Index.
@* Index.
@y by putting the new module here, we preserve all the previous section numbers
@ We assume an interface to \CEE/ command-line emulation as supplied by
the |ccommand| function of Metrowerks CodeWarrior, as defined in
Expand All @@ -144,5 +144,5 @@ the header file \.{console.h}.
#include <console.h>
@^system dependencies@>

@** Index.
@* Index.
@z
32 changes: 14 additions & 18 deletions comm-ql.ch
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,24 @@ ex <dev_>cc;'-v -h -c -=500000 -DCWEBINPUTS=flp2_ common_c'
@x
\def\v{\char'174} % vertical (|) in typewriter font

\def\title{Common code for CTANGLE and CWEAVE (Version 4.9)}
\def\title{Common code for CTANGLE and CWEAVE (Version 4.10)}
\def\topofcontents{\null\vfill
\centerline{\titlefont Common code for {\ttitlefont CTANGLE} and
{\ttitlefont CWEAVE}}
\vskip 15pt
\centerline{(Version 4.9)}
\centerline{(Version 4.10)}
\vfill}
\def\botofcontents{\vfill
\noindent
@y
\def\v{\char'174} % vertical (|) in typewriter font
\def\title{Common code for CTANGLE and CWEAVE (QL Version 4.9)}
\def\title{Common code for CTANGLE and CWEAVE (QL Version 4.10)}
\def\topofcontents{\null\vfill
\centerline{\titlefont Common code for {\ttitlefont CTANGLE} and
{\ttitlefont CWEAVE}}
\vskip 15pt
\centerline{(Version 4.9)}
\centerline{(Version 4.10)}
\vfill}
\def\botofcontents{\vfill
\noindent
Expand Down Expand Up @@ -212,17 +212,15 @@ the routine as if it would work.
@<Complain about argument length@>@;
if (dot_pos==NULL) {
sprintf(tex_file_name,"%s.tex",*argv);
sprintf(idx_file_name,"%s.idx",*argv);
sprintf(scn_file_name,"%s.scn",*argv);
sprintf(C_file_name,"%s.c",*argv);
} else {
strcpy(tex_file_name,*argv);
strcpy(C_file_name,*argv);
if (make_xrefs) { /* indexes will be generated */
*dot_pos='\0';
sprintf(idx_file_name,"%s.idx",*argv);
sprintf(scn_file_name,"%s.scn",*argv);
}
*dot_pos='\0'; /* string now ends where the dot was */
}
if (make_xrefs) { /* indexes will be generated */
sprintf(idx_file_name,"%s.idx",*argv);
sprintf(scn_file_name,"%s.scn",*argv);
}
found_out=true;
}
Expand All @@ -233,17 +231,15 @@ the routine as if it would work.
@<Complain about argument length@>;
if (dot_pos==NULL) {
sprintf(tex_file_name,"%s_tex",*argv);
sprintf(idx_file_name,"%s_idx",*argv);
sprintf(scn_file_name,"%s_scn",*argv);
sprintf(C_file_name,"%s_c",*argv);
} else {
strcpy(tex_file_name,*argv);
strcpy(C_file_name,*argv);
if (make_xrefs) { /* indexes will be generated */
*dot_pos='\0';
sprintf(idx_file_name,"%s_idx",*argv);
sprintf(scn_file_name,"%s_scn",*argv);
}
*dot_pos='\0'; /* string now ends where the dot was */
}
if (make_xrefs) { /* indexes will be generated */
sprintf(idx_file_name,"%s_idx",*argv);
sprintf(scn_file_name,"%s_scn",*argv);
}
found_out=true;
}
Expand Down
4 changes: 2 additions & 2 deletions comm-vms.ch
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ null device |"NL:"| should be used, when no changes are desired.
@z

@x section 85 (01-FEB-1992 ST)
@** Index.
@* Index.
@y
@* VAX/VMS specific code.
We have used |SS$_NORMAL| and |SS$_ABORT| as return codes,
Expand All @@ -84,5 +84,5 @@ so we have to include the system message codes.
@<Include files@>=
#include ssdef /* we need VAX/VMS system messages */

@** Index.
@* Index.
@z
12 changes: 3 additions & 9 deletions comm-w32.ch
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,10 @@ header files to be safe.
Admittedly, this is not vital for cweb, except that I build the whole texlive
set of programs using the __fastcall convention.
@x
extern boolean names_match(name_pointer,const char *,size_t,eight_bits);@/
@x section 11
extern boolean names_match(name_pointer,const char *,size_t,eight_bits);
@y
extern boolean __cdecl names_match(name_pointer,const char *,size_t,eight_bits);@/
@z
@x
extern void init_p(name_pointer,eight_bits);@/
@y
extern void __cdecl init_p(name_pointer,eight_bits);@/
extern boolean __cdecl names_match(name_pointer,const char *,size_t,eight_bits);
@z
@x section 75
Expand Down
Loading

0 comments on commit 6007f47

Please sign in to comment.