]> git.eshelyaron.com Git - emacs.git/commitdiff
make-docfile: don't corrupt heap for an invalid .elc file
authorJim Meyering <meyering@redhat.com>
Sun, 30 Jan 2011 09:17:36 +0000 (10:17 +0100)
committerJim Meyering <meyering@redhat.com>
Sun, 30 Jan 2011 09:17:36 +0000 (10:17 +0100)
lib-src/ChangeLog
lib-src/make-docfile.c

index bc76c253ab3c7cb7caedb24cd8176e2a4b00f2e0..6428819daa31a623f4b27ad9e83a28197b39ad2a 100644 (file)
@@ -1,3 +1,11 @@
+2011-01-30  Jim Meyering  <meyering@redhat.com>
+
+       make-docfile: don't corrupt heap for an invalid .elc file
+       "printf '#@1a' > in.elc; ./make-docfile in.elc" would store 0
+       one byte before just-malloc'd saved_string buffer.
+       * make-docfile.c (scan_lisp_file): Diagnose an invalid dynamic
+       doc string length.  Also fix an always-false while-loop test.
+
 2011-01-29  Eli Zaretskii  <eliz@gnu.org>
 
        * makefile.w32-in (LOCAL_FLAGS): Add -I../lib.
index 0872f9728a250eea3133bf3c0c1f0f005620dbb5..8addbda0489fe07da138795eda9205c3756f4ab5 100644 (file)
@@ -873,8 +873,8 @@ scan_lisp_file (const char *filename, const char *mode)
          c = getc (infile);
          if (c == '@')
            {
-             int length = 0;
-             int i;
+             size_t length = 0;
+             size_t i;
 
              /* Read the length.  */
              while ((c = getc (infile),
@@ -884,6 +884,12 @@ scan_lisp_file (const char *filename, const char *mode)
                  length += c - '0';
                }
 
+             if (length <= 1)
+               fatal ("invalid dynamic doc string length", "");
+
+             if (c != ' ')
+               fatal ("space not found after dynamic doc string length", "");
+
              /* The next character is a space that is counted in the length
                 but not part of the doc string.
                 We already read it, so just ignore it.  */
@@ -899,7 +905,7 @@ scan_lisp_file (const char *filename, const char *mode)
                 but it is redundant in DOC.  So get rid of it here.  */
              saved_string[length - 1] = 0;
              /* Skip the line break.  */
-             while (c == '\n' && c == '\r')
+             while (c == '\n' || c == '\r')
                c = getc (infile);
              /* Skip the following line.  */
              while (c != '\n' && c != '\r')