INN commit: branches/2.5 (8 files)

INN Commit rra at isc.org
Sun Aug 21 23:23:27 UTC 2011


    Date: Sunday, August 21, 2011 @ 16:23:26
  Author: eagle
Revision: 9364

Cast the argument to tolower()

Like the other ctype.h functions, tolower takes an int, which on systems
with signed chars can result in unexpected type promotion and broken
behavior.  Follow best practice of always casting the argument to an
unsigned char.

Remove some dead code in the innfeed config parser.

Modified:
  branches/2.5/backends/innxmit.c
  branches/2.5/innd/art.c
  branches/2.5/innd/cc.c
  branches/2.5/innd/keywords.c
  branches/2.5/innd/python.c
  branches/2.5/innfeed/configfile.y
  branches/2.5/lib/hash.c
  branches/2.5/nnrpd/nnrpd.c

----------------------+
 backends/innxmit.c   |    2 +-
 innd/art.c           |    2 +-
 innd/cc.c            |    4 ++--
 innd/keywords.c      |    2 +-
 innd/python.c        |    2 +-
 innfeed/configfile.y |   32 +-------------------------------
 lib/hash.c           |    2 +-
 nnrpd/nnrpd.c        |    2 +-
 8 files changed, 9 insertions(+), 39 deletions(-)

Modified: backends/innxmit.c
===================================================================
--- backends/innxmit.c	2011-08-21 23:22:01 UTC (rev 9363)
+++ backends/innxmit.c	2011-08-21 23:23:26 UTC (rev 9364)
@@ -208,7 +208,7 @@
     for (p = MessageID + 1; *p && (*p != '>'); p++) {
 	hash <<= 1;
 	if (isupper((unsigned char) *p)) {
-	    hash += tolower(*p);
+	    hash += tolower((unsigned char) *p);
 	} else {
 	    hash += *p;
 	}

Modified: innd/art.c
===================================================================
--- innd/art.c	2011-08-21 23:22:01 UTC (rev 9363)
+++ innd/art.c	2011-08-21 23:23:26 UTC (rev 9364)
@@ -2207,7 +2207,7 @@
     strlcpy(ControlWord, HDR(HDR__CONTROL), sizeof(ControlWord));
     for (p = ControlWord; *p && !ISWHITE(*p); p++)
       if (isupper((unsigned char) *p))
-	*p = tolower(*p);
+	*p = tolower((unsigned char) *p);
     *p = '\0';
     LikeNewgroup = (strcasecmp(ControlWord, "newgroup") == 0
                     || strcasecmp(ControlWord, "rmgroup") == 0);

Modified: innd/cc.c
===================================================================
--- innd/cc.c	2011-08-21 23:22:01 UTC (rev 9363)
+++ innd/cc.c	2011-08-21 23:23:26 UTC (rev 9364)
@@ -411,7 +411,7 @@
     if (Rest[0] != NF_FLAG_ALIAS) {
 	Rest[1] = '\0';
 	if (isupper((unsigned char) Rest[0]))
-	    Rest[0] = tolower(Rest[0]);
+	    Rest[0] = tolower((unsigned char) Rest[0]);
     }
     return CCdochange(ngp, Rest);
 }
@@ -1002,7 +1002,7 @@
     if (Rest[0] != NF_FLAG_ALIAS) {
 	Rest[1] = '\0';
 	if (isupper((unsigned char) Rest[0]))
-	    Rest[0] = tolower(Rest[0]);
+	    Rest[0] = tolower((unsigned char) Rest[0]);
     }
 
     who = av[2];

Modified: innd/keywords.c
===================================================================
--- innd/keywords.c	2011-08-21 23:22:01 UTC (rev 9363)
+++ innd/keywords.c	2011-08-21 23:23:26 UTC (rev 9364)
@@ -185,7 +185,7 @@
 	/* Squash to lowercase. */
 	for (chase = this_word; *chase; chase++)
 	    if (isupper((unsigned char) *chase))
-		*chase = tolower(*chase);
+		*chase = tolower((unsigned char) *chase);
     }
 
     /* If there were no words, we're done. */

Modified: innd/python.c
===================================================================
--- innd/python.c	2011-08-21 23:22:01 UTC (rev 9363)
+++ innd/python.c	2011-08-21 23:23:26 UTC (rev 9364)
@@ -525,7 +525,7 @@
                 }
                 wasspace = true;
 	    } else {
-                *q++ = tolower(*p);
+                *q++ = tolower((unsigned char) *p);
                 wasspace = false;
             }
             p++;

Modified: innfeed/configfile.y
===================================================================
--- innfeed/configfile.y	2011-08-21 23:22:01 UTC (rev 9363)
+++ innfeed/configfile.y	2011-08-21 23:23:26 UTC (rev 9364)
@@ -530,42 +530,12 @@
   t->scope_type = xstrdup (type) ;
 
   for (i = 0 ; t->scope_type[i] != '\0' ; i++)
-    t->scope_type[i] = tolower (t->scope_type[i]) ;
+    t->scope_type[i] = tolower ((unsigned char) t->scope_type[i]) ;
 
   return t ;
 }
 
 
-
-#if 0
-static int strNCaseCmp (const char *a, const char *b, size_t len)
-{
-  while (a && b && *a && *b && (tolower (*a) == tolower (*b)) && len > 0)
-    a++, b++, len-- ;
-
-  if (a == NULL && b == NULL)
-    return 0 ;
-  else if (a == NULL)
-    return 1 ;
-  else if (b == NULL)
-    return -1 ;
-  else if (*a == '\0' && *b == '\0')
-    return 0 ;
-  else if (*a == '\0')
-    return 1 ;
-  else if (*b == '\0')
-    return -1 ;
-  else if (*a < *b)
-    return 1 ;
-  else if (*a > *b)
-    return -1 ;
-  else
-    return 0 ;
-
-  abort () ;
-}
-#endif
-
 #define BAD_KEY "line %d: illegal key name: %s"
 #define NON_ALPHA "line %d: keys must start with a letter: %s"
 

Modified: lib/hash.c
===================================================================
--- lib/hash.c	2011-08-21 23:22:01 UTC (rev 9363)
+++ lib/hash.c	2011-08-21 23:23:26 UTC (rev 9364)
@@ -78,7 +78,7 @@
     }
     if (new != NULL)
         for (q = new + (p - MessageID); *q != '\0'; q++)
-            *q = tolower(*q);
+            *q = tolower((unsigned char) *q);
     hash = Hash(new ? new : MessageID, len);
     if (new != NULL)
 	free(new);

Modified: nnrpd/nnrpd.c
===================================================================
--- nnrpd/nnrpd.c	2011-08-21 23:22:01 UTC (rev 9363)
+++ nnrpd/nnrpd.c	2011-08-21 23:23:26 UTC (rev 9364)
@@ -519,7 +519,7 @@
     if (valid) {
         for (p = hostname; *p != '\0'; p++)
             if (isupper((unsigned char) *p))
-                *p = tolower((int) *p);
+                *p = tolower((unsigned char) *p);
         return true;
     } else {
 	HostErrorStr = MISMATCH;




More information about the inn-committers mailing list