aboutsummaryrefslogtreecommitdiffstats
path: root/src/xml.c
diff options
context:
space:
mode:
authorEli Zaretskii2016-10-23 16:54:00 +0300
committerEli Zaretskii2016-10-23 16:54:00 +0300
commit9afea93ed536fb9110ac62b413604cf4c4302199 (patch)
tree1730d866aa1b10e47e163596a97f69fba907c8f0 /src/xml.c
parentb8e8e1528829516ccce5ce0be8b97cdce0a86999 (diff)
downloademacs-9afea93ed536fb9110ac62b413604cf4c4302199.tar.gz
emacs-9afea93ed536fb9110ac62b413604cf4c4302199.zip
Attempt to catch reads from a buffer that is relocated
* src/xml.c (parse_region): Add assertion to ensure buffer text is not relocated while libxml2 is reading it. (Bug#24764)
Diffstat (limited to 'src/xml.c')
-rw-r--r--src/xml.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/src/xml.c b/src/xml.c
index b1175d14a1a..1ef84bd917e 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,
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,24 @@ 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);
203 if (htmlp) 205 if (htmlp)
204 doc = htmlReadMemory ((char *) BYTE_POS_ADDR (istart_byte), 206 doc = htmlReadMemory ((char *)buftext,
205 iend_byte - istart_byte, burl, "utf-8", 207 iend_byte - istart_byte, burl, "utf-8",
206 HTML_PARSE_RECOVER|HTML_PARSE_NONET| 208 HTML_PARSE_RECOVER|HTML_PARSE_NONET|
207 HTML_PARSE_NOWARNING|HTML_PARSE_NOERROR| 209 HTML_PARSE_NOWARNING|HTML_PARSE_NOERROR|
208 HTML_PARSE_NOBLANKS); 210 HTML_PARSE_NOBLANKS);
209 else 211 else
210 doc = xmlReadMemory ((char *) BYTE_POS_ADDR (istart_byte), 212 doc = xmlReadMemory ((char *)buftext,
211 iend_byte - istart_byte, burl, "utf-8", 213 iend_byte - istart_byte, burl, "utf-8",
212 XML_PARSE_NONET|XML_PARSE_NOWARNING| 214 XML_PARSE_NONET|XML_PARSE_NOWARNING|
213 XML_PARSE_NOBLANKS |XML_PARSE_NOERROR); 215 XML_PARSE_NOBLANKS |XML_PARSE_NOERROR);
214 216
217 /* If the assertion below fails, malloc was called inside the above
218 libxml2 functions, and ralloc.c caused relocation of buffer text,
219 so we could have read from unrelated memory. */
220 eassert (buftext == BYTE_POS_ADDR (istart_byte));
221
215 if (doc != NULL) 222 if (doc != NULL)
216 { 223 {
217 Lisp_Object r = Qnil; 224 Lisp_Object r = Qnil;