Re: Patch: ctype functions require 'unsigned char' args (ITS#1678) ================ Written by Hallvard B. Furuseth and placed into the public domain. This software is not subject to any license of the University of Oslo. ================ Here are fixes for more places where the argument to ctype.h functions should be in the range of `unsigned char'. Explanation of the last patch (to schema_init.c:bvcasechr()): TOLOWER() and TOUPPER() return values in the range of `unsigned char', but bvcasechr() then compares those values with a plain `char'. So I convert the return values from TOLOWER()/TOUPPER() to `char' first. Hallvard B. Furuseth , April 2002. diff -u2 -r clients/maildap/main.c~ clients/maildap/main.c --- clients/maildap/main.c~ Fri Jan 4 21:17:30 2002 +++ clients/maildap/main.c Sun Apr 14 12:09:18 2002 @@ -420,7 +420,7 @@ if ( pos > 0 ) { /* Delete whitespace at the beginning of new data */ - if ( isspace( buf[pos] ) ) { + if ( isspace( (unsigned char) buf[pos] ) ) { char *s, *d; - for ( s = buf+pos; isspace(*s); s++ ) + for ( s = buf+pos; isspace((unsigned char) *s); s++ ) ; for ( d = buf+pos; *s; s++, d++ ) { @@ -519,8 +519,8 @@ as->as_priority = current_priority; p = s; - while ( isspace ( *p ) ) + while ( isspace ( (unsigned char) *p ) ) p++; q = p; - while ( !isspace ( *q ) && *q != '\0' ) + while ( !isspace ( (unsigned char) *q ) && *q != '\0' ) q++; *q = '\0'; @@ -529,8 +529,8 @@ while ( *p ) { - while ( isspace ( *p ) ) + while ( isspace ( (unsigned char) *p ) ) p++; q = p; - while ( !isspace ( *q ) && *q != '\0' ) + while ( !isspace ( (unsigned char) *q ) && *q != '\0' ) q++; *q = '\0'; @@ -555,5 +555,5 @@ if ( q ) { p = q + 1; - while ( *q && !isspace( *q ) ) { + while ( *q && !isspace( (unsigned char) *q ) ) { q++; } diff -u2 -r clients/tools/ldapmodify.c~ clients/tools/ldapmodify.c --- clients/tools/ldapmodify.c~ Fri Feb 8 19:10:06 2002 +++ clients/tools/ldapmodify.c Sun Apr 14 14:43:03 2002 @@ -813,5 +813,5 @@ int icnt; for ( icnt = val.bv_len; --icnt > 0; ) { - if ( !isspace( val.bv_val[icnt] ) ) { + if ( !isspace( (unsigned char) val.bv_val[icnt] ) ) { break; } @@ -858,5 +858,5 @@ int icnt; for ( icnt = val.bv_len; --icnt > 0; ) { - if ( !isspace( val.bv_val[icnt] ) ) { + if ( !isspace( (unsigned char) val.bv_val[icnt] ) ) { break; } diff -u2 -r libraries/liblber/bprint.c~ libraries/liblber/bprint.c --- libraries/liblber/bprint.c~ Mon Apr 8 10:55:56 2002 +++ libraries/liblber/bprint.c Sat Apr 13 18:30:45 2002 @@ -286,5 +286,5 @@ off = BP_GRAPH + n + ((n >= 8)?1:0); - if ( isprint( data[i] )) { + if ( isprint( (unsigned char) data[i] )) { line[ BP_GRAPH + n ] = data[i]; } else { diff -u2 -r libraries/libldap/cyrus.c~ libraries/libldap/cyrus.c --- libraries/libldap/cyrus.c~ Wed Mar 27 19:12:18 2002 +++ libraries/libldap/cyrus.c Sat Apr 13 18:31:34 2002 @@ -847,5 +847,5 @@ "minssf=", sizeof("minssf")) ) { - if( isdigit( props[i][sizeof("minssf")] ) ) { + if( isdigit( (unsigned char) props[i][sizeof("minssf")] ) ) { got_min_ssf++; min_ssf = atoi( &props[i][sizeof("minssf")] ); @@ -857,5 +857,5 @@ "maxssf=", sizeof("maxssf")) ) { - if( isdigit( props[i][sizeof("maxssf")] ) ) { + if( isdigit( (unsigned char) props[i][sizeof("maxssf")] ) ) { got_max_ssf++; max_ssf = atoi( &props[i][sizeof("maxssf")] ); @@ -867,5 +867,5 @@ "maxbufsize=", sizeof("maxbufsize")) ) { - if( isdigit( props[i][sizeof("maxbufsize")] ) ) { + if( isdigit( (unsigned char) props[i][sizeof("maxbufsize")] ) ) { got_maxbufsize++; maxbufsize = atoi( &props[i][sizeof("maxbufsize")] ); diff -u2 -r servers/slapd/aclparse.c~ servers/slapd/aclparse.c --- servers/slapd/aclparse.c~ Thu Apr 4 11:15:40 2002 +++ servers/slapd/aclparse.c Sun Apr 14 14:51:14 2002 @@ -1192,17 +1192,17 @@ for( i=1; str[i] != '\0'; i++ ) { - if( TOLOWER(str[i]) == 'w' ) { + if( TOLOWER((unsigned char) str[i]) == 'w' ) { ACL_PRIV_SET(mask, ACL_PRIV_WRITE); - } else if( TOLOWER(str[i]) == 'r' ) { + } else if( TOLOWER((unsigned char) str[i]) == 'r' ) { ACL_PRIV_SET(mask, ACL_PRIV_READ); - } else if( TOLOWER(str[i]) == 's' ) { + } else if( TOLOWER((unsigned char) str[i]) == 's' ) { ACL_PRIV_SET(mask, ACL_PRIV_SEARCH); - } else if( TOLOWER(str[i]) == 'c' ) { + } else if( TOLOWER((unsigned char) str[i]) == 'c' ) { ACL_PRIV_SET(mask, ACL_PRIV_COMPARE); - } else if( TOLOWER(str[i]) == 'x' ) { + } else if( TOLOWER((unsigned char) str[i]) == 'x' ) { ACL_PRIV_SET(mask, ACL_PRIV_AUTH); diff -u2 -r servers/slapd/back-passwd/search.c~ servers/slapd/back-passwd/search.c --- servers/slapd/back-passwd/search.c~ Fri Apr 12 10:42:23 2002 +++ servers/slapd/back-passwd/search.c Sun Apr 14 14:53:22 2002 @@ -326,5 +326,5 @@ s = buf+i; strcpy(s, pw->pw_name); - *s = TOUPPER(*s); + *s = TOUPPER((unsigned char)*s); strcat(s, vals[0].bv_val+i+1); vals[0].bv_val = buf; diff -u2 -r servers/slapd/back-sql/util.c~ servers/slapd/back-sql/util.c --- servers/slapd/back-sql/util.c~ Mon Oct 22 13:23:09 2001 +++ servers/slapd/back-sql/util.c Sun Apr 14 14:47:54 2002 @@ -116,5 +116,12 @@ *(*p)++='\0'; -#define BACKSQL_NEXT_WORD {while (*s && isspace(*s)) s++; if (!*s) return res; q=s; while (*q && !isspace(*q)) q++; if (*q) *q++='\0';} +#define BACKSQL_NEXT_WORD { \ + while (*s && isspace((unsigned char)*s)) s++; \ + if (!*s) return res; \ + q=s; \ + while (*q && !isspace((unsigned char)*q)) q++; \ + if (*q) *q++='\0'; \ + } + BACKSQL_NEXT_WORD; res=backsql_strcat(res,&res_len,s,NULL);/*table name*/ diff -u2 -r servers/slapd/config.c~ servers/slapd/config.c --- servers/slapd/config.c~ Mon Apr 8 19:56:58 2002 +++ servers/slapd/config.c Sat Apr 13 18:14:05 2002 @@ -2231,5 +2231,5 @@ return rc; } else if ( !strcasecmp( cargv[0], "TLSVerifyClient" ) ) { - if ( isdigit( cargv[1][0] ) ) { + if ( isdigit( (unsigned char) cargv[1][0] ) ) { i = atoi(cargv[1]); rc = ldap_pvt_tls_set_option( NULL, diff -u2 -r servers/slapd/referral.c~ servers/slapd/referral.c --- servers/slapd/referral.c~ Fri Apr 12 10:42:21 2002 +++ servers/slapd/referral.c Sat Apr 13 18:32:38 2002 @@ -315,5 +315,5 @@ /* trim the label */ for( k=0; kbv_len; k++ ) { - if( isspace(jv->bv_val[k]) ) { + if( isspace( (unsigned char) jv->bv_val[k] ) ) { jv->bv_val[k] = '\0'; jv->bv_len = k; diff -u2 -r servers/slapd/schema_init.c~ servers/slapd/schema_init.c --- servers/slapd/schema_init.c~ Mon Apr 8 10:55:59 2002 +++ servers/slapd/schema_init.c Sun Apr 14 14:52:47 2002 @@ -99,9 +99,9 @@ -static char *bvcasechr( struct berval *bv, int c, ber_len_t *len ) +static char *bvcasechr( struct berval *bv, unsigned char c, ber_len_t *len ) { ber_len_t i; - int lower = TOLOWER( c ); - int upper = TOUPPER( c ); + char lower = TOLOWER( c ); + char upper = TOUPPER( c ); if( c == 0 ) return NULL;