[pcre-dev] Bug Report: Overlapping memory copy (fwd)

Kezdőlap
Üzenet törlése
Szerző: Andrew Ho
Dátum:  
Címzett: PCRE Developers
Új témák: [pcre-dev] Moving project to new home
Tárgy: [pcre-dev] Bug Report: Overlapping memory copy (fwd)
Heyas,

This seems like a fine use of this new alias. :)

Should we update the website and README files, etc. to include this new
alias? Or was this alias solely to discuss project maintenance issues?

Humbly,

Andrew

----------------------------------------------------------------------
'Twas brillig, and the slithy toves                         Andrew Ho
  Did gyre and gimble in the wabe.                  andrew@???
  All mimsy were the borogoves,
  And the mome raths outgrabe.          http://www.zeuscat.com/andrew/
----------------------------------------------------------------------


---------- Forwarded message ----------
Date: Thu, 8 Mar 2007 09:42:29 +0530
From: Mithun Dhali <mithuntnt@???>
To: webmaster@???, Philip Hazel <ph10@???>
Subject: Bug Report: Overlapping memory copy

Hi,
I am not sure i should be posting here. But i am doing so because the
perlre.html does not say where to send bugs to.

I was going through pcre-7.0 code and found one source of problem.

In case the system does not provide a memmove/bcopy method, the
pcre_internal.h has a provided a method for this purpose

#if ! HAVE_MEMMOVE
#undef  memmove        /* some systems may have a macro */
#if HAVE_BCOPY
#define memmove(a, b, c) bcopy(b, a, c)
#else  /* HAVE_BCOPY */
static void *
pcre_memmove(unsigned char *dest, const unsigned char *src, size_t n)
{
size_t i;
dest += n;
src += n;
for (i = 0; i < n; ++i) *(--dest) =  *(--src);
return dest;
}
#define memmove(a, b, c) pcre_memmove(a, b, c)
#endif   /* not HAVE_BCOPY */
#endif   /* not HAVE_MEMMOVE */
#endif   /* not VPCOMPAT */


this method does not work if dest and src is overlapping and src gt
destbecause it copies from the right hand side and thus corrupting
source in the
process which is the case in the pcre implemetnation.


In the pcre_compile.c one such case arises.
     if (previous != NULL)
       {
       if (previous > orig_code)
         {
         memmove(orig_code, previous, code - previous);
         code -= previous - orig_code;
         previous = orig_code;
         }
       }
     else code = orig_code;


Here the src=previous > dest=orig_code and may be overlapping.

I got errors on calling the method pcre_comile method with
pcre_compile("a[^\\r\\n]+",0,&errormsg,&error,NULL) ;

a[^\r\n]+
>> start branch

length=6 added 0 c=a
length=8 added 2 c=[
length=41 added 33 c=+
P = a[^\r\n]+
EC 8 EM internal error: unexpected repeat


and traced the source to this.

Regards

--
Mithun Dhali
CSE, IIT Kharagpur
A-304, RK, IIT Kharagpur 721302, India
/com/gmail/mithuntnt
+91-9732654573
+91-33-25118032 (H)