From 44d853e989df672860db90b8035b31aa05a01a01 Mon Sep 17 00:00:00 2001 From: johanknol Date: Thu, 4 Oct 2001 10:20:14 +0000 Subject: [PATCH] fixed bug #467142 git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@1354 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- src/SDCCsymt.c | 6 ++++++ src/SDCCsymt.h | 5 +++-- support/Util/SDCCerr.c | 2 ++ support/Util/SDCCerr.h | 1 + 4 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/SDCCsymt.c b/src/SDCCsymt.c index 433afeaf..b87b4c51 100644 --- a/src/SDCCsymt.c +++ b/src/SDCCsymt.c @@ -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 */ diff --git a/src/SDCCsymt.h b/src/SDCCsymt.h index 88a5d546..47bf56b5 100644 --- a/src/SDCCsymt.h +++ b/src/SDCCsymt.h @@ -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 ___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 */ diff --git a/support/Util/SDCCerr.c b/support/Util/SDCCerr.c index 15e2618b..ad1e1abe 100644 --- a/support/Util/SDCCerr.c +++ b/support/Util/SDCCerr.c @@ -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" }, }; /* diff --git a/support/Util/SDCCerr.h b/support/Util/SDCCerr.h index 75b17f90..aa76231f 100644 --- a/support/Util/SDCCerr.h +++ b/support/Util/SDCCerr.h @@ -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. -- 2.30.2