Bert Wesarg wrote:
> Hi all,
> 
> I'm getting an buffer overflow error with recent GCC (ubuntu 4.3.2)
> and -O3 optimization. The new cool feature is called _FORTIFY_SOURCE
> (maybe). This checks at runtime buffer bounds within str*() and mem*()
> functions. The problem that hits me is in regularExpr.c. The function
> makeDelimiterTable() expects the second argument to be of type
> 'unsigned char[256]' but the declaration is only 'unsigned char *'.
> memset() is that called with a length parameter of 256 and the
> internal checks fails because the length of the arguments is not
> known. If I declare this function with the 'unsigned char[256]' all
> works as expected. The question I have now is: can all supported
> platforms this syntax or is this purely my problem? I can disable
> these checks with -U_FORTIFY_SOURCE.

Looking at the source I'd guess all the occurrences of "256" should be
UCHAR_MAX+1, and there would appear to be no reason to change the
function definition to "unsigned char[UCHAR_MAX+1]"

--- source/regularExp.c.20080301        2008-03-01 10:12:26.000000000 +1100
+++ source/regularExp.c 2008-10-22 23:30:15.000000000 +1100
@@ -444,7 +444,7 @@
 /* Array sizes for arrays used by function init_ansi_classes. */

 #define WHITE_SPACE_SIZE   16
-#define ALNUM_CHAR_SIZE   256
+#define ALNUM_CHAR_SIZE   (UCHAR_MAX+1)

 /* Number of bytes to offset from the beginning of the regex program to
the start
    of the actual compiled regex code, i.e. skipping over the MAGIC
number and
@@ -2656,7 +2656,7 @@

 /* Default table for determining whether a character is a word
delimiter. */

-static unsigned char  Default_Delimiters [UCHAR_MAX] = {0};
+static unsigned char  Default_Delimiters [UCHAR_MAX+1] = {0};

 static unsigned char *Current_Delimiters;  /* Current delimiter table */

@@ -2666,7 +2666,7 @@
 static int             match              (unsigned char *, int *);
 static unsigned long   greedy             (unsigned char *, long);
 static void            adjustcase         (unsigned char *, int,
unsigned char);
-static unsigned char * makeDelimiterTable (unsigned char *, unsigned
char *);
+static unsigned char * makeDelimiterTable (unsigned char *, unsigned
char[UCHAR_MAX+1]);

 /*
  * ExecRE - match a `regexp' structure against a string
@@ -2702,7 +2702,7 @@
             unsigned char **s_ptr;
             unsigned char **e_ptr;
                      int    ret_val = 0;
-            unsigned char   tempDelimitTable [256];
+            unsigned char   tempDelimitTable [UCHAR_MAX+1];
                      int    i;

    /* Check for valid parameters. */
@@ -4136,7 +4136,7 @@
 /*----------------------------------------------------------------------*
  * makeDelimiterTable
  *
- * Translate a null-terminated string of delimiters into a 256 byte
+ * Translate a null-terminated string of delimiters into a UCHAR_MAX+1 byte
  * lookup table for determining whether a character is a delimiter or
  * not.
  *
@@ -4147,11 +4147,11 @@

 static unsigned char * makeDelimiterTable (
    unsigned char *delimiters,
-   unsigned char *table) {
+   unsigned char table[UCHAR_MAX+1]) {

    unsigned char *c;

-   memset (table, 0, 256);
+   memset (table, 0, UCHAR_MAX+1);

    for (c = (unsigned char *) delimiters; *c != '\0'; c++) {
       table [*c] = 1;

-- 
There's no point in being grown up if you can't be childish sometimes.
                -- Dr. Who
-- 
NEdit Develop mailing list - [email protected]
http://www.nedit.org/mailman/listinfo/develop

Reply via email to