[117] in Zephyr_Comments

home help back first fref pref prev next nref lref last post

two bugs with zwrite and a patch

daemon@ATHENA.MIT.EDU (jik@ATHENA.MIT.EDU)
Tue Oct 25 03:33:43 1988

From: <jik@ATHENA.MIT.EDU>
Date: Tue, 25 Oct 88 03:33:26 EDT
To: zephyr-comments@ATHENA.MIT.EDU

While playing around with trying to make the signature field to what
it's supposed to, I discovered two bugs in the sources to zwrite.

1. In the code which reads a message from stdin, if the message is
   empty after the first line is read, then the command
   malloc((unsigned)(msgsize+strlen(bfr))) is used to allocate space.
   The "msgsize+" is unnecessary, since the message has to be empty.
2. In the same message-reading code, the final null tacked onto the
   end of the code is NOT made part of the message, since msgsize is
   not incremented after adding the null.

A context diff is displayed below for installation into the sources.

***************
*** 213,224 ****
  			message = realloc(message,
  					  (unsigned)(msgsize+strlen(bfr)));
  		else
! 			message = malloc((unsigned)(msgsize+strlen(bfr)));
  		(void) strcpy(message+msgsize, bfr);
  		msgsize += strlen(bfr);
  	    }
  	    message = realloc(message, (unsigned)(msgsize+1));
  	    message[msgsize] = '\0';
  	}
  	else {	/* Use read so you can send binary messages... */
  	    while (nchars = read(fileno(stdin), bfr, sizeof bfr)) {
--- 213,225 ----
  			message = realloc(message,
  					  (unsigned)(msgsize+strlen(bfr)));
  		else
! 			message = malloc((unsigned)(strlen(bfr)));
  		(void) strcpy(message+msgsize, bfr);
  		msgsize += strlen(bfr);
  	    }
  	    message = realloc(message, (unsigned)(msgsize+1));
  	    message[msgsize] = '\0';
+ 	    msgsize += 1;
  	}
  	else {	/* Use read so you can send binary messages... */
  	    while (nchars = read(fileno(stdin), bfr, sizeof bfr)) {

		      *************************

  --> Jonathan Kamens
      Project Athena Watchmaker
      SIPB (Student Information Processing Board) Member
      Volunteer OLC Consultant
      jik@ATHENA.MIT.EDU

home help back first fref pref prev next nref lref last post