Skip to content

Commit 129614b

Browse files
committed
edit/vi.c: sanity checks from OpenSUSE
Source: https://build.opensuse.org/package/view_file/shells/ksh/ksh93-vi.dif Patch from 2007, apparently never upstreamed.
1 parent 3ad4307 commit 129614b

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

  • src/cmd/ksh93/edit

‎src/cmd/ksh93/edit/vi.c‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,8 @@ int ed_viread(void *context, int fd, register char *shbuf, int nchar, int reedit
385385

386386
if(!yankbuf)
387387
yankbuf = (genchar*)malloc(MAXLINE*CHARSIZE);
388+
if(!vp->lastline)
389+
vp->lastline = (genchar*)malloc(MAXLINE*CHARSIZE);
388390
if( vp->last_cmd == '\0' )
389391
{
390392
/*** first time for this shell ***/
@@ -394,6 +396,8 @@ int ed_viread(void *context, int fd, register char *shbuf, int nchar, int reedit
394396
vp->lastmotion = '\0';
395397
vp->lastrepeat = 1;
396398
vp->repeat = 1;
399+
if(!yankbuf)
400+
return(-1);
397401
*yankbuf = 0;
398402
}
399403

@@ -1117,7 +1121,7 @@ static void cdelete(Vi_t *vp,register int nchars, int mode)
11171121

11181122
/*** save characters to be deleted ***/
11191123

1120-
if( mode != 'c' )
1124+
if( mode != 'c' && yankbuf )
11211125
{
11221126
i = cp[nchars];
11231127
cp[nchars] = 0;
@@ -2172,6 +2176,8 @@ static void save_last(register Vi_t* vp)
21722176
{
21732177
register int i;
21742178

2179+
if(vp->lastline == NULL)
2180+
return;
21752181
if( (i = cur_virt - first_virt + 1) > 0 )
21762182
{
21772183
/*** save last thing user typed ***/
@@ -2420,6 +2426,8 @@ static int textmod(register Vi_t *vp,register int c, int mode)
24202426
/*** change p from lastline to yankbuf ***/
24212427
p = yankbuf;
24222428
}
2429+
if(!p)
2430+
return(BAD);
24232431

24242432
addin:
24252433
switch( c )
@@ -2693,6 +2701,8 @@ static int textmod(register Vi_t *vp,register int c, int mode)
26932701
vp->lastmotion = c;
26942702
if( c == 'y' )
26952703
{
2704+
if(!yankbuf)
2705+
return(BAD);
26962706
gencpy(yankbuf, virtual);
26972707
}
26982708
else if(!delmotion(vp, c, 'y'))

0 commit comments

Comments
 (0)