From: Mattias EngdegÄrd Date: Fri, 25 Jul 2025 19:53:37 +0000 (+0200) Subject: Check for end-of-file when reading character escapes (bug#79097) X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=f7f7322dc43243cd95cb8712ae0db5a2eec8001e;p=emacs.git Check for end-of-file when reading character escapes (bug#79097) * src/lread.c (read_char_escape): Add check. * test/src/lread-tests.el (lread-char-escape-eof): New test. (cherry picked from commit 33161e51e539eadeb11282c06df73a5d76afdff2) --- diff --git a/src/lread.c b/src/lread.c index 287528ab32d..54b74b18782 100644 --- a/src/lread.c +++ b/src/lread.c @@ -3108,6 +3108,8 @@ read_char_escape (source_t *source, int next_char) chr = c; break; } + if (chr < 0) + end_of_file_error (); eassert (chr >= 0 && chr < (1 << CHARACTERBITS)); /* Apply Control modifiers, using the rules: diff --git a/test/src/lread-tests.el b/test/src/lread-tests.el index 02e3efcf06c..421c0c0ed4a 100644 --- a/test/src/lread-tests.el +++ b/test/src/lread-tests.el @@ -358,6 +358,37 @@ literals (Bug#20852)." (should-error (read-from-string "?\\\n x")) (should (equal (read-from-string "\"a\\\nb\"") '("ab" . 6)))) +(ert-deftest lread-char-escape-eof () + ;; Check that unfinished char escapes signal an error. + (should-error (read "?\\")) + + (should-error (read "?\\^")) + (should-error (read "?\\C")) + (should-error (read "?\\M")) + (should-error (read "?\\S")) + (should-error (read "?\\H")) + (should-error (read "?\\A")) + + (should-error (read "?\\C-")) + (should-error (read "?\\M-")) + (should-error (read "?\\S-")) + (should-error (read "?\\H-")) + (should-error (read "?\\A-")) + (should-error (read "?\\s-")) + + (should-error (read "?\\C-\\")) + (should-error (read "?\\C-\\M")) + (should-error (read "?\\C-\\M-")) + + (should-error (read "?\\x")) + (should-error (read "?\\u")) + (should-error (read "?\\u234")) + (should-error (read "?\\U")) + (should-error (read "?\\U0010010")) + (should-error (read "?\\N")) + (should-error (read "?\\N{")) + (should-error (read "?\\N{SPACE"))) + (ert-deftest lread-force-load-doc-strings () ;; Verify that lazy doc strings are loaded lazily by default, ;; but eagerly with `force-load-doc-strings' set.