emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

emacs-27 df04f3e: Fix a rare segfault in syntax.c


From: Eli Zaretskii
Subject: emacs-27 df04f3e: Fix a rare segfault in syntax.c
Date: Sat, 19 Sep 2020 12:56:26 -0400 (EDT)

branch: emacs-27
commit df04f3e755f3001ebb9cc428faa7fa46059e636b
Author: Eli Zaretskii <eliz@gnu.org>
Commit: Eli Zaretskii <eliz@gnu.org>

    Fix a rare segfault in syntax.c
    
    * src/syntax.c (Fforward_comment): Prevent the loop for COUNT < 0
    from going outside the valid range of character/byte positions.
    (Bug#43499)
    
    * doc/lispref/syntax.texi (Syntax Class Table): Mention the
    "comment-fence" and "string-fence" as alternative names of 2
    syntax classes.
---
 doc/lispref/syntax.texi | 18 ++++++++++--------
 src/syntax.c            | 25 ++++++++++++++-----------
 2 files changed, 24 insertions(+), 19 deletions(-)

diff --git a/doc/lispref/syntax.texi b/doc/lispref/syntax.texi
index b3c7766..b99b5de 100644
--- a/doc/lispref/syntax.texi
+++ b/doc/lispref/syntax.texi
@@ -256,10 +256,11 @@ look in the standard syntax table to find the syntax of 
this
 character.
 
 @item Generic comment delimiters: @samp{!}
-Characters that start or end a special kind of comment.  @emph{Any}
-generic comment delimiter matches @emph{any} generic comment
-delimiter, but they cannot match a comment starter or comment ender;
-generic comment delimiters can only match each other.
+(This syntax class is also known as ``comment-fence''.)  Characters
+that start or end a special kind of comment.  @emph{Any} generic
+comment delimiter matches @emph{any} generic comment delimiter, but
+they cannot match a comment starter or comment ender; generic comment
+delimiters can only match each other.
 
 This syntax class is primarily meant for use with the
 @code{syntax-table} text property (@pxref{Syntax Properties}).  You
@@ -268,10 +269,11 @@ first and last characters of the range 
@code{syntax-table} properties
 identifying them as generic comment delimiters.
 
 @item Generic string delimiters: @samp{|}
-Characters that start or end a string.  This class differs from the
-string quote class in that @emph{any} generic string delimiter can
-match any other generic string delimiter; but they do not match
-ordinary string quote characters.
+(This syntax class is also known as ``string-fence''.)  Characters
+that start or end a string.  This class differs from the string quote
+class in that @emph{any} generic string delimiter can match any other
+generic string delimiter; but they do not match ordinary string quote
+characters.
 
 This syntax class is primarily meant for use with the
 @code{syntax-table} text property (@pxref{Syntax Properties}).  You
diff --git a/src/syntax.c b/src/syntax.c
index a79ab86..e8b32f5 100644
--- a/src/syntax.c
+++ b/src/syntax.c
@@ -2545,20 +2545,23 @@ between them, return t; otherwise return nil.  */)
              bool fence_found = 0;
              ptrdiff_t ini = from, ini_byte = from_byte;
 
-             while (1)
+             if (from > stop)
                {
-                 DEC_BOTH (from, from_byte);
-                 UPDATE_SYNTAX_TABLE_BACKWARD (from);
-                 c = FETCH_CHAR_AS_MULTIBYTE (from_byte);
-                 if (SYNTAX (c) == Scomment_fence
-                     && !char_quoted (from, from_byte))
+                 while (1)
                    {
-                     fence_found = 1;
-                     break;
+                     DEC_BOTH (from, from_byte);
+                     UPDATE_SYNTAX_TABLE_BACKWARD (from);
+                     c = FETCH_CHAR_AS_MULTIBYTE (from_byte);
+                     if (SYNTAX (c) == Scomment_fence
+                         && !char_quoted (from, from_byte))
+                       {
+                         fence_found = 1;
+                         break;
+                       }
+                     else if (from == stop)
+                       break;
+                     rarely_quit (++quit_count);
                    }
-                 else if (from == stop)
-                   break;
-                 rarely_quit (++quit_count);
                }
              if (fence_found == 0)
                {



reply via email to

[Prev in Thread] Current Thread [Next in Thread]