1
0
Fork 0
mirror of git://git.code.sf.net/p/cdesktopenv/code synced 2025-02-13 11:42:21 +00:00

Fix parsing of multibyte characters

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
https://github.com/att/ast/commit/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)
This commit is contained in:
Martijn Dekker 2020-06-07 22:51:45 +02:00
parent 7559f83eff
commit 781f0a39aa

View file

@ -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: