[net.bugs.usg] More null pointer follies in PWB/Graphics

guy@sun.uucp (Guy Harris) (07/21/85)

The same code fragment that was in those "stat" routines is also in a number
of other commands, so the plague was spread there also.  Here's the fixes:

*** dev.d/hp7220.d/hpd.d/dev.c.BAK	Thu May  2 10:08:14 1985
--- dev.d/hp7220.d/hpd.d/dev.c	Sat Jul 20 17:23:03 1985
***************
*** 100,106
  	if(argc<=1 ) argc=2,argf=0; /* no args,use stdin */
  	else argf=1;
  	while(argc-->1){
! 		if(strcmp(*++argv,"-")==0 || !argf) fpi=stdin;
  		else if( **argv != '-') {
  			if((fpi=fopen(*argv,"r"))==NULL) {
  				ERRPR1(cannot open %s, *argv);

--- 100,106 -----
  	if(argc<=1 ) argc=2,argf=0; /* no args,use stdin */
  	else argf=1;
  	while(argc-->1){
! 		if(!argf || strcmp(*++argv,"-")==0) fpi=stdin;
  		else if( **argv != '-') {
  			if((fpi=fopen(*argv,"r"))==NULL) {
  				ERRPR1(cannot open %s, *argv);

*** dev.d/tek4000.d/td.d/dev.c.BAK	Thu May  2 10:08:47 1985
--- dev.d/tek4000.d/td.d/dev.c	Sat Jul 20 17:29:57 1985
***************
*** 70,76
  	if(argc<=1 ) argc=2,argf=0; /* no args,use stdin */
  	else argf=1;
  	while(argc-->1){
! 		if(strcmp(*++argv,"-")==0 || !argf) fpi=stdin;
  		else if( **argv != '-') {
  			if((fpi=fopen(*argv,"r"))==NULL) {
  				ERRPR1(cannot open %s, *argv);

--- 70,76 -----
  	if(argc<=1 ) argc=2,argf=0; /* no args,use stdin */
  	else argf=1;
  	while(argc-->1){
! 		if(!argf || strcmp(*++argv,"-")==0) fpi=stdin;
  		else if( **argv != '-') {
  			if((fpi=fopen(*argv,"r"))==NULL) {
  				ERRPR1(cannot open %s, *argv);

*** gutil.d/gtop.d/gtop.c.BAK	Thu May  2 10:09:14 1985
--- gutil.d/gtop.d/gtop.c	Sat Jul 20 17:31:30 1985
***************
*** 64,70
  	else argf=1;
  
  	while(argc-- > 1) {
! 		if( strcmp(*++argv,"-")==0 || !argf ) fpi=stdin;
  		else if( **argv!='-' ) {
  			if( (fpi=fopen(*argv,"r"))==NULL ) {
  				ERRPR1(cannot open %s, *argv);

--- 64,70 -----
  	else argf=1;
  
  	while(argc-- > 1) {
! 		if( !argf || strcmp(*++argv,"-")==0 ) fpi=stdin;
  		else if( **argv!='-' ) {
  			if( (fpi=fopen(*argv,"r"))==NULL ) {
  				ERRPR1(cannot open %s, *argv);

*** gutil.d/gd.c.BAK	Thu May  2 10:09:20 1985
--- gutil.d/gd.c	Sat Jul 20 17:32:17 1985
***************
*** 32,38
  	else argf=1;
  
  	while(argc-- > 1) {
! 		if( strcmp(*++argv,"-")==0 || !argf ) fpi=stdin;
  		else if( **argv!='-' ) {
  			if( (fpi=fopen(*argv,"r"))==NULL ) {
  				ERRPR1(cannot open %s, *argv);

--- 32,38 -----
  	else argf=1;
  
  	while(argc-- > 1) {
! 		if( !argf || strcmp(*++argv,"-")==0 ) fpi=stdin;
  		else if( **argv!='-' ) {
  			if( (fpi=fopen(*argv,"r"))==NULL ) {
  				ERRPR1(cannot open %s, *argv);

*** gutil.d/pd.c.BAK	Thu May  2 10:09:20 1985
--- gutil.d/pd.c	Sat Jul 20 17:32:43 1985
***************
*** 30,36
  	else argf=1;
  
  	while(argc-- > 1) {
! 		if( strcmp(*++argv,"-")==0 || !argf ) fpi=stdin;
  		else if( **argv!='-' ) {
  			if((fpi =fopen(*argv,"r")) == NULL) continue;
  		} else { argc++; continue; }

--- 30,36 -----
  	else argf=1;
  
  	while(argc-- > 1) {
! 		if( !argf || strcmp(*++argv,"-")==0 ) fpi=stdin;
  		else if( **argv!='-' ) {
  			if((fpi =fopen(*argv,"r")) == NULL) continue;
  		} else { argc++; continue; }

*** tod.d/vtoc.d/vtoc.c.BAK	Sat Jul 20 17:47:19 1985
--- tod.c/vtoc.d/vtoc.c	Sat Jul 20 17:47:34 1985
***************
*** 64,70
  	if( argc==1 ) argc=2, argf=0; /* no args, use stdin */
  	else argf=1;
  	while (argc-- > 1){
! 		if(strcmp(*++argv,"-") == 0 || !argf) *argv="-";
  		else if(**argv != '-') {
  			if(access(*argv,0) != NULL){
  				ERRPR1(cannot access %s, *argv);

--- 64,70 -----
  	if( argc==1 ) argc=2, argf=0; /* no args, use stdin */
  	else argf=1;
  	while (argc-- > 1){
! 		if(!argf || strcmp(*++argv,"-") == 0) c="-";
  		else if(**argv != '-') {
  			if(access(*argv,0) != NULL){
  				ERRPR1(cannot access %s, *argv);
***************
*** 70,75
  				ERRPR1(cannot access %s, *argv);
  				continue;
  			}
  		} else	{ argc++; continue; }
  
  		mktemp(tempfile);

--- 70,76 -----
  				ERRPR1(cannot access %s, *argv);
  				continue;
  			}
+ 			c = *argv;
  		} else	{ argc++; continue; }
  
  		mktemp(tempfile);
***************
*** 73,79
  		} else	{ argc++; continue; }
  
  		mktemp(tempfile);
! 		sprintf(command,"cat %s|/usr/bin/graf/remcom>%s",*argv,tempfile);
  		system(command);
  		if((fpi=fopen(tempfile,"r")) == NULL) {
  			ERRPR1(cannot open %s,tempfile);

--- 74,80 -----
  		} else	{ argc++; continue; }
  
  		mktemp(tempfile);
! 		sprintf(command,"cat %s|/usr/bin/graf/remcom>%s",c,tempfile);
  		system(command);
  		if((fpi=fopen(tempfile,"r")) == NULL) {
  			ERRPR1(cannot open %s,tempfile);

How about we change the machine whose UNIX port is the basis for all the
USDL systems from a 3B2 to a modified PDP-1?  It's a ones-complement, 18-bit
machine, so that should trip up some code right there.  We add
byte-addressing *but* use the upper-half of a 36-bit double word for the
byte offset, so sizeof(int) != sizeof(char *) and sizeof(char *) !=
sizeof(anything_else *).  Then we give it an MMU so it can run UNIX, and
then map location 0777777 out of the address space *and* use that value for
null pointers.  That way, null pointers will 1) not have an all-zero
representation and 2) not be dereferencable.  If your code works on that
machine, it'll probably work on just about *anything*.  Much better than
using a warmed-over VAX which permits people to keep all the bad habits they
learned on their VAXes at school...  (only 1/2 :-), if that much)

	Guy Harris

guy@sun.uucp (Guy Harris) (07/21/85)

Whoops, here's one I missed.  Note that for all of these, your line numbers
may differ:

*** gutil.d/ptog.d/ptog.c.BAK	Thu May  2 10:09:18 1985
--- gutil.d/ptog.d/ptog.c	Sat Jul 20 18:09:39 1985
***************
*** 48,54
  	else argf=1;
  
  	while(argc-- > 1) {
! 		if( strcmp(*++argv,"-")==0 || !argf ) fpi=stdin;
  		else if( **argv!='-' ) {
  			if((fpi =fopen(*argv,"r")) == NULL) continue;
  		} else { argc++; continue; }

--- 48,54 -----
  	else argf=1;
  
  	while(argc-- > 1) {
! 		if( !argf || strcmp(*++argv,"-")==0 ) fpi=stdin;
  		else if( **argv!='-' ) {
  			if((fpi =fopen(*argv,"r")) == NULL) continue;
  		} else { argc++; continue; }