aboutsummaryrefslogtreecommitdiffstats
path: root/src/dired.c
diff options
context:
space:
mode:
authorNoam Postavsky2016-10-19 20:23:50 -0400
committerNoam Postavsky2016-10-21 22:24:54 -0400
commitad66b3fadb7ae22a4cbb82bb1507c39ceadf3897 (patch)
treebc3857bb1d0eeccfd16a0fb3e4d8cb44a9ebec56 /src/dired.c
parent5a26c9b0e1b0d9a2de35e0a8b0a803017e70def0 (diff)
downloademacs-ad66b3fadb7ae22a4cbb82bb1507c39ceadf3897.tar.gz
emacs-ad66b3fadb7ae22a4cbb82bb1507c39ceadf3897.zip
Fix handling of allocation in regex matching
`re_match_2_internal' uses pointers to the lisp objects that it searches. Since it may call malloc when growing the "fail stack", these pointers may be invalidated while searching, resulting in memory curruption (Bug #24358). To fix this, we check the pointer that the lisp object (as specified by re_match_object) points to before and after growing the stack, and update existing pointers accordingly. * src/regex.c (STR_BASE_PTR): New macro. (ENSURE_FAIL_STACK, re_search_2): Use it to convert pointers into offsets before possible malloc call, and back into pointers again afterwards. (POS_AS_IN_BUFFER): Add explanatory comment about punning trick. * src/search.c (search_buffer): Instead of storing search location as pointers, store them as pointers and recompute the corresponding address for each call to `re_search_2'. (string_match_1, fast_string_match_internal, fast_looking_at): * src/dired.c (directory_files_internal): Set `re_match_object' to Qnil after calling `re_search' or `re_match_2'. * src/regex.h (re_match_object): Mention new usage in commentary.
Diffstat (limited to 'src/dired.c')
-rw-r--r--src/dired.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/src/dired.c b/src/dired.c
index dba575ce4c2..006f74c834d 100644
--- a/src/dired.c
+++ b/src/dired.c
@@ -259,9 +259,11 @@ directory_files_internal (Lisp_Object directory, Lisp_Object full,
259 QUIT; 259 QUIT;
260 260
261 bool wanted = (NILP (match) 261 bool wanted = (NILP (match)
262 || re_search (bufp, SSDATA (name), len, 0, len, 0) >= 0); 262 || (re_match_object = name,
263 re_search (bufp, SSDATA (name), len, 0, len, 0) >= 0));
263 264
264 immediate_quit = 0; 265 immediate_quit = 0;
266 re_match_object = Qnil; /* Stop protecting name from GC. */
265 267
266 if (wanted) 268 if (wanted)
267 { 269 {