Browse Source

r8692@Kushana: nickm | 2006-08-31 13:38:07 -0400
Fix bug 327 (part 2): Cast char to unsigned char before passing to toupper/tolower. (Follow the same idiom as with isupper and friends, in case we run into the same problem on SGI or whereever it was.)


svn:r8310

Nick Mathewson 18 years ago
parent
commit
f170e5798f
5 changed files with 8 additions and 5 deletions
  1. 3 0
      src/common/compat.h
  2. 1 1
      src/common/container.c
  3. 2 2
      src/common/util.c
  4. 1 1
      src/or/config.c
  5. 1 1
      src/or/routerparse.c

+ 3 - 0
src/common/compat.h

@@ -155,6 +155,9 @@ const void *tor_memmem(const void *haystack, size_t hlen, const void *needle,
 #define TOR_ISLOWER(c)   islower((int)(unsigned char)(c))
 #define TOR_ISUPPER(c)   isupper((int)(unsigned char)(c))
 
+#define TOR_TOLOWER(c)   ((char)tolower((int)(unsigned char)(c)))
+#define TOR_TOUPPER(c)   ((char)toupper((int)(unsigned char)(c)))
+
 #ifdef MS_WINDOWS
 #define _SHORT_FILE_ (tor_fix_source_file(__FILE__))
 const char *tor_fix_source_file(const char *fname);

+ 1 - 1
src/common/container.c

@@ -824,7 +824,7 @@ strmap_remove_lc(strmap_t *map, const char *key)
  *       iter = strmap_iter_next_rmv(iter);
  *       free(val);
  *    } else {
- *       for (;*cp;cp++) *cp = toupper(*cp);
+ *       for (;*cp;cp++) *cp = TOR_TOUPPER(*cp);
  *       iter = strmap_iter_next(iter);
  *    }
  * }

+ 2 - 2
src/common/util.c

@@ -308,7 +308,7 @@ void
 tor_strlower(char *s)
 {
   while (*s) {
-    *s = tolower(*s);
+    *s = TOR_TOLOWER(*s);
     ++s;
   }
 }
@@ -319,7 +319,7 @@ void
 tor_strupper(char *s)
 {
   while (*s) {
-    *s = toupper(*s);
+    *s = TOR_TOUPPER(*s);
     ++s;
   }
 }

+ 1 - 1
src/or/config.c

@@ -1737,7 +1737,7 @@ get_default_nickname(void)
       *cp = '\0';
       break;
     }
-    *cp = tolower(*cp);
+    *cp = TOR_TOLOWER(*cp);
   }
 
   /* Strip invalid characters. */

+ 1 - 1
src/or/routerparse.c

@@ -1279,7 +1279,7 @@ router_parse_addr_policy_from_string(const char *s, int assume_action)
   len = strlen(s);
   cp = tmp = tor_malloc(len+2);
   for (idx = 0; idx < len; ++idx) {
-    tmp[idx] = tolower(s[idx]);
+    tmp[idx] = TOR_TOLOWER(s[idx]);
   }
   tmp[len]='\n';
   tmp[len+1]='\0';