cppinit.c (cpp_start_read): Fix buffer overwrite.
authorDave Brolley <brolley@cygnus.com>
Tue, 13 Apr 1999 09:43:28 +0000 (09:43 +0000)
committerDave Brolley <brolley@gcc.gnu.org>
Tue, 13 Apr 1999 09:43:28 +0000 (05:43 -0400)
Tue Apr 13 12:14:07 1999  Dave Brolley  <brolley@cygnus.com>
* cppinit.c (cpp_start_read): Fix buffer overwrite.
* Makefile.in (cppinit.o): Typo in dependencies.

From-SVN: r26401

gcc/ChangeLog
gcc/Makefile.in
gcc/cppinit.c

index ccf1d9f19788061e7252127d952a4809fac93ea3..0dd765009a09217fb23c5ea2fc87aa3b113e75af 100644 (file)
@@ -1,3 +1,8 @@
+Tue Apr 13 12:14:07 1999  Dave Brolley  <brolley@cygnus.com>
+
+       * cppinit.c (cpp_start_read): Fix buffer overwrite.
+       * Makefile.in (cppinit.o): Typo in dependencies.
+
 Tue Apr 13 05:04:59 1999  Richard Earnshaw (rearnsha@arm.com)
 
        * arm.h (function prototypes for arm.c): Ifdef these out if
index 80fc7b750ad91359350bb2d01e1fb0765232b614..942280cf94f98c21e774ef264e390ff84fd16d38 100644 (file)
@@ -1988,7 +1988,7 @@ cpperror.o: cpperror.c $(CONFIG_H) cpplib.h intl.h system.h
 cppexp.o:   cppexp.c   $(CONFIG_H) cpplib.h intl.h system.h
 cppfiles.o: cppfiles.c $(CONFIG_H) cpplib.h intl.h system.h
 
-cppinit.o:  cppalloc.c $(CONFIG_H) cpplib.h intl.h system.h \
+cppinit.o:  cppinit.c $(CONFIG_H) cpplib.h intl.h system.h \
                cpphash.h prefix.h output.h Makefile
        $(CC) $(ALL_CFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) \
          -DGCC_INCLUDE_DIR=\"$(libsubdir)/include\" \
index 73008008357f997bd7d2ed4c484e5592bfbcb148..d02a1f9b8275bf71a2f152f97a067fa10d65dbda 100644 (file)
@@ -881,22 +881,21 @@ cpp_start_read (pfile, fname)
     {
       struct default_include *p = include_defaults_array;
       char *specd_prefix = opts->include_prefix;
-      char *default_prefix = alloca (sizeof GCC_INCLUDE_DIR - 7);
-      int default_len;
-      int specd_len;
 
       /* Search "translated" versions of GNU directories.
         These have /usr/local/lib/gcc... replaced by specd_prefix.  */
       if (specd_prefix != 0)
        {
+         char *default_prefix = alloca (sizeof GCC_INCLUDE_DIR - 7);
          /* Remove the `include' from /usr/local/lib/gcc.../include.
             GCC_INCLUDE_DIR will always end in /include. */
+         int default_len = sizeof GCC_INCLUDE_DIR - 8;
+         int specd_len = strlen (specd_prefix);
+
          default_len = sizeof GCC_INCLUDE_DIR - 8;
          memcpy (default_prefix, GCC_INCLUDE_DIR, default_len);
          default_prefix[default_len] = '\0';
 
-
-         specd_len = strlen (specd_prefix);
          for (p = include_defaults_array; p->fname; p++)
            {
              /* Some standard dirs are only for C++.  */
@@ -909,10 +908,12 @@ cpp_start_read (pfile, fname)
                    {
                      /* Yes; change prefix and add to search list.  */
                      int flen = strlen (p->fname);
-                     int this_len = specd_len - default_len + flen;
+                     int this_len = specd_len + flen - default_len;
                      char *str = (char *) xmalloc (this_len + 1);
                      memcpy (str, specd_prefix, specd_len);
-                     memcpy (str+specd_len, p->fname, flen + 1);
+                     memcpy (str + specd_len,
+                             p->fname + default_len,
+                             flen - default_len + 1);
 
                      append_include_chain (pfile, opts->pending,
                                            str, SYSTEM);