diff options
| author | Paul Eggert | 2016-10-25 12:50:30 -0700 |
|---|---|---|
| committer | Paul Eggert | 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 emacs-a37820aef918cfaffbd1a74649e2a929f12c453b.zip | |
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
| @@ -181,6 +181,7 @@ parse_region (Lisp_Object start, Lisp_Object end, Lisp_Object base_url, | |||
| 181 | Lisp_Object result = Qnil; | 181 | Lisp_Object result = Qnil; |
| 182 | const char *burl = ""; | 182 | const char *burl = ""; |
| 183 | ptrdiff_t istart, iend, istart_byte, iend_byte; | 183 | ptrdiff_t istart, iend, istart_byte, iend_byte; |
| 184 | unsigned char *buftext; | ||
| 184 | 185 | ||
| 185 | xmlCheckVersion (LIBXML_VERSION); | 186 | xmlCheckVersion (LIBXML_VERSION); |
| 186 | 187 | ||
| @@ -200,18 +201,32 @@ parse_region (Lisp_Object start, Lisp_Object end, Lisp_Object base_url, | |||
| 200 | burl = SSDATA (base_url); | 201 | burl = SSDATA (base_url); |
| 201 | } | 202 | } |
| 202 | 203 | ||
| 204 | buftext = BYTE_POS_ADDR (istart_byte); | ||
| 205 | #ifdef REL_ALLOC | ||
| 206 | /* Prevent ralloc.c from relocating the current buffer while libxml2 | ||
| 207 | functions below read its text. */ | ||
| 208 | r_alloc_inhibit_buffer_relocation (1); | ||
| 209 | #endif | ||
| 203 | if (htmlp) | 210 | if (htmlp) |
| 204 | doc = htmlReadMemory ((char *) BYTE_POS_ADDR (istart_byte), | 211 | doc = htmlReadMemory ((char *)buftext, |
| 205 | iend_byte - istart_byte, burl, "utf-8", | 212 | iend_byte - istart_byte, burl, "utf-8", |
| 206 | HTML_PARSE_RECOVER|HTML_PARSE_NONET| | 213 | HTML_PARSE_RECOVER|HTML_PARSE_NONET| |
| 207 | HTML_PARSE_NOWARNING|HTML_PARSE_NOERROR| | 214 | HTML_PARSE_NOWARNING|HTML_PARSE_NOERROR| |
| 208 | HTML_PARSE_NOBLANKS); | 215 | HTML_PARSE_NOBLANKS); |
| 209 | else | 216 | else |
| 210 | doc = xmlReadMemory ((char *) BYTE_POS_ADDR (istart_byte), | 217 | doc = xmlReadMemory ((char *)buftext, |
| 211 | iend_byte - istart_byte, burl, "utf-8", | 218 | iend_byte - istart_byte, burl, "utf-8", |
| 212 | XML_PARSE_NONET|XML_PARSE_NOWARNING| | 219 | XML_PARSE_NONET|XML_PARSE_NOWARNING| |
| 213 | XML_PARSE_NOBLANKS |XML_PARSE_NOERROR); | 220 | XML_PARSE_NOBLANKS |XML_PARSE_NOERROR); |
| 214 | 221 | ||
| 222 | #ifdef REL_ALLOC | ||
| 223 | r_alloc_inhibit_buffer_relocation (0); | ||
| 224 | #endif | ||
| 225 | /* If the assertion below fails, malloc was called inside the above | ||
| 226 | libxml2 functions, and ralloc.c caused relocation of buffer text, | ||
| 227 | so we could have read from unrelated memory. */ | ||
| 228 | eassert (buftext == BYTE_POS_ADDR (istart_byte)); | ||
| 229 | |||
| 215 | if (doc != NULL) | 230 | if (doc != NULL) |
| 216 | { | 231 | { |
| 217 | Lisp_Object r = Qnil; | 232 | Lisp_Object r = Qnil; |