aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorEli Zaretskii2016-10-24 16:59:34 +0300
committerEli Zaretskii2016-10-24 16:59:34 +0300
commit1047496722a58ef5b736dae64d32adeb58c5055c (patch)
treefd2de5184909b90e6a9aeefd6c55c8967063a06b /src
parent31219927a9b2c5ef2f702bda245ffc306be7b1a2 (diff)
downloademacs-1047496722a58ef5b736dae64d32adeb58c5055c.tar.gz
emacs-1047496722a58ef5b736dae64d32adeb58c5055c.zip
Another fix for using pointer to buffer text
* src/search.c (Freplace_match): Move the call to BYTE_POS_ADDR after the call to xpalloc, to avoid the danger of buffer text relocation after its address was taken. (Bug#24358)
Diffstat (limited to 'src')
-rw-r--r--src/search.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/src/search.c b/src/search.c
index 5c04916f92e..f8acd40fa08 100644
--- a/src/search.c
+++ b/src/search.c
@@ -2640,6 +2640,7 @@ since only regular expressions have distinguished subexpressions. */)
2640 const unsigned char *add_stuff = NULL; 2640 const unsigned char *add_stuff = NULL;
2641 ptrdiff_t add_len = 0; 2641 ptrdiff_t add_len = 0;
2642 ptrdiff_t idx = -1; 2642 ptrdiff_t idx = -1;
2643 ptrdiff_t begbyte;
2643 2644
2644 if (str_multibyte) 2645 if (str_multibyte)
2645 { 2646 {
@@ -2702,11 +2703,10 @@ since only regular expressions have distinguished subexpressions. */)
2702 set up ADD_STUFF and ADD_LEN to point to it. */ 2703 set up ADD_STUFF and ADD_LEN to point to it. */
2703 if (idx >= 0) 2704 if (idx >= 0)
2704 { 2705 {
2705 ptrdiff_t begbyte = CHAR_TO_BYTE (search_regs.start[idx]); 2706 begbyte = CHAR_TO_BYTE (search_regs.start[idx]);
2706 add_len = CHAR_TO_BYTE (search_regs.end[idx]) - begbyte; 2707 add_len = CHAR_TO_BYTE (search_regs.end[idx]) - begbyte;
2707 if (search_regs.start[idx] < GPT && GPT < search_regs.end[idx]) 2708 if (search_regs.start[idx] < GPT && GPT < search_regs.end[idx])
2708 move_gap_both (search_regs.start[idx], begbyte); 2709 move_gap_both (search_regs.start[idx], begbyte);
2709 add_stuff = BYTE_POS_ADDR (begbyte);
2710 } 2710 }
2711 2711
2712 /* Now the stuff we want to add to SUBSTED 2712 /* Now the stuff we want to add to SUBSTED
@@ -2719,6 +2719,11 @@ since only regular expressions have distinguished subexpressions. */)
2719 add_len - (substed_alloc_size - substed_len), 2719 add_len - (substed_alloc_size - substed_len),
2720 STRING_BYTES_BOUND, 1); 2720 STRING_BYTES_BOUND, 1);
2721 2721
2722 /* We compute this after the call to xpalloc, because that
2723 could cause buffer text be relocated when ralloc.c is used. */
2724 if (idx >= 0)
2725 add_stuff = BYTE_POS_ADDR (begbyte);
2726
2722 /* Now add to the end of SUBSTED. */ 2727 /* Now add to the end of SUBSTED. */
2723 if (add_stuff) 2728 if (add_stuff)
2724 { 2729 {