diff options
author | Paul Eggert <eggert@cs.ucla.edu> | 2016-10-25 12:50:30 -0700 |
---|---|---|
committer | Paul Eggert <eggert@cs.ucla.edu> | 2016-10-25 12:50:30 -0700 |
commit | a37820aef918cfaffbd1a74649e2a929f12c453b (patch) | |
tree | 6c9a005f6adcb3369d6cb344d54c8747197777e3 /src/xml.c | |
parent | 630f535ad6fbaa5e67df6fa5207e49b1728e08f9 (diff) | |
parent | ee04aedc723b035eedaf975422d4eb242894121b (diff) | |
download | emacs-a37820aef918cfaffbd1a74649e2a929f12c453b.tar.gz |
Merge from origin/emacs-25
ee04aed Fix handling of buffer relocation in regex.c functions
71ca4f6 Avoid relocating buffers while libxml2 reads its text
1b3fc8a ; Remove redundant code in gmalloc.c
9afea93 Attempt to catch reads from a buffer that is relocated
Diffstat (limited to 'src/xml.c')
-rw-r--r-- | src/xml.c | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/src/xml.c b/src/xml.c index 03e9053f297..7d61dc7413e 100644 --- a/src/xml.c +++ b/src/xml.c @@ -181,6 +181,7 @@ parse_region (Lisp_Object start, Lisp_Object end, Lisp_Object base_url, Lisp_Object result = Qnil; const char *burl = ""; ptrdiff_t istart, iend, istart_byte, iend_byte; + unsigned char *buftext; xmlCheckVersion (LIBXML_VERSION); @@ -200,18 +201,32 @@ parse_region (Lisp_Object start, Lisp_Object end, Lisp_Object base_url, burl = SSDATA (base_url); } + buftext = BYTE_POS_ADDR (istart_byte); +#ifdef REL_ALLOC + /* Prevent ralloc.c from relocating the current buffer while libxml2 + functions below read its text. */ + r_alloc_inhibit_buffer_relocation (1); +#endif if (htmlp) - doc = htmlReadMemory ((char *) BYTE_POS_ADDR (istart_byte), + doc = htmlReadMemory ((char *)buftext, iend_byte - istart_byte, burl, "utf-8", HTML_PARSE_RECOVER|HTML_PARSE_NONET| HTML_PARSE_NOWARNING|HTML_PARSE_NOERROR| HTML_PARSE_NOBLANKS); else - doc = xmlReadMemory ((char *) BYTE_POS_ADDR (istart_byte), + doc = xmlReadMemory ((char *)buftext, iend_byte - istart_byte, burl, "utf-8", XML_PARSE_NONET|XML_PARSE_NOWARNING| XML_PARSE_NOBLANKS |XML_PARSE_NOERROR); +#ifdef REL_ALLOC + r_alloc_inhibit_buffer_relocation (0); +#endif + /* If the assertion below fails, malloc was called inside the above + libxml2 functions, and ralloc.c caused relocation of buffer text, + so we could have read from unrelated memory. */ + eassert (buftext == BYTE_POS_ADDR (istart_byte)); + if (doc != NULL) { Lisp_Object r = Qnil; |