bison-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: FYI: Strip blanks from %*-param


From: Paul Eggert
Subject: Re: FYI: Strip blanks from %*-param
Date: Mon, 27 Sep 2004 15:10:59 -0700
User-agent: Gnus/5.1006 (Gnus v5.10.6) Emacs/21.3 (gnu/linux)

Akim Demaille <address@hidden> writes:

> +  /* Strip surrounding white spaces.  */
> +  while (strchr (blank, *decl))
> +    ++decl;

There's a potential buffer overrun here, since strchr (blank, '\0')
returns non-NULL.  I installed this:

2004-09-27  Paul Eggert  <address@hidden>

        * src/parse-gram.y (add_param): Rewrite to avoid strchr,
        since it's less likely to work if NULs are involved in the future.

Index: parse-gram.y
===================================================================
RCS file: /cvsroot/bison/bison/src/parse-gram.y,v
retrieving revision 1.50
retrieving revision 1.51
diff -p -c -r1.50 -r1.51
*** parse-gram.y        27 Sep 2004 07:42:04 -0000      1.50
--- parse-gram.y        27 Sep 2004 22:03:42 -0000      1.51
*************** lloc_default (YYLTYPE const *rhs, int n)
*** 472,500 ****
  static void
  add_param (char const *type, char *decl, location loc)
  {
!   static char const alphanum[] =
!     "0123456789"
      "abcdefghijklmnopqrstuvwxyz"
      "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
!     "_";
!   static char const blank[] = " \t";
!   char const *alpha = alphanum + 10;
    char const *name_start = NULL;
    char *p;
  
    for (p = decl; *p; p++)
!     if ((p == decl || ! strchr (alphanum, p[-1])) && strchr (alpha, p[0]))
        name_start = p;
  
!   /* Strip the surrounding '{' and '}'.  */
!   decl++;
!   *--p = '\0';
! 
!   /* Strip surrounding white spaces.  */
!   while (strchr (blank, *decl))
!     ++decl;
!   while (strchr (blank, p[-1]))
!     *--p = '\0';
  
    if (! name_start)
      complain_at (loc, _("missing identifier in parameter declaration"));
--- 472,498 ----
  static void
  add_param (char const *type, char *decl, location loc)
  {
!   static char const alphanum[26 + 26 + 1 + 10] =
      "abcdefghijklmnopqrstuvwxyz"
      "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
!     "_"
!     "0123456789";
    char const *name_start = NULL;
    char *p;
  
    for (p = decl; *p; p++)
!     if ((p == decl
!        || ! memchr (alphanum, p[-1], sizeof alphanum))
!       && memchr (alphanum, p[0], sizeof alphanum - 10))
        name_start = p;
  
!   /* Strip the surrounding '{' and '}', and any blanks just inside
!      the braces.  */
!   while (*--p == ' ' || *p == '\t')
!     continue;
!   *p = '\0';
!   while (*++decl == ' ' || *decl == '\t')
!     continue;
  
    if (! name_start)
      complain_at (loc, _("missing identifier in parameter declaration"));
*************** add_param (char const *type, char *decl,
*** 504,510 ****
        size_t name_len;
  
        for (name_len = 1;
!          name_start[name_len] && strchr (alphanum, name_start[name_len]);
           name_len++)
        continue;
  
--- 502,508 ----
        size_t name_len;
  
        for (name_len = 1;
!          memchr (alphanum, name_start[name_len], sizeof alphanum);
           name_len++)
        continue;
  




reply via email to

[Prev in Thread] Current Thread [Next in Thread]