Bug 137707

Summary: -CURRENT ee(1) segfaults when seeking to an out-of-bound line number
Product: Base System Reporter: deeptech71 <deeptech71>
Component: binAssignee: Xin LI <delphij>
Status: Closed FIXED    
Severity: Affects Only Me    
Priority: Normal    
Version: Unspecified   
Hardware: Any   
OS: Any   
Attachments:
Description Flags
ee.c-patch none

Description deeptech71@gmail.com 2009-08-13 01:40:08 UTC
ee(1) segfaults when the cursor is on line 1, and a command is given to jump to line number 0, or the cursor is on the last line and a command is given to jump to a higher line number (it does not segfault when the cursor is on an "inner" line).

Tested some binaries on the released ISOs as well:
8.0-BETA2 also has this issue,
7.1-RELEASE does NOT have this issue.

How-To-Repeat: 1. run ee
2. press CTRL+C
3. type any integer other than 1
Comment 1 Fredrik Lindberg 2009-08-13 10:50:42 UTC
The version of ee.c in contrib/ee initialize char *direction to NULL,
the value of this pointer is then calculated depending on if the
cursor should move up and down. Without any next lines, the pointer
is never initialized before fed to strcmp() which segfaults on
the NULL pointer.

This bug is only triggered if the cursor is at the last line and
one attempts to move down.

To minimize the changes of the contrib source it's easiest to
just initialize direction to "d", this should have no impact
as the pointer is changed when possible and moving "down" 0 lines
has no effect.

CCed the upstream author as the sources in the tree (1.5.0)
looks identical in this aspect.

Hugh, any particular reason direction isn't just a char? I might
be missing something but it seems it's only used with lines containing
one character only.

Fredrik

Program received signal SIGSEGV, Segmentation fault.
0x281a4ec8 in strcmp () from /lib/libc.so.7

#1  0x0804cda6 in goto_line (cmd_str=0x28217102 "2")
     at /usr/home/fli/work/freebsd/src/usr.bin/ee/../../contrib/ee/ee.c:2027
2027			if (!strcmp(direction, "d"))
(gdb) print direction
$1 = 0x0
(gdb) print number
$4 = 2
(gdb) print t_line->line_number
$5 = 1
(gdb) print t_line->next_line
$6 = (struct text *) 0x0
Comment 2 Alexander Best 2009-11-10 01:01:51 UTC
patch has been committed to HEAD by delphij@ (r199123).

needs to be mfc'ed to 8-stable and maybe 8.0 (if re@ approves). afaic 7-stable
and 6-stable still run ee 1.4.x. originator reports that the problem doesn't
exist in the ee 1.4 branch.

please mark pr patched.

thanks.
alex
Comment 3 Xin LI freebsd_committer freebsd_triage 2009-11-10 01:16:15 UTC
State Changed
From-To: open->patched

A patch has been committed against -HEAD to address this issue. 

The current plan is to MFC the change to 8-STABLE next week, but 
probably not 8.0-RELEASE since we are already late with the release. 


Comment 4 Xin LI freebsd_committer freebsd_triage 2009-11-10 01:16:15 UTC
Responsible Changed
From-To: freebsd-bugs->delphij

Take since I have committed the change.
Comment 5 Xin LI freebsd_committer freebsd_triage 2009-12-14 22:38:58 UTC
State Changed
From-To: patched->closed

Patch has been applied against 8-STABLE.  This is not applicable 
for 7.x so I think this ticket can be closed.
Comment 6 dfilter service freebsd_committer freebsd_triage 2009-12-14 22:39:10 UTC
Author: delphij
Date: Mon Dec 14 22:38:51 2009
New Revision: 200556
URL: http://svn.freebsd.org/changeset/base/200556

Log:
  MFC r199123:
  
  Add a minimal change to prevent NULL deference in ee(1).
  
  To repeat the problem, one can press "Ctrl+C" and then enter "0".
  
  Submitted by:   Alexander Best <alexbestms wwu de>
  PR:		bin/137707

Modified:
  stable/8/contrib/ee/ee.c
Directory Properties:
  stable/8/contrib/ee/   (props changed)

Modified: stable/8/contrib/ee/ee.c
==============================================================================
--- stable/8/contrib/ee/ee.c	Mon Dec 14 22:30:07 2009	(r200555)
+++ stable/8/contrib/ee/ee.c	Mon Dec 14 22:38:51 2009	(r200556)
@@ -1993,7 +1993,7 @@ char *cmd_str;
 	int number;
 	int i;
 	char *ptr;
-	char *direction = NULL;
+	char *direction = "d";
 	struct text *t_line;
 
 	ptr = cmd_str;
_______________________________________________
svn-src-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"