bin/80732

Rostislav Krasny rosti.bsd at gmail.com
Thu May 26 18:30:07 PDT 2005


The following reply was made to PR bin/80732; it has been noted by GNATS.

From: Rostislav Krasny <rosti.bsd at gmail.com>
To: Maxim Konovalov <maxim at macomnet.ru>
Cc: bug-followup at freebsd.org
Subject: Re: bin/80732
Date: Fri, 27 May 2005 04:22:06 +0200

 This is a multi-part message in MIME format.
 --------------070103080705040905030601
 Content-Type: text/plain; charset=us-ascii; format=flowed
 Content-Transfer-Encoding: 7bit
 
 Maxim Konovalov wrote:
 > Why didn't you check the return code from malloc(3) and read(2)?
 > Could you please fix that?  Could you remove all style(9) changes
 > from your diff?
 
 Fixed. Thank you for the comment. New diff of telnetd(8) is attached to 
 this email (inline).
 
 P.S. The original diff of getty(8) doesn't need any change so far.
 
 --------------070103080705040905030601
 Content-Type: text/plain;
  name="telnetd2.patch"
 Content-Transfer-Encoding: 7bit
 Content-Disposition: inline;
  filename="telnetd2.patch"
 
 diff -ur telnetd.orig/ext.h /usr/src/contrib/telnet/telnetd/ext.h
 --- telnetd.orig/ext.h	Sat Dec  1 00:28:07 2001
 +++ /usr/src/contrib/telnet/telnetd/ext.h	Thu May 26 23:37:30 2005
 @@ -112,8 +112,7 @@
  #endif
  	process_slc(unsigned char, unsigned char, cc_t),
  	ptyflush(void),
 -	putchr(int),
 -	putf(char *, char *),
 +	putf(char *, char *, size_t),
  	recv_ayt(void),
  	send_do(int, int),
  	send_dont(int, int),
 diff -ur telnetd.orig/telnetd.c /usr/src/contrib/telnet/telnetd/telnetd.c
 --- telnetd.orig/telnetd.c	Sun Feb 13 15:17:23 2005
 +++ /usr/src/contrib/telnet/telnetd/telnetd.c	Fri May 27 03:00:29 2005
 @@ -42,7 +42,6 @@
  #include "telnetd.h"
  #include "pathnames.h"
  
 -#include <sys/mman.h>
  #include <err.h>
  #include <libutil.h>
  #include <paths.h>
 @@ -740,6 +739,7 @@
  	char *HE;
  	char *HN;
  	char *IM;
 +	char *IF;
  	int nfd;
  
  	/*
 @@ -904,18 +904,39 @@
  
  		HE = Getstr("he", &cp);
  		HN = Getstr("hn", &cp);
 -		IM = Getstr("im", &cp);
 +		IF = Getstr("if", &cp);
  		if (HN && *HN)
  			(void) strlcpy(host_name, HN, sizeof(host_name));
 -		if (IM == 0)
 -			IM = strdup("");
 +		if (IF != NULL) {
 +			int if_fd;
 +
 +			if ((if_fd = open(IF, O_RDONLY)) != -1) {
 +				struct stat if_fst;
 +				ssize_t if_r;
 +
 +				fstat(if_fd, &if_fst);
 +				IM = malloc(if_fst.st_size + 1);
 +				if (IM != NULL) {
 +					if_r = read(if_fd, IM, if_fst.st_size);
 +					IM[(if_r != -1)? if_r : 0] = 0;
 +				}
 +				close(if_fd);
 +			} else {
 +				IF = NULL;
 +			}
 +		}
 +		if (IF == NULL) {
 +			IM = Getstr("im", &cp);
 +			if (IM == NULL)
 +				IM = strdup("");
 +		}
  	} else {
  		IM = strdup(DEFAULT_IM);
  		HE = 0;
  	}
  	edithost(HE, host_name);
  	if (hostinfo && *IM)
 -		putf(IM, ptyibuf2);
 +		putf(IM, ptyibuf2, BUFSIZ);
  
  	if (pcc)
  		(void) strncat(ptyibuf2, ptyip, pcc+1);
 diff -ur telnetd.orig/utility.c /usr/src/contrib/telnet/telnetd/utility.c
 --- telnetd.orig/utility.c	Sun May  4 05:54:49 2003
 +++ /usr/src/contrib/telnet/telnetd/utility.c	Thu May 26 23:37:42 2005
 @@ -393,22 +393,6 @@
  	editedhost[sizeof editedhost - 1] = '\0';
  }
  
 -static char *putlocation;
 -
 -static void
 -putstr(const char *s)
 -{
 -
 -	while (*s)
 -		putchr(*s++);
 -}
 -
 -void
 -putchr(int cc)
 -{
 -	*putlocation++ = cc;
 -}
 -
  #ifdef __FreeBSD__
  static char fmtstr[] = { "%+" };
  #else
 @@ -416,11 +400,12 @@
  #endif
  
  void
 -putf(char *cp, char *where)
 +putf(char *cp, char *where, size_t where_size)
  {
  	char *slash;
  	time_t t;
  	char db[100];
 +	char ch_str[2] = {0, 0};
  #ifdef __FreeBSD__
  	static struct utsname kerninfo;
  
 @@ -428,19 +413,13 @@
  		uname(&kerninfo);
  #endif
  
 -	putlocation = where;
 -
  	while (*cp) {
  		if (*cp =='\n') {
 -			putstr("\r\n");
 -			cp++;
 -			continue;
 +			strlcat(where, "\r\n", where_size);
  		} else if (*cp != '%') {
 -			putchr(*cp++);
 -			continue;
 -		}
 -		switch (*++cp) {
 -
 +			*ch_str = *cp;
 +			strlcat(where, ch_str, where_size);
 +		} else switch (*++cp) {
  		case 't':
  #ifdef	STREAMSPTY
  			/* names are like /dev/pts/2 -- we want pts/2 */
 @@ -448,14 +427,14 @@
  #else
  			slash = strrchr(line, '/');
  #endif
 -			if (slash == (char *) 0)
 -				putstr(line);
 +			if (slash == NULL)
 +				strlcat(where, line, where_size);
  			else
 -				putstr(&slash[1]);
 +				strlcat(where, &slash[1], where_size);
  			break;
  
  		case 'h':
 -			putstr(editedhost);
 +			strlcat(where, editedhost, where_size);
  			break;
  
  		case 'd':
 @@ -464,30 +443,34 @@
  #endif
  			(void)time(&t);
  			(void)strftime(db, sizeof(db), fmtstr, localtime(&t));
 -			putstr(db);
 +			strlcat(where, db, where_size);
  			break;
  
  #ifdef __FreeBSD__
  		case 's':
 -			putstr(kerninfo.sysname);
 +			strlcat(where, kerninfo.sysname, where_size);
  			break;
  
  		case 'm':
 -			putstr(kerninfo.machine);
 +			strlcat(where, kerninfo.machine, where_size);
  			break;
  
  		case 'r':
 -			putstr(kerninfo.release);
 +			strlcat(where, kerninfo.release, where_size);
  			break;
  
  		case 'v':
 -			putstr(kerninfo.version);
 +			strlcat(where, kerninfo.version, where_size);
  			break;
  #endif
  
  		case '%':
 -			putchr('%');
 +			*ch_str = '%';
 +			strlcat(where, ch_str, where_size);
  			break;
 +
 +		case 0:
 +			return;
  		}
  		cp++;
  	}
 
 --------------070103080705040905030601--


More information about the freebsd-bugs mailing list