fixed bug #467142
authorjohanknol <johanknol@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Thu, 4 Oct 2001 10:20:14 +0000 (10:20 +0000)
committerjohanknol <johanknol@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Thu, 4 Oct 2001 10:20:14 +0000 (10:20 +0000)
git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@1354 4a8a32a2-be11-0410-ad9d-d568d2c75423

src/SDCCsymt.c
src/SDCCsymt.h
support/Util/SDCCerr.c
support/Util/SDCCerr.h

index 433afeafc7ffa0b9cc7147f80f2982896016d46d..b87b4c51767a1c5b69e48a58f24f38771e5a924e 100644 (file)
@@ -112,6 +112,12 @@ addSym (bucket ** stab,
     checkTypeSanity(((symbol *)sym)->etype, ((symbol *)sym)->name);
   }
 
+  /* prevent overflow of the (r)name buffers */
+  if (strlen(sname)>SDCC_SYMNAME_MAX) {
+    werror (W_SYMBOL_NAME_TOO_LONG, SDCC_SYMNAME_MAX);
+    sname[SDCC_SYMNAME_MAX]='\0';
+  }
+
   /* the symbols are always added at the head of the list  */
   i = hashKey (sname);
   /* get a free entry */
index 88a5d546795b6ab582408d15486324fb87040bd9..47bf56b58af963b294539bb7139e50155cdcf31a 100644 (file)
@@ -25,7 +25,8 @@
 #define  SDCCSYMT_H
 
 #define MAX_NEST_LEVEL  256
-#define SDCC_NAME_MAX    64
+#define SDCC_SYMNAME_MAX 64
+#define SDCC_NAME_MAX  3*SDCC_SYMNAME_MAX // big enough for _<func>_<var>_etc
 #include "SDCChasht.h"
 
 
@@ -182,7 +183,7 @@ sym_link;
 
 typedef struct symbol
   {
-    char name[SDCC_NAME_MAX + 1];      /* Input Variable Name     */
+    char name[SDCC_SYMNAME_MAX + 1];   /* Input Variable Name     */
     char rname[SDCC_NAME_MAX + 1];     /* internal name           */
 
     short level;               /* declration lev,fld offset */
index 15e2618b3fb43c41e41afe290990a2dac921c689..ad1e1abee9c06cc335ddd7a6cd091c90fd7e546a 100644 (file)
@@ -366,6 +366,8 @@ struct
     "converting integral to pointer without a cast" },
 { W_PTR2INTEGRAL_NOCAST, ERROR_LEVEL_WARNING,
     "converting pointer to integral without a cast" },
+{ W_SYMBOL_NAME_TOO_LONG, ERROR_LEVEL_WARNING,
+    "symbol name too long, truncated to %d chars" },
 };
 
 /*
index 75b17f90617956369c20dee4fc0563ea7b217140..aa76231ffbbb75d8ca4c4a984ab55a8c9024f248 100644 (file)
@@ -171,6 +171,7 @@ SDCCERR - SDCC Standard error handler
 #define E_VOID_VALUE_USED 153
 #define W_INTEGRAL2PTR_NOCAST 154
 #define W_PTR2INTEGRAL_NOCAST 155
+#define W_SYMBOL_NAME_TOO_LONG 156
 
 /** Describes the maximum error level that will be logged.  Any level
  *  includes all of the levels listed after it.