bin/63197: tftp Bus error, core dumped

Alex Vasylenko lxv at omut.org
Sat Mar 8 06:30:03 UTC 2008


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

From: Alex Vasylenko <lxv at omut.org>
To: bug-followup at FreeBSD.org, freebsd at nbritton.org
Cc: Gavin Atkinson <gavin.atkinson at ury.york.ac.uk>,
        Kris Kennaway <kris at obsecurity.org>
Subject: Re: bin/63197: tftp Bus error, core dumped
Date: Sat, 08 Mar 2008 01:09:49 -0500

 This is a multi-part message in MIME format.
 --------------080802000805000105040905
 Content-Type: text/plain; charset=ISO-8859-1
 Content-Transfer-Encoding: 7bit
 
 Please try attached patch. It should also address the issue of empty
 history after ^C (test case: start tftp; type '?<enter>'; check history
 - command is there; ^C; check history - empty)
 
 --------------080802000805000105040905
 Content-Type: text/plain;
  name="tftp_main_c.patch"
 Content-Transfer-Encoding: 7bit
 Content-Disposition: inline;
  filename="tftp_main_c.patch"
 
 --- /usr/src/usr.bin/tftp/main.c	2003-10-11 20:27:55.000000000 -0400
 +++ main.c	2008-03-08 00:33:18.000000000 -0500
 @@ -106,7 +106,7 @@
  void	setverbose(int, char **);
  void	status(int, char **);
  
 -static void command(void) __dead2;
 +static void command(int, EditLine *, History *, HistEvent *);
  static const char *command_prompt(void);
  
  static void getusage(char *);
 @@ -161,17 +161,42 @@
  	int argc;
  	char *argv[];
  {
 +	int vrbose;
 +	EditLine *el;
 +	History *hist;
 +	HistEvent he;
 +   
  	f = -1;
  	strcpy(mode, "netascii");
  	signal(SIGINT, intr);
 +
 +	vrbose = isatty(0);
 +	el = 0;
 +	hist = 0;
 +
 +	if (vrbose) {
 +		el = el_init("tftp", stdin, stdout, stderr);
 +		hist = history_init();
 +		history(hist, &he, H_EVENT, 100);
 +		el_set(el, EL_HIST, history, hist);
 +		el_set(el, EL_EDITOR, "emacs");
 +		el_set(el, EL_PROMPT, command_prompt);
 +		el_set(el, EL_SIGNAL, 1);
 +		el_source(el, NULL);
 +	}
 +
  	if (argc > 1) {
  		if (setjmp(toplevel) != 0)
  			exit(txrx_error);
  		setpeer(argc, argv);
  	}
 -	if (setjmp(toplevel) != 0)
 +	if (setjmp(toplevel) != 0) {
 +		if (vrbose) {
 +			el_reset(el);
 +		}
  		(void)putchar('\n');
 -	command();
 +	}
 +	command(vrbose, el, hist, &he);
  }
  
  char    hostname[MAXHOSTNAMELEN];
 @@ -621,35 +646,21 @@
   * Command parser.
   */
  static void
 -command()
 +command(int vrbose, EditLine *el, History *hist, HistEvent *hep)
  {
 -	HistEvent he;
  	struct cmd *c;
 -	static EditLine *el;
 -	static History *hist;
  	const char *bp;
  	char *cp;
 -	int len, num, vrbose;
 +	int len, num;
  
 -	vrbose = isatty(0);
 -	if (vrbose) {
 -		el = el_init("tftp", stdin, stdout, stderr);
 -		hist = history_init();
 -		history(hist, &he, H_EVENT, 100);
 -		el_set(el, EL_HIST, history, hist);
 -		el_set(el, EL_EDITOR, "emacs");
 -		el_set(el, EL_PROMPT, command_prompt);
 -		el_set(el, EL_SIGNAL, 1);
 -		el_source(el, NULL);
 -	}
  	for (;;) {
  		if (vrbose) {
 -                        if ((bp = el_gets(el, &num)) == NULL || num == 0)
 -                                exit(0);
 -                        len = (num > MAXLINE) ? MAXLINE : num;
 -                        memcpy(line, bp, len);
 -                        line[len] = '\0';
 -                        history(hist, &he, H_ENTER, bp);
 +			if ((bp = el_gets(el, &num)) == NULL || num == 0)
 +				exit(0);
 +			len = (num > MAXLINE) ? MAXLINE : num;
 +			memcpy(line, bp, len);
 +			line[len] = '\0';
 +			history(hist, hep, H_ENTER, bp);
  		} else {
  			if (fgets(line, sizeof line , stdin) == 0) {
  				if (feof(stdin)) {
 
 --------------080802000805000105040905--


More information about the freebsd-bugs mailing list