Hi!

We've found that if the $HISTFILE doesn't exist and can't be created for some 
reason (e.g., read-only NFS home) ksh may crash with segmentation fault when 
trying to insert the last word of the previous command using the M-_ or M-. 
keyboard shortcut. 

Also, when the history file is accessible but empty, a garbage string is 
printed.

Problem is in src/cmd/ksh93/edit/history.c :  char *hist_word(...
line 1074:

        if(!hp)
#if KSHELL
        {
                strncpy(string,((Shell_t*)hp->histshell)->lastarg,size);
                return(string);
        }


where hp is dereferenced while having NULL value. 

We are using attached patch temporarily.

Regards,

Michal Hlavinka
diff -up ksh-20080202/src/cmd/ksh93/edit/emacs.c.histword ksh-20080202/src/cmd/ksh93/edit/emacs.c
--- ksh-20080202/src/cmd/ksh93/edit/emacs.c.histword	2009-04-06 16:06:01.000000000 +0200
+++ ksh-20080202/src/cmd/ksh93/edit/emacs.c	2009-04-06 16:06:56.000000000 +0200
@@ -895,7 +895,8 @@ static int escape(register Emacs_t* ep,r
 			genchar name[MAXLINE];
 			char buf[MAXLINE];
 			char *ptr;
-			ptr = hist_word(buf,MAXLINE,(count?count:-1));
+			if(!(ptr = hist_word(buf,MAXLINE,(count?count:-1))))
+				break;
 #if !KSHELL
 			if(ptr==0)
 			{
diff -up ksh-20080202/src/cmd/ksh93/edit/history.c.histword ksh-20080202/src/cmd/ksh93/edit/history.c
--- ksh-20080202/src/cmd/ksh93/edit/history.c.histword	2007-07-09 22:22:57.000000000 +0200
+++ ksh-20080202/src/cmd/ksh93/edit/history.c	2009-04-06 15:53:18.000000000 +0200
@@ -1072,10 +1072,7 @@ char *hist_word(char *string,int size,in
 	History_t *hp = hist_ptr;
 	if(!hp)
 #if KSHELL
-	{
-		strncpy(string,((Shell_t*)hp->histshell)->lastarg,size);
-		return(string);
-	}
+		return NULL;
 #else
 		return(NIL(char*));
 #endif /* KSHELL */
diff -up ksh-20080202/src/cmd/ksh93/edit/vi.c.histword ksh-20080202/src/cmd/ksh93/edit/vi.c
--- ksh-20080202/src/cmd/ksh93/edit/vi.c.histword	2009-04-06 16:24:01.000000000 +0200
+++ ksh-20080202/src/cmd/ksh93/edit/vi.c	2009-04-06 16:24:34.000000000 +0200
@@ -2356,7 +2356,8 @@ addin:
 			genchar tmpbuf[MAXLINE];
 			if(vp->repeat_set==0)
 				vp->repeat = -1;
-			p = (genchar*)hist_word((char*)tmpbuf,MAXLINE,vp->repeat);
+			if (!(p = (genchar*)hist_word((char*)tmpbuf,MAXLINE,vp->repeat)))
+				break;
 #if !KSHELL
 			if(p==0)
 			{
_______________________________________________
ast-developers mailing list
[email protected]
https://mailman.research.att.com/mailman/listinfo/ast-developers

Reply via email to