texinfo-commits
[Top][All Lists]
Advanced

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

[no subject]


From: Gavin D. Smith
Date: Tue, 15 Oct 2024 11:37:36 -0400 (EDT)

branch: master
commit 5416a74ddd6e04dbf1575925a2be63369cb80b71
Author: Gavin Smith <gavinsmith0123@gmail.com>
AuthorDate: Tue Oct 15 16:37:19 2024 +0100

    Always null terminate key sequence array
    
    * info/infokey.c (compile): Always null-terminate 'seq' array.
    Avoid filling the array completely as this could lead to a segfault
    if exactly 20 characters were given in a key sequence, e.g.
    
    bbbbbbbbbbbbbbbbbbb down-line
    
    Report of uninitialised variable from Vitezslav Crhonek, found
    with a static analysis tool.
---
 ChangeLog      | 13 +++++++++++++
 info/infokey.c | 10 ++++++----
 2 files changed, 19 insertions(+), 4 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index aa135ef00e..840570e1a3 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2024-10-15  Gavin Smith <gavinsmith0123@gmail.com>
+
+       Always null terminate key sequence array
+
+       * info/infokey.c (compile): Always null-terminate 'seq' array.
+       Avoid filling the array completely as this could lead to a segfault
+       if exactly 20 characters were given in a key sequence, e.g.
+
+       bbbbbbbbbbbbbbbbbbb down-line
+
+       Report of uninitialised variable from Vitezslav Crhonek, found
+       with a static analysis tool.
+
 2024-10-15  Gavin Smith <gavinsmith0123@gmail.com>
 
        * install-info/install-info.c (open_possibly_compressed_file):
diff --git a/info/infokey.c b/info/infokey.c
index ec06cec51f..460985353f 100644
--- a/info/infokey.c
+++ b/info/infokey.c
@@ -219,8 +219,11 @@ compile (FILE *fp, const char *filename, int 
*suppress_info, int *suppress_ea)
 
 #define        To_seq(c) \
                  do { \
-                   if (slen < sizeof seq/sizeof(int)) \
-                     seq[slen++] = meta ? KEYMAP_META(c) : (c); \
+                   if (slen < sizeof seq/sizeof(int) - 1) \
+                     { \
+                       seq[slen++] = meta ? KEYMAP_META(c) : (c); \
+                       seq[slen] = '\0'; \
+                     } \
                    else \
                      { \
                        syntax_error(filename, lnum, \
@@ -229,6 +232,7 @@ compile (FILE *fp, const char *filename, int 
*suppress_info, int *suppress_ea)
                      } \
                    meta = 0; \
                  } while (0)
+  seq[0] = '\0';
 
   while (!error && (rescan || (c = fgetc (fp)) != EOF))
     {
@@ -494,8 +498,6 @@ compile (FILE *fp, const char *filename, int 
*suppress_info, int *suppress_ea)
                       ke.value.function = a != A_INVALID
                                             ? &function_doc_array[a]
                                             : &invalid_function;
-                      To_seq (0);
-
                       if (section == info)
                         keymap_bind_keyseq (info_keymap, seq, &ke);
                       else /* section == ea */



reply via email to

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