[Patch:] restore the native use of isdigit() instead of ap_isdigit() in httpd.

classic Classic list List threaded Threaded
17 messages Options
Reply | Threaded
Open this post in threaded view
|

[Patch:] restore the native use of isdigit() instead of ap_isdigit() in httpd.

Daniel Ouellet
Here is a patch to restore the use of the native isdigit() instead of
the ap_isdigit one.

Comments are welcome.

Thanks for your time looking at this.

Daniel

=========================================

Index: src/main/http_protocol.c
===================================================================
RCS file: /cvs/src/usr.sbin/httpd/src/main/http_protocol.c,v
retrieving revision 1.30
diff -u -r1.30 http_protocol.c
--- src/main/http_protocol.c 11 Feb 2006 19:15:57 -0000 1.30
+++ src/main/http_protocol.c 30 Mar 2006 07:47:59 -0000
@@ -154,7 +154,7 @@
  return BYTERANGE_EMPTY;
      }

-    if (ap_isdigit(*r->range))
+    if (isdigit(*r->range))
  *start = ap_strtol(r->range, (char **)&r->range, 10);
      else
  *start = -1;
@@ -169,7 +169,7 @@
      while (ap_isspace(*r->range))
          ++r->range;

-    if (ap_isdigit(*r->range))
+    if (isdigit(*r->range))
  *end = ap_strtol(r->range, (char **)&r->range, 10);
      else
  *end = -1;
@@ -1012,8 +1012,8 @@
      if (strlen(r->protocol) == 8
          && r->protocol[0] == 'H' && r->protocol[1] == 'T'
  && r->protocol[2] == 'T' && r->protocol[3] == 'P'
-        && r->protocol[4] == '/' && ap_isdigit(r->protocol[5])
- && r->protocol[6] == '.' && ap_isdigit(r->protocol[7])) {
+        && r->protocol[4] == '/' && isdigit(r->protocol[5])
+ && r->protocol[6] == '.' && isdigit(r->protocol[7])) {
          r->proto_num = HTTP_VERSION(r->protocol[5] - '0',
r->protocol[7] - '0');
      }
      else {
@@ -2768,9 +2768,9 @@
           */
          if (r->status_line != NULL
              && strlen(r->status_line) > 4       /* long enough */
-            && ap_isdigit(r->status_line[0])
-            && ap_isdigit(r->status_line[1])
-            && ap_isdigit(r->status_line[2])
+            && isdigit(r->status_line[0])
+            && isdigit(r->status_line[1])
+            && isdigit(r->status_line[2])
              && ap_isspace(r->status_line[3])
              && ap_isalnum(r->status_line[4])) {
              title = r->status_line;
Index: src/main/http_vhost.c
===================================================================
RCS file: /cvs/src/usr.sbin/httpd/src/main/http_vhost.c,v
retrieving revision 1.7
diff -u -r1.7 http_vhost.c
--- src/main/http_vhost.c 21 Aug 2003 13:11:35 -0000 1.7
+++ src/main/http_vhost.c 30 Mar 2006 07:47:59 -0000
@@ -724,7 +724,7 @@
          if (*src == ':') {
              /* check the port part */
              while (*++src) {
-                if (!ap_isdigit(*src)) {
+                if (!isdigit(*src)) {
                      goto bad;
                  }
              }
Index: src/main/util.c
===================================================================
RCS file: /cvs/src/usr.sbin/httpd/src/main/util.c,v
retrieving revision 1.19
diff -u -r1.19 util.c
--- src/main/util.c 20 Jan 2006 00:21:43 -0000 1.19
+++ src/main/util.c 30 Mar 2006 07:47:59 -0000
@@ -389,7 +389,7 @@
      while ((c = *src++) != '\0') {
  if (c == '&')
     no = 0;
- else if (c == '$' && ap_isdigit(*src))
+ else if (c == '$' && isdigit(*src))
     no = *src++ - '0';
  else
     no = 10;
@@ -414,7 +414,7 @@
      while ((c = *src++) != '\0') {
  if (c == '&')
     no = 0;
- else if (c == '$' && ap_isdigit(*src))
+ else if (c == '$' && isdigit(*src))
     no = *src++ - '0';
  else
     no = 10;
@@ -1771,7 +1771,7 @@

      for (x = 0; u[x] != ':'; x++) {
  if ((!u[x]) ||
-    ((!ap_isalpha(u[x])) && (!ap_isdigit(u[x])) &&
+    ((!ap_isalpha(u[x])) && (!isdigit(u[x])) &&
      (u[x] != '+') && (u[x] != '-') && (u[x] != '.'))) {
     return 0;
  }
Index: src/main/util_date.c
===================================================================
RCS file: /cvs/src/usr.sbin/httpd/src/main/util_date.c,v
retrieving revision 1.6
diff -u -r1.6 util_date.c
--- src/main/util_date.c 21 Aug 2003 13:11:35 -0000 1.6
+++ src/main/util_date.c 30 Mar 2006 07:47:59 -0000
@@ -106,7 +106,7 @@
  return 0;
     break;
  case '#':
-    if (!ap_isdigit(d))
+    if (!isdigit(d))
  return 0;
     break;
  case '&':
@@ -114,7 +114,7 @@
  return 0;
     break;
  case '~':
-    if ((d != ' ') && !ap_isdigit(d))
+    if ((d != ' ') && !isdigit(d))
  return 0;
     break;
  default:
Index: src/main/util_script.c
===================================================================
RCS file: /cvs/src/usr.sbin/httpd/src/main/util_script.c,v
retrieving revision 1.15
diff -u -r1.15 util_script.c
--- src/main/util_script.c 9 Feb 2005 12:13:10 -0000 1.15
+++ src/main/util_script.c 30 Mar 2006 07:47:59 -0000
@@ -169,7 +169,7 @@
  }
  env[j] = ap_pstrcat(p, elts[i].key, "=", elts[i].val, NULL);
  whack = env[j];
- if (ap_isdigit(*whack)) {
+ if (isdigit(*whack)) {
     *whack++ = '_';
  }
  while (*whack != '=') {
Index: src/modules/extra/mod_define.c
===================================================================
RCS file: /cvs/src/usr.sbin/httpd/src/modules/extra/mod_define.c,v
retrieving revision 1.3
diff -u -r1.3 mod_define.c
--- src/modules/extra/mod_define.c 9 Feb 2005 12:13:10 -0000 1.3
+++ src/modules/extra/mod_define.c 30 Mar 2006 07:47:59 -0000
@@ -128,7 +128,7 @@
              cc = CC_BRACECLOSE;
          else if (ap_isalpha(*cp))
              cc = CC_IDCHAR1;
-        else if (ap_isdigit(*cp) || *cp == '_' || *cp == ':')
+        else if (isdigit(*cp) || *cp == '_' || *cp == ':')
              cc = CC_IDCHAR;
          else if (*cp == '\0')
              cc = CC_EOS;
Index: src/modules/proxy/mod_proxy.c
===================================================================
RCS file: /cvs/src/usr.sbin/httpd/src/modules/proxy/mod_proxy.c,v
retrieving revision 1.14
diff -u -r1.14 mod_proxy.c
--- src/modules/proxy/mod_proxy.c 9 Feb 2005 12:13:10 -0000 1.14
+++ src/modules/proxy/mod_proxy.c 30 Mar 2006 07:47:59 -0000
@@ -668,7 +668,7 @@
      ap_get_module_config(s->module_config, &proxy_module);
      int *New;

-    if (!ap_isdigit(arg[0]))
+    if (!isdigit(arg[0]))
          return "AllowCONNECT: port number must be numeric";

      New = ap_push_array(conf->allowed_connect_ports);
Index: src/modules/proxy/proxy_ftp.c
===================================================================
RCS file: /cvs/src/usr.sbin/httpd/src/modules/proxy/proxy_ftp.c,v
retrieving revision 1.14
diff -u -r1.14 proxy_ftp.c
--- src/modules/proxy/proxy_ftp.c 9 Feb 2005 12:13:10 -0000 1.14
+++ src/modules/proxy/proxy_ftp.c 30 Mar 2006 07:48:00 -0000
@@ -194,8 +194,8 @@
      if (len == -1)
          return -1;
  /* check format */
-    if (len < 5 || !ap_isdigit(linebuff[0]) || !ap_isdigit(linebuff[1]) ||
-     !ap_isdigit(linebuff[2]) || (linebuff[3] != ' ' && linebuff[3] !=
'-'))
+    if (len < 5 || !isdigit(linebuff[0]) || !isdigit(linebuff[1]) ||
+     !isdigit(linebuff[2]) || (linebuff[3] != ' ' && linebuff[3] != '-'))
          status = 0;
      else
          status = 100 * linebuff[0] + 10 * linebuff[1] + linebuff[2] -
111 * '0';
@@ -234,8 +234,8 @@
      len = ap_bgets(linebuff, sizeof linebuff, ctrl);
      if (len == -1)
          return -1;
-    if (len < 5 || !ap_isdigit(linebuff[0]) || !ap_isdigit(linebuff[1]) ||
-     !ap_isdigit(linebuff[2]) || (linebuff[3] != ' ' && linebuff[3] !=
'-'))
+    if (len < 5 || !isdigit(linebuff[0]) || !isdigit(linebuff[1]) ||
+     !isdigit(linebuff[2]) || (linebuff[3] != ' ' && linebuff[3] != '-'))
          status = 0;
      else
          status = 100 * linebuff[0] + 10 * linebuff[1] + linebuff[2] -
111 * '0';
@@ -389,8 +389,8 @@
              n = strlen(buf);
          }
          /* Handle unix style or DOS style directory  */
-        else if (buf[0] == 'd' || buf[0] == '-' || buf[0] == 'l' ||
ap_isdigit(buf[0])) {
-            if (ap_isdigit(buf[0])) {   /* handle DOS dir */
+        else if (buf[0] == 'd' || buf[0] == '-' || buf[0] == 'l' ||
isdigit(buf[0])) {
+            if (isdigit(buf[0])) {   /* handle DOS dir */
                  searchptr = strchr(buf, '<');
                  if (searchptr != NULL)
                      *searchptr = '[';
@@ -617,7 +617,7 @@
      strp2 = strchr(desthost, ':');
      if (strp2 != NULL) {
          *(strp2++) = '\0';
-        if (ap_isdigit(*strp2)) {
+        if (isdigit(*strp2)) {
              destport = atoi(strp2);
              destportstr = strp2;
          }
@@ -1087,7 +1087,7 @@
                  len = 0;
              }
              else if (i == 213) {/* Size command ok */
-                for (j = 0; j < sizeof resp && ap_isdigit(resp[j]); j++);
+                for (j = 0; j < sizeof resp && isdigit(resp[j]); j++);
                  resp[j] = '\0';
                  if (resp[0] != '\0')
                      size = ap_pstrdup(p, resp);
Index: src/modules/proxy/proxy_http.c
===================================================================
RCS file: /cvs/src/usr.sbin/httpd/src/modules/proxy/proxy_http.c,v
retrieving revision 1.16
diff -u -r1.16 proxy_http.c
--- src/modules/proxy/proxy_http.c 9 Feb 2005 12:13:10 -0000 1.16
+++ src/modules/proxy/proxy_http.c 30 Mar 2006 07:48:00 -0000
@@ -212,7 +212,7 @@
      strp2 = strchr(desthost, ':');
      if (strp2 != NULL) {
          *(strp2++) = '\0';
-        if (ap_isdigit(*strp2)) {
+        if (isdigit(*strp2)) {
              destport = atoi(strp2);
              destportstr = strp2;
          }
Index: src/modules/proxy/proxy_util.c
===================================================================
RCS file: /cvs/src/usr.sbin/httpd/src/modules/proxy/proxy_util.c,v
retrieving revision 1.15
diff -u -r1.15 proxy_util.c
--- src/modules/proxy/proxy_util.c 9 Feb 2005 12:13:10 -0000 1.15
+++ src/modules/proxy/proxy_util.c 30 Mar 2006 07:48:00 -0000
@@ -77,7 +77,7 @@
      int ch;

      ch = x[0];
-    if (ap_isdigit(ch))
+    if (isdigit(ch))
          i = ch - '0';
      else if (ap_isupper(ch))
          i = ch - ('A' - 10);
@@ -86,7 +86,7 @@
      i <<= 4;

      ch = x[1];
-    if (ap_isdigit(ch))
+    if (isdigit(ch))
          i += ch - '0';
      else if (ap_isupper(ch))
          i += ch - ('A' - 10);
@@ -249,7 +249,7 @@
          *(strp++) = '\0';

          for (i = 0; strp[i] != '\0'; i++)
-            if (!ap_isdigit(strp[i]))
+            if (!isdigit(strp[i]))
                  break;

          /* if (i == 0) the no port was given; keep default */
@@ -267,7 +267,7 @@
          return "Missing host in URL";
  /* check hostname syntax */
      for (i = 0; host[i] != '\0'; i++)
-        if (!ap_isdigit(host[i]) && host[i] != '.')
+        if (!isdigit(host[i]) && host[i] != '.')
              break;
      /* must be an IP address */
      if (host[i] == '\0' && (ap_inet_addr(host) == -1 ||
inet_network(host) == -1))
@@ -805,7 +805,7 @@
      for (i = 0, j = 0; i < 16; i++) {
          ch = x[i];
          j <<= 4;
-        if (ap_isdigit(ch))
+        if (isdigit(ch))
              j |= ch - '0';
          else if (ap_isupper(ch))
              j |= ch - ('A' - 10);
@@ -897,7 +897,7 @@
      struct per_thread_data *ptd = get_per_thread_data();

      for (i = 0; host[i] != '\0'; i++)
-        if (!ap_isdigit(host[i]) && host[i] != '.')
+        if (!isdigit(host[i]) && host[i] != '.')
              break;

      if (host[i] != '\0') {
@@ -981,7 +981,7 @@
          if (*addr == '/' && quads > 0)  /* netmask starts here. */
              break;

-        if (!ap_isdigit(*addr))
+        if (!isdigit(*addr))
              return 0;           /* no digit at start of quad */

          ip_addr[quads] = ap_strtol(addr, &tmp, 0);
@@ -1003,7 +1003,7 @@
      for (This->addr.s_addr = 0, i = 0; i < quads; ++i)
          This->addr.s_addr |= htonl(ip_addr[i] << (24 - 8 * i));

-    if (addr[0] == '/' && ap_isdigit(addr[1])) {        /* net mask
follows: */
+    if (addr[0] == '/' && isdigit(addr[1])) {        /* net mask
follows: */
          char *tmp;

          ++addr;
Index: src/modules/standard/mod_access.c
===================================================================
RCS file: /cvs/src/usr.sbin/httpd/src/modules/standard/mod_access.c,v
retrieving revision 1.7
diff -u -r1.7 mod_access.c
--- src/modules/standard/mod_access.c 21 Nov 2003 18:12:49 -0000 1.7
+++ src/modules/standard/mod_access.c 30 Mar 2006 07:48:00 -0000
@@ -139,7 +139,7 @@

  static int is_ip(const char *host)
  {
-    while ((*host == '.') || ap_isdigit(*host))
+    while ((*host == '.') || isdigit(*host))
  host++;
      return (*host == '\0');
  }
@@ -207,7 +207,7 @@
  a->x.ip.mask = mask;
          a->x.ip.net.s_addr  = (a->x.ip.net.s_addr & mask.s_addr);   /*
pjr - This fixes PR 4770 */
      }
-    else if (ap_isdigit(*where) && is_ip(where)) {
+    else if (isdigit(*where) && is_ip(where)) {
  /* legacy syntax for ip addrs: a.b.c. ==> a.b.c.0/24 for example */
  int shift;
  char *t;
@@ -221,11 +221,11 @@
  shift = 24;
  while (*s) {
     t = s;
-    if (!ap_isdigit(*t)) {
+    if (!isdigit(*t)) {
  a->type = T_FAIL;
  return "invalid ip address";
     }
-    while (ap_isdigit(*t)) {
+    while (isdigit(*t)) {
  ++t;
     }
     if (*t == '.') {
Index: src/modules/standard/mod_alias.c
===================================================================
RCS file: /cvs/src/usr.sbin/httpd/src/modules/standard/mod_alias.c,v
retrieving revision 1.12
diff -u -r1.12 mod_alias.c
--- src/modules/standard/mod_alias.c 2 Dec 2004 19:42:47 -0000 1.12
+++ src/modules/standard/mod_alias.c 30 Mar 2006 07:48:00 -0000
@@ -186,7 +186,7 @@
  status = HTTP_MOVED_TEMPORARILY;
      else if (!strcasecmp(arg1, "seeother"))
  status = HTTP_SEE_OTHER;
-    else if (ap_isdigit(*arg1))
+    else if (isdigit(*arg1))
  status = atoi(arg1);
      else {
  f = arg1;
Index: src/modules/standard/mod_expires.c
===================================================================
RCS file: /cvs/src/usr.sbin/httpd/src/modules/standard/mod_expires.c,v
retrieving revision 1.8
diff -u -r1.8 mod_expires.c
--- src/modules/standard/mod_expires.c 21 Aug 2003 13:11:36 -0000 1.8
+++ src/modules/standard/mod_expires.c 30 Mar 2006 07:48:00 -0000
@@ -285,7 +285,7 @@
      while (word[0]) {
          /* <num>
           */
-        if (ap_isdigit(word[0])) {
+        if (isdigit(word[0])) {
              num = atoi(word);
          }
          else {
Index: src/modules/standard/mod_imap.c
===================================================================
RCS file: /cvs/src/usr.sbin/httpd/src/modules/standard/mod_imap.c,v
retrieving revision 1.8
diff -u -r1.8 mod_imap.c
--- src/modules/standard/mod_imap.c 20 Jan 2006 00:21:43 -0000 1.8
+++ src/modules/standard/mod_imap.c 30 Mar 2006 07:48:01 -0000
@@ -260,7 +260,7 @@
          return (-1);            /* in case we aren't passed anything */
      }

-    while (*args && !ap_isdigit(*args) && *args != ',') {
+    while (*args && !isdigit(*args) && *args != ',') {
          args++;                 /* jump to the first digit, but not past
                                     a comma or end */
      }
@@ -292,7 +292,7 @@
          start_of_y++;           /* start looking at the character after
                                     the comma */

-        while (*start_of_y && !ap_isdigit(*start_of_y)) {
+        while (*start_of_y && !isdigit(*start_of_y)) {
              start_of_y++;       /* jump to the first digit, but not
                                     past the end */
  }
@@ -749,14 +749,14 @@
              while (ap_isspace(*string_pos)) {      /* past whitespace */
                  string_pos++;
     }
-            while (ap_isdigit(*string_pos)) {      /* and the 1st number */
+            while (isdigit(*string_pos)) {      /* and the 1st number */
                  string_pos++;
     }
              string_pos++;       /* skip the ',' */
              while (ap_isspace(*string_pos)) {      /* past any more
whitespace */
                  string_pos++;
     }
-            while (ap_isdigit(*string_pos)) {      /* 2nd number */
+            while (isdigit(*string_pos)) {      /* 2nd number */
                  string_pos++;
     }
              vertex++;
Index: src/modules/standard/mod_include.c
===================================================================
RCS file: /cvs/src/usr.sbin/httpd/src/modules/standard/mod_include.c,v
retrieving revision 1.14
diff -u -r1.14 mod_include.c
--- src/modules/standard/mod_include.c 9 Feb 2005 12:13:10 -0000 1.14
+++ src/modules/standard/mod_include.c 30 Mar 2006 07:48:01 -0000
@@ -300,7 +300,7 @@

          /* is it numeric ? */
          if (s[1] == '#') {
-            for (j = 2, val = 0; j < i && ap_isdigit(s[j]); j++) {
+            for (j = 2, val = 0; j < i && isdigit(s[j]); j++) {
                  val = val * 10 + s[j] - '0';
              }
              s += i;
Index: src/modules/standard/mod_log_config.c
===================================================================
RCS file: /cvs/src/usr.sbin/httpd/src/modules/standard/mod_log_config.c,v
retrieving revision 1.17
diff -u -r1.17 mod_log_config.c
--- src/modules/standard/mod_log_config.c 9 Feb 2005 12:13:10 -0000 1.17
+++ src/modules/standard/mod_log_config.c 30 Mar 2006 07:48:01 -0000
@@ -717,7 +717,7 @@
          case '8':
          case '9':
              i = *s - '0';
-            while (ap_isdigit(*++s)) {
+            while (isdigit(*++s)) {
                  i = i * 10 + (*s) - '0';
              }
              if (!it->conditions) {
Index: src/modules/standard/mod_mime_magic.c
===================================================================
RCS file: /cvs/src/usr.sbin/httpd/src/modules/standard/mod_mime_magic.c,v
retrieving revision 1.9
diff -u -r1.9 mod_mime_magic.c
--- src/modules/standard/mod_mime_magic.c 9 Feb 2005 12:13:10 -0000 1.9
+++ src/modules/standard/mod_mime_magic.c 30 Mar 2006 07:48:02 -0000
@@ -1115,7 +1115,7 @@
  s = l;
  if (*l == '+' || *l == '-')
     l++;
- if (ap_isdigit((unsigned char) *l)) {
+ if (isdigit((unsigned char) *l)) {
     m->in.offset = ap_strtol(l, &t, 0);
     if (*s == '-')
  m->in.offset = -m->in.offset;
@@ -1130,7 +1130,7 @@
      }


-    while (ap_isdigit((unsigned char) *l))
+    while (isdigit((unsigned char) *l))
  ++l;
      EATAB;

@@ -1403,7 +1403,7 @@
  /* Single hex char to int; -1 if not a hex char. */
  static int hextoint(int c)
  {
-    if (ap_isdigit((unsigned char) c))
+    if (isdigit((unsigned char) c))
  return c - '0';
      if ((c >= 'a') && (c <= 'f'))
  return c + 10 - 'a';
@@ -2266,10 +2266,10 @@

      /* check for recognized revision suffix */
      suffix_pos = strlen(r->filename) - 1;
-    if (!ap_isdigit(r->filename[suffix_pos])) {
+    if (!isdigit(r->filename[suffix_pos])) {
  return 0;
      }
-    while (suffix_pos >= 0 && ap_isdigit(r->filename[suffix_pos]))
+    while (suffix_pos >= 0 && isdigit(r->filename[suffix_pos]))
  suffix_pos--;
      if (suffix_pos < 0 || r->filename[suffix_pos] != '@') {
  return 0;
Index: src/modules/standard/mod_negotiation.c
===================================================================
RCS file: /cvs/src/usr.sbin/httpd/src/modules/standard/mod_negotiation.c,v
retrieving revision 1.8
diff -u -r1.8 mod_negotiation.c
--- src/modules/standard/mod_negotiation.c 9 Feb 2005 12:13:10 -0000 1.8
+++ src/modules/standard/mod_negotiation.c 30 Mar 2006 07:48:02 -0000
@@ -547,7 +547,7 @@
          if (strcmp(tok, "trans") == 0 ||
              strcmp(tok, "vlist") == 0 ||
              strcmp(tok, "guess-small") == 0 ||
-            ap_isdigit(tok[0]) ||
+            isdigit(tok[0]) ||
              strcmp(tok, "*") == 0) {

              /* The user agent supports transparent negotiation */
Index: src/modules/standard/mod_rewrite.c
===================================================================
RCS file: /cvs/src/usr.sbin/httpd/src/modules/standard/mod_rewrite.c,v
retrieving revision 1.24
diff -u -r1.24 mod_rewrite.c
--- src/modules/standard/mod_rewrite.c 9 Feb 2005 12:13:10 -0000 1.24
+++ src/modules/standard/mod_rewrite.c 30 Mar 2006 07:48:03 -0000
@@ -881,7 +881,7 @@
              else if (strcasecmp(val, "seeother") == 0) {
                  status = HTTP_SEE_OTHER;
              }
-            else if (ap_isdigit(*val)) {
+            else if (isdigit(*val)) {
                  status = atoi(val);
              }
              if (!ap_is_HTTP_REDIRECT(status)) {
@@ -2423,7 +2423,7 @@
     space -= span;
     continue;
  }
- else if (ap_isdigit(inp[1])) {
+ else if (isdigit(inp[1])) {
     int n = inp[1] - '0';
     backrefinfo *bri = NULL;
     if (inp[0] == '$') {
Index: src/modules/standard/mod_usertrack.c
===================================================================
RCS file: /cvs/src/usr.sbin/httpd/src/modules/standard/mod_usertrack.c,v
retrieving revision 1.12
diff -u -r1.12 mod_usertrack.c
--- src/modules/standard/mod_usertrack.c 6 Dec 2004 13:14:10 -0000 1.12
+++ src/modules/standard/mod_usertrack.c 30 Mar 2006 07:48:03 -0000
@@ -365,7 +365,7 @@
      cls  = ap_get_module_config(parms->server->module_config,
                                  &usertrack_module);
      /* The simple case first - all numbers (we assume) */
-    if (ap_isdigit(arg[0]) && ap_isdigit(arg[strlen(arg) - 1])) {
+    if (isdigit(arg[0]) && isdigit(arg[strlen(arg) - 1])) {
          cls->expires = atol(arg);
          return NULL;
      }
@@ -384,7 +384,7 @@
      /* {<num> <type>}* */
      while (word[0]) {
          /* <num> */
- if (ap_isdigit(word[0]))
+ if (isdigit(word[0]))
              num = atoi(word);
          else
              return "bad expires code, numeric value expected.";
Index: src/modules/standard/mod_vhost_alias.c
===================================================================
RCS file: /cvs/src/usr.sbin/httpd/src/modules/standard/mod_vhost_alias.c,v
retrieving revision 1.8
diff -u -r1.8 mod_vhost_alias.c
--- src/modules/standard/mod_vhost_alias.c 21 Aug 2003 13:11:37 -0000 1.8
+++ src/modules/standard/mod_vhost_alias.c 30 Mar 2006 07:48:03 -0000
@@ -214,7 +214,7 @@
     ++p;
  }
  /* digit N */
- if (ap_isdigit(*p)) {
+ if (isdigit(*p)) {
     ++p;
  }
  else {
@@ -234,7 +234,7 @@
     ++p;
  }
  /* digit M */
- if (ap_isdigit(*p)) {
+ if (isdigit(*p)) {
     ++p;
  }
  else {
Index: src/regex/regcomp.c
===================================================================
RCS file: /cvs/src/usr.sbin/httpd/src/regex/regcomp.c,v
retrieving revision 1.6
diff -u -r1.6 regcomp.c
--- src/regex/regcomp.c 2 Dec 2004 19:42:48 -0000 1.6
+++ src/regex/regcomp.c 30 Mar 2006 07:48:03 -0000
@@ -312,7 +312,7 @@
  ordinary(p, c);
  break;
  case '{': /* okay as ordinary except if digit follows */
- REQUIRE(!MORE() || !ap_isdigit(PEEK()), REG_BADRPT);
+ REQUIRE(!MORE() || !isdigit(PEEK()), REG_BADRPT);
  /* FALLTHROUGH */
  default:
  ordinary(p, c);
@@ -324,7 +324,7 @@
  c = PEEK();
  /* we call { a repetition if followed by a digit */
  if (!( c == '*' || c == '+' || c == '?' ||
- (c == '{' && MORE2() && ap_isdigit(PEEK2())) ))
+ (c == '{' && MORE2() && isdigit(PEEK2())) ))
  return; /* no repetition, we're done */
  NEXT1();

@@ -353,7 +353,7 @@
  case '{':
  count = p_count(p);
  if (EAT(',')) {
- if (ap_isdigit(PEEK())) {
+ if (isdigit(PEEK())) {
  count2 = p_count(p);
  REQUIRE(count <= count2, REG_BADBR);
  } else /* single number with comma */
@@ -374,7 +374,7 @@
  return;
  c = PEEK();
  if (!( c == '*' || c == '+' || c == '?' ||
- (c == '{' && MORE2() && ap_isdigit(PEEK2())) ) )
+ (c == '{' && MORE2() && isdigit(PEEK2())) ) )
  return;
  SETERROR(REG_BADRPT);
  }
@@ -531,7 +531,7 @@
  } else if (EATTWO('\\', '{')) {
  count = p_count(p);
  if (EAT(',')) {
- if (MORE() && ap_isdigit(PEEK())) {
+ if (MORE() && isdigit(PEEK())) {
  count2 = p_count(p);
  REQUIRE(count <= count2, REG_BADBR);
  } else /* single number with comma */
@@ -562,7 +562,7 @@
  register int count = 0;
  register int ndigits = 0;

- while (MORE() && ap_isdigit(PEEK()) && count <= DUPMAX) {
+ while (MORE() && isdigit(PEEK()) && count <= DUPMAX) {
  count = count*10 + (GETNEXT() - '0');
  ndigits++;
  }

Reply | Threaded
Open this post in threaded view
|

Re: [Patch:] restore the native use of isdigit() instead of ap_isdigit() in httpd.

Joerg Sonnenberger
On Thu, Mar 30, 2006 at 03:08:11AM -0500, Daniel Ouellet wrote:
> Here is a patch to restore the use of the native isdigit() instead of
> the ap_isdigit one.

Have you checked that the arguments are always from the unsigned char
domain? Even though OpenBSD's isdigit handles it internally, it is more
efficient when the compiler can drop one conditional.

Joerg

Reply | Threaded
Open this post in threaded view
|

Re: [Patch:] restore the native use of isdigit() instead of ap_isdigit() in httpd.

Daniel Ouellet
[hidden email] wrote:
> On Thu, Mar 30, 2006 at 03:08:11AM -0500, Daniel Ouellet wrote:
>
>>Here is a patch to restore the use of the native isdigit() instead of
>>the ap_isdigit one.
>
>
> Have you checked that the arguments are always from the unsigned char
> domain? Even though OpenBSD's isdigit handles it internally, it is more
> efficient when the compiler can drop one conditional.

What I did is to check how it was process by the macro in the
/include/ctype.h:

__CTYPE_INLINE int isdigit(int c)
{
         return (c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)c] & _N));
}

Then apache cast the type to (unsigned char) before calling it and here
it's done in the macro of the system as well. The cast result is the
same here no? Because it is a macro, it would be replace before been
compile anyway no? So, the conditional would be drop no matter what.

May be there is something else I don't think of in the compile process.
Macro are replace by the pre processor no?

Just to be clean however, I am not at the stage yet to correct a lots of
problem if any in the code, I am still trying to clean it up as much as
I can.
I welcome feedback to my education if I miss something obvious. I have a
big red and white target on my belly, shoot away! (:>

Daniel

Reply | Threaded
Open this post in threaded view
|

Re: [Patch:] restore the native use of isdigit() instead of ap_isdigit() in httpd.

Joerg Sonnenberger
On Thu, Mar 30, 2006 at 02:44:19PM -0500, Daniel Ouellet wrote:
> What I did is to check how it was process by the macro in the
> /include/ctype.h:
>
> __CTYPE_INLINE int isdigit(int c)
> {
>         return (c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)c] & _N));
> }

The important point is that isdigit should not be called with an argment
of type char. As I said, it works on OpenBSD. It does not work on other
systems. isdigit is a documented interface, so it should be used
correctly, since someone might want to use it on a different system
later.

Joerg

Reply | Threaded
Open this post in threaded view
|

Re: [Patch:] restore the native use of isdigit() instead of ap_isdigit() in httpd.

Daniel Ouellet
[hidden email] wrote:
> The important point is that isdigit should not be called with an argment
> of type char. As I said, it works on OpenBSD. It does not work on other
> systems. isdigit is a documented interface, so it should be used
> correctly, since someone might want to use it on a different system
> later.

OK, that's fair. So, if I understand you right then, I will redo the
changes and anywhere that is might not be already (unsigned char), you
would suggest that I called it like this for example then and the
results would be the same as it is now using the ap_isdigit() one.

If *r->range is not already (unsigned char), then cast it

so:
if (isdigit((unsigned char)*r->range))
instead of:
if (isdigit(*r->range))
if apply here.

So if already (unsigned char), then obviously leave it alone.

Do I understand you properly?

We can also take that off list if everyone else already understand this
and I am just thick. I don't want to waist anyone times.

Thanks for your feedback.

Reply | Threaded
Open this post in threaded view
|

Re: [Patch:] restore the native use of isdigit() instead of ap_isdigit() in httpd.

Joerg Sonnenberger
On Thu, Mar 30, 2006 at 03:20:44PM -0500, Daniel Ouellet wrote:
> OK, that's fair. So, if I understand you right then, I will redo the
> changes and anywhere that is might not be already (unsigned char), you
> would suggest that I called it like this for example then and the
> results would be the same as it is now using the ap_isdigit() one.

Exactly. It might help you to remove the explicit cast in ctype.h for
testing, GCC should warn about char used as index.

Joerg

Reply | Threaded
Open this post in threaded view
|

Re: [Patch:] restore the native use of isdigit() instead of ap_isdigit() in httpd.

Daniel Boulet-2
In reply to this post by Joerg Sonnenberger
Hmmm.  The isdigit man page from the Single Unix Specification on the  
Open Groups' web site (www.unix.org) declares isdigit as follows:

        #include <ctype.h>

        int isdigit(int c);

This documentation for the isdigit interface would appear to allow  
the parameter to be a char since chars can certainly be cast to ints  
without any loss of information.

I will say that arguing that one should pass unsigned char's to  
isdigit to ensure portability across even antique environments that  
do not adhere to the roughly ten year old Single Unix Specification  
makes a certain amount of sense.  Arguing that one should not pass  
chars to isdigit because it violates isdigit's documented interface  
is the part that I'm having trouble with.

There is a caveat on the Open Group's man page which reads as follows:

The functionality described on this reference page is aligned with  
the ISO C standard. Any conflict between the requirements described  
here and the ISO C standard is unintentional. This volume of IEEE Std  
1003.1-2001 defers to the ISO C standard.

I don't have a copy of the ISO C standard.  Could someone who has  
access to the ISO C standard check to see how it defines isdigit?

-Danny

On 30-Mar-2006, at 12:50 PM, [hidden email] wrote:

> On Thu, Mar 30, 2006 at 02:44:19PM -0500, Daniel Ouellet wrote:
>> What I did is to check how it was process by the macro in the
>> /include/ctype.h:
>>
>> __CTYPE_INLINE int isdigit(int c)
>> {
>>         return (c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)c] &  
>> _N));
>> }
>
> The important point is that isdigit should not be called with an  
> argment
> of type char. As I said, it works on OpenBSD. It does not work on  
> other
> systems. isdigit is a documented interface, so it should be used
> correctly, since someone might want to use it on a different system
> later.
>
> Joerg

Reply | Threaded
Open this post in threaded view
|

Re: [Patch:] restore the native use of isdigit() instead of ap_isdigit() in httpd.

Garance A Drosihn
In reply to this post by Joerg Sonnenberger
At 9:50 PM +0200 3/30/06, [hidden email] wrote:

>On Thu, Mar 30, 2006 at 02:44:19PM -0500, Daniel Ouellet wrote:
>>  What I did is to check how it was process by the macro in the
>>  /include/ctype.h:
>>
>>  __CTYPE_INLINE int isdigit(int c)
>>  {
>>          return (c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)c] & _N));
>>  }
>
>The important point is that isdigit should not be called with
>an argment of type char. As I said, it works on OpenBSD. It
>does not work on other systems. isdigit is a documented
>interface, so it should be used correctly, since someone might
>want to use it on a different system later.

Fwiw, what I do is define is*ch and to*ch macros, such as:

#define isdigitch(Anychar) isdigit((u_char)(Anychar))

and then use these whenever some code had been calling
isdigit() with a plain 'char' type.  At the point I define
those macros, I include comments as to why I do this, since
this seems to be a pretty common programming mistake.  The
mistake usually isn't too bad for isdigit(), but it is more
likely to be serious for some of the other is*() functions.

E.g.:

/*
  * All the following take a parameter of 'int', but expect values in the
  * range of unsigned char.  Define wrappers which take values of type 'char',
  * whether signed or unsigned, and ensure they end up in the right range.
  */
#define isdigitch(Anychar) isdigit((u_char)(Anychar))
#define islowerch(Anychar) islower((u_char)(Anychar))
#define isupperch(Anychar) isupper((u_char)(Anychar))
#define tolowerch(Anychar) tolower((u_char)(Anychar))

Note: this is what I do.  I am not an OpenBSD developer, and
it wouldn't surprise me if opinions about this varied.  But
when I've done it, it's been to FIX code which was using one
of these routines incorrectly.  By having these defines, the
programmer only has to type 2 extra characters compared to
the official function, and (IMO) they are more likely to do
that than to remember to do:
       islower((unsigned char)somevar)

...particularly if they are not noticing any errors when
using a "plain char" type, because they are only testing
on a hardware-platform where "plain char" is actually the
same as "unsigned char".

Again:  I am sure opinions about this will vary quite a bit.

--
Garance Alistair Drosehn            =   [hidden email]
Senior Systems Programmer           or  [hidden email]
Rensselaer Polytechnic Institute    or  [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: [Patch:] restore the native use of isdigit() instead of ap_isdigit() in httpd.

Ted Unangst-2
In reply to this post by Daniel Boulet-2
On 3/30/06, Daniel Boulet <[hidden email]> wrote:
> I don't have a copy of the ISO C standard.  Could someone who has
> access to the ISO C standard check to see how it defines isdigit?

"In all cases the argument is an int, the value of which shall be
representable as an unsigned char or shall equal the value of the
marco EOF.  If the value has any other value, teh behavior is
undefined."  int, unsigned char, and EOF are all in bold.

Reply | Threaded
Open this post in threaded view
|

Re: [Patch:] restore the native use of isdigit() instead of ap_isdigit() in httpd.

Joerg Sonnenberger
In reply to this post by Daniel Boulet-2
On Thu, Mar 30, 2006 at 03:21:29PM -0700, Daniel Boulet wrote:

> Hmmm.  The isdigit man page from the Single Unix Specification on the  
> Open Groups' web site (www.unix.org) declares isdigit as follows:
>
> #include <ctype.h>
>
> int isdigit(int c);
>
> This documentation for the isdigit interface would appear to allow  
> the parameter to be a char since chars can certainly be cast to ints  
> without any loss of information.

Please read the *full* description, especially the following:
    The c argument is an int, the value of which the application shall
    ensure is a character representable as an unsigned char or equal to
    the value of the macro EOF. If the argument has any other value, the
    behavior is undefined.

Joerg

Reply | Threaded
Open this post in threaded view
|

Re: [Patch:] restore the native use of isdigit() instead of ap_isdigit() in httpd.

Ted Unangst-2
In reply to this post by Ted Unangst-2
On 3/30/06, Ted Unangst <[hidden email]> wrote:
> marco EOF.  If the value has any other value, teh behavior is

i was obviously quoting from a draft of the standard. :)

Reply | Threaded
Open this post in threaded view
|

Re: [Patch:] restore the native use of isdigit() instead of ap_isdigit() in httpd.

Theo de Raadt
In reply to this post by Joerg Sonnenberger
> > Hmmm.  The isdigit man page from the Single Unix Specification on the  
> > Open Groups' web site (www.unix.org) declares isdigit as follows:
> >
> > #include <ctype.h>
> >
> > int isdigit(int c);
> >
> > This documentation for the isdigit interface would appear to allow  
> > the parameter to be a char since chars can certainly be cast to ints  
> > without any loss of information.
>
> Please read the *full* description, especially the following:
>     The c argument is an int, the value of which the application shall
>     ensure is a character representable as an unsigned char or equal to
>     the value of the macro EOF. If the argument has any other value, the
>     behavior is undefined.

And if you are not angry by the time you read to the end of this, then
you don't understand the full consequences of the horrid place we have
ended up in.

Reply | Threaded
Open this post in threaded view
|

Re: [Patch:] restore the native use of isdigit() instead of ap_isdigit() in httpd.

Daniel Boulet-2
In reply to this post by Joerg Sonnenberger
Ok.  I stand mostly corrected.  What this appears to be saying is  
that if the value that one passes to isdigit is either EOF or what  
one would get if one assigned an unsigned char to an int then one is  
safe.  If one is carrying the character around in an int and one  
knows that the int's value is either EOF or a value derived directly  
from an unsigned char then one is safe.  If one knows that the value  
in question is not EOF then using an unsigned char to represent the  
value is obviously safer than using a char.  If one can't be sure  
that the value might be EOF then it would seem that an int is safer.  
Using a char is never the safe/portable choice.  Since one cannot  
represent the value EOF in an unsigned char then using an unsigned  
char to represent the value is unsafe if the value in question might  
be EOF.  It is, of course, safe to use an unsigned char if one knows  
that the value in question cannot be EOF.

Thanks for the clarification.

-Danny

On 30-Mar-2006, at 4:38 PM, [hidden email] wrote:

> On Thu, Mar 30, 2006 at 03:21:29PM -0700, Daniel Boulet wrote:
>> Hmmm.  The isdigit man page from the Single Unix Specification on the
>> Open Groups' web site (www.unix.org) declares isdigit as follows:
>>
>> #include <ctype.h>
>>
>> int isdigit(int c);
>>
>> This documentation for the isdigit interface would appear to allow
>> the parameter to be a char since chars can certainly be cast to ints
>> without any loss of information.
>
> Please read the *full* description, especially the following:
>     The c argument is an int, the value of which the application shall
>     ensure is a character representable as an unsigned char or  
> equal to
>     the value of the macro EOF. If the argument has any other  
> value, the
>     behavior is undefined.
>
> Joerg

Reply | Threaded
Open this post in threaded view
|

Re: [Patch:] restore the native use of isdigit() instead of ap_isdigit() in httpd.

Daniel Boulet-2
In reply to this post by Theo de Raadt
I resisted the temptation to add "Blech!" to the end of my last note.

Sigh.

-Danny

P.S. Sorry to pollute this thread with this language-lawyer  
nonsense.  I'm done now.  Please carry on with the "regularly  
scheduled programming".

On 30-Mar-2006, at 4:47 PM, Theo de Raadt wrote:

>>> Hmmm.  The isdigit man page from the Single Unix Specification on  
>>> the
>>> Open Groups' web site (www.unix.org) declares isdigit as follows:
>>>
>>> #include <ctype.h>
>>>
>>> int isdigit(int c);
>>>
>>> This documentation for the isdigit interface would appear to allow
>>> the parameter to be a char since chars can certainly be cast to ints
>>> without any loss of information.
>>
>> Please read the *full* description, especially the following:
>>     The c argument is an int, the value of which the application  
>> shall
>>     ensure is a character representable as an unsigned char or  
>> equal to
>>     the value of the macro EOF. If the argument has any other  
>> value, the
>>     behavior is undefined.
>
> And if you are not angry by the time you read to the end of this, then
> you don't understand the full consequences of the horrid place we have
> ended up in.

Reply | Threaded
Open this post in threaded view
|

Re: [Patch:] restore the native use of isdigit() instead of ap_isdigit() in httpd.

Garance A Drosihn
In reply to this post by Daniel Boulet-2
At 3:21 PM -0700 3/30/06, Daniel Boulet wrote:

>Hmmm.  The isdigit man page from the Single Unix Specification
>on the Open Groups' web site (www.unix.org) declares isdigit
>as follows:
>
> #include <ctype.h>
>
> int isdigit(int c);
>
>This documentation for the isdigit interface would appear to
>allow the parameter to be a char since chars can certainly
>be cast to ints without any loss of information.

And this is exactly why we have the problem.  Programmers
read the above, and jump to the same conclusion you did.

Note that on some platforms, 'char' is the same as 'signed
char', while on other hardware platforms a plain 'char' is
defined to be the same as 'unsigned char'.

When 'char' is signed, then the values it holds can be
negative values.  You never "lose" any information casting
that to an int, but you also do not always end up with value
in the proper range for these functions.  And if you test
your code on a platform where 'char' == 'unsigned char',
then even a good battery of unit-tests on that platform
will not discover this coding error.

And since the acceptable range is -1 (EOF) to 255, there
are some of these functions where you can not even cheat
by pretending the range is -255 to 255.  The value you'd
want the routine to return for a "char value" of -1 will
not be the correct value for EOF.

The stupid thing in these routines is that the behavior is
UNDEFINED for values outside the correct range.  We would
probably be doing ourselves (as programmers) a favor if we
made it a major error to pass in any negative value other
than the value for EOF.  Many programmers have read the
description of these routines, and never quite understood
that these routines do *not* take a parameter of 'char'.

I've seen people write updates to change:
      isblah((unsigned char)*someptr)
to   isblah(*someptr)
because they thought the original programmer was an idiot.

--
Garance Alistair Drosehn            =   [hidden email]
Senior Systems Programmer           or  [hidden email]
Rensselaer Polytechnic Institute    or  [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: [Patch:] restore the native use of isdigit() instead of ap_isdigit() in httpd.

Daniel Ouellet
In reply to this post by Daniel Boulet-2
Following strong advise, I am redoing this slower and much more
carefully with the justification as well included.

Only doing one file at a time, this round.

Hopefully this will be more welcome and useful.

Changes affected needs casts as none are (unsigned char) already.

All define in include/httpd.h as the following

struct request_rec {
...
        const char *range;
        char *protocol;
        const char *status_line;
...
}

So, new patch included.

Thanks.

Daniel

PS: I also change the spacing on the line I was working as well to make
it KNF.

================================

Index: http_protocol.c
===================================================================
RCS file: /cvs/src/usr.sbin/httpd/src/main/http_protocol.c,v
retrieving revision 1.30
diff -u -r1.30 http_protocol.c
--- http_protocol.c 11 Feb 2006 19:15:57 -0000 1.30
+++ http_protocol.c 31 Mar 2006 04:11:16 -0000
@@ -154,7 +154,7 @@
  return BYTERANGE_EMPTY;
      }

-    if (ap_isdigit(*r->range))
+    if (isdigit((unsigned char)*r->range))
  *start = ap_strtol(r->range, (char **)&r->range, 10);
      else
  *start = -1;
@@ -169,7 +169,7 @@
      while (ap_isspace(*r->range))
          ++r->range;

-    if (ap_isdigit(*r->range))
+    if (isdigit((unsigned char)*r->range))
  *end = ap_strtol(r->range, (char **)&r->range, 10);
      else
  *end = -1;
@@ -1011,9 +1011,9 @@
      /* Avoid sscanf in the common case */
      if (strlen(r->protocol) == 8
          && r->protocol[0] == 'H' && r->protocol[1] == 'T'
- && r->protocol[2] == 'T' && r->protocol[3] == 'P'
-        && r->protocol[4] == '/' && ap_isdigit(r->protocol[5])
- && r->protocol[6] == '.' && ap_isdigit(r->protocol[7])) {
+        && r->protocol[2] == 'T' && r->protocol[3] == 'P'
+        && r->protocol[4] == '/' && isdigit((unsigned char)r->protocol[5])
+        && r->protocol[6] == '.' && isdigit((unsigned
char)r->protocol[7])) {
          r->proto_num = HTTP_VERSION(r->protocol[5] - '0',
r->protocol[7] - '0');
      }
      else {
@@ -2768,9 +2768,9 @@
           */
          if (r->status_line != NULL
              && strlen(r->status_line) > 4       /* long enough */
-            && ap_isdigit(r->status_line[0])
-            && ap_isdigit(r->status_line[1])
-            && ap_isdigit(r->status_line[2])
+            && isdigit((unsigned char)r->status_line[0])
+            && isdigit((unsigned char)r->status_line[1])
+            && isdigit((unsigned char)r->status_line[2])
              && ap_isspace(r->status_line[3])
              && ap_isalnum(r->status_line[4])) {
              title = r->status_line;

Reply | Threaded
Open this post in threaded view
|

Re: [Patch:] restore the native use of isdigit() instead of ap_isdigit() in httpd.

Ted Unangst-2
In reply to this post by Daniel Boulet-2
On 3/30/06, Garance A Drosihn <[hidden email]> wrote:
> The stupid thing in these routines is that the behavior is
> UNDEFINED for values outside the correct range.  We would
> probably be doing ourselves (as programmers) a favor if we
> made it a major error to pass in any negative value other
> than the value for EOF.  Many programmers have read the
> description of these routines, and never quite understood
> that these routines do *not* take a parameter of 'char'.

i've thought about making all invalid values false.  while the current
openbsd implementation is safe, isdigit('1' + 256) returns true!

something like
int
isdigit(int c) {
    return c == EOF ? 0 : c < CHAR_MIN ? 0 : c > UCHAR_MAX ? 0 :
((_ctype_ + 1)[(unsigned char)c] & _N));
}