Skip to content

Commit

Permalink
Fix parsing of multibyte characters
Browse files Browse the repository at this point in the history
According to Red Hat, this fixes "a bug on input buffer boundary
and/or temporary composing buffer of multibyte characters".
The patch was credited to Paulo Andrade <pandrade@redhat.com>.

To be honest, I don't know how to trigger this bug or what the code
removed by this fix really does, but this patch is in production
use at Red Hat, removes some smelly stuff, and is not triggering
any regression test failures, so I'll just take this one on faith.

https://bugzilla.redhat.com/show_bug.cgi?id=1417886
att@4fa2020b

src/cmd/ksh93/sh/fcin.c:
- _fcmbget(): Remove some dodgy-looking buffer-fiddling code that
  is marked as "for testing purposes with small buffers".

(cherry picked from commit 407760fdbddcb7f8ac92b5d1da29d3e09dac0369)
  • Loading branch information
McDutchie committed Jun 11, 2020
1 parent 7559f83 commit 781f0a3
Showing 1 changed file with 1 addition and 45 deletions.
46 changes: 1 addition & 45 deletions src/cmd/ksh93/sh/fcin.c
Expand Up @@ -150,56 +150,12 @@ extern void fcrestore(Fcin_t *fp)
_Fcin = *fp;
}

/* for testing purposes with small buffers */
#if defined(IOBSIZE) && (IOBSIZE < 2*MB_LEN_MAX)
# undef MB_LEN_MAX
# define MB_LEN_MAX (IOBSIZE/2)
#endif

struct Extra
{
unsigned char buff[2*MB_LEN_MAX];
unsigned char *next;
};

int _fcmbget(short *len)
{
static struct Extra extra;
register int i, c, n;
if(_Fcin.fcleft)
{
if((c = mbsize(extra.next)) < 0)
c = 1;
if((_Fcin.fcleft -= c) <=0)
{
_Fcin.fcptr = (unsigned char*)fcfirst() - _Fcin.fcleft;
_Fcin.fcleft = 0;
}
*len = c;
if(c==1)
c = *extra.next++;
else if(c==0)
_Fcin.fcleft = 0;
else
c = mbchar(extra.next);
return(c);
}
register int c;
switch(*len = mbsize(_Fcin.fcptr))
{
case -1:
if(_Fcin._fcfile && (n=(_Fcin.fclast-_Fcin.fcptr)) < MB_LEN_MAX)
{
memcpy(extra.buff, _Fcin.fcptr, n);
_Fcin.fcptr = _Fcin.fclast;
for(i=n; i < MB_LEN_MAX+n; i++)
{
if((extra.buff[i] = fcgetc(c))==0)
break;
}
_Fcin.fcleft = n;
extra.next = extra.buff;
return(fcmbget(len));
}
*len = 1;
/* fall through */
case 0:
Expand Down

0 comments on commit 781f0a3

Please sign in to comment.