From 709ce4fa6c0a8aea66c4b6e15bf42aa3352ad2e2 Mon Sep 17 00:00:00 2001 From: Kurt Zeilenga Date: Mon, 15 Apr 2002 20:42:42 +0000 Subject: [PATCH] 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. --- clients/maildap/main.c | 14 +++++++------- clients/tools/ldapmodify.c | 4 ++-- libraries/liblber/bprint.c | 2 +- libraries/libldap/cyrus.c | 6 +++--- servers/slapd/aclparse.c | 10 +++++----- servers/slapd/back-passwd/search.c | 2 +- servers/slapd/back-sql/util.c | 9 ++++++++- servers/slapd/config.c | 2 +- servers/slapd/referral.c | 2 +- servers/slapd/schema_init.c | 6 +++--- 10 files changed, 32 insertions(+), 25 deletions(-) diff --git a/clients/maildap/main.c b/clients/maildap/main.c index f8fd751779..345c8f4256 100644 --- a/clients/maildap/main.c +++ b/clients/maildap/main.c @@ -419,9 +419,9 @@ get_config_line( FILE *cf, int *lineno) (*lineno)++; 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++ ) { *d = *s; @@ -518,20 +518,20 @@ add_attr_semantics( char *s ) as = calloc( 1, sizeof( AttrSemantics ) ); 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'; as->as_name = strdup( p ); p = q + 1; 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'; if ( !strcasecmp( p, "multivalued" ) ) { @@ -554,7 +554,7 @@ add_attr_semantics( char *s ) q = strchr( p, '=' ); if ( q ) { p = q + 1; - while ( *q && !isspace( *q ) ) { + while ( *q && !isspace( (unsigned char) *q ) ) { q++; } if ( *q ) { diff --git a/clients/tools/ldapmodify.c b/clients/tools/ldapmodify.c index 8db5c81776..f55cb80aa1 100644 --- a/clients/tools/ldapmodify.c +++ b/clients/tools/ldapmodify.c @@ -812,7 +812,7 @@ process_ldif_rec( char *rbuf, int count ) int icnt; for ( icnt = val.bv_len; --icnt > 0; ) { - if ( !isspace( val.bv_val[icnt] ) ) { + if ( !isspace( (unsigned char) val.bv_val[icnt] ) ) { break; } } @@ -857,7 +857,7 @@ process_ldif_rec( char *rbuf, int count ) 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 --git a/libraries/liblber/bprint.c b/libraries/liblber/bprint.c index a6ae8ce7ed..23ebf88853 100644 --- a/libraries/liblber/bprint.c +++ b/libraries/liblber/bprint.c @@ -285,7 +285,7 @@ int ber_output_dump( 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 { line[ BP_GRAPH + n ] = '.'; diff --git a/libraries/libldap/cyrus.c b/libraries/libldap/cyrus.c index 5f128098d3..d14e893c05 100644 --- a/libraries/libldap/cyrus.c +++ b/libraries/libldap/cyrus.c @@ -846,7 +846,7 @@ int ldap_pvt_sasl_secprops( } else if( !strncasecmp(props[i], "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")] ); } else { @@ -856,7 +856,7 @@ int ldap_pvt_sasl_secprops( } else if( !strncasecmp(props[i], "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")] ); } else { @@ -866,7 +866,7 @@ int ldap_pvt_sasl_secprops( } else if( !strncasecmp(props[i], "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")] ); } else { diff --git a/servers/slapd/aclparse.c b/servers/slapd/aclparse.c index 95397c2668..1c8a5bad37 100644 --- a/servers/slapd/aclparse.c +++ b/servers/slapd/aclparse.c @@ -1191,19 +1191,19 @@ str2accessmask( const char *str ) } 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); } else if( str[i] != '0' ) { diff --git a/servers/slapd/back-passwd/search.c b/servers/slapd/back-passwd/search.c index 2cdeb4c9cf..83db8ae5fe 100644 --- a/servers/slapd/back-passwd/search.c +++ b/servers/slapd/back-passwd/search.c @@ -325,7 +325,7 @@ pw2entry( Backend *be, struct passwd *pw, const char **text ) strncpy(buf, vals[0].bv_val, i); 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 --git a/servers/slapd/back-sql/util.c b/servers/slapd/back-sql/util.c index fcb1254db2..00e1d33889 100644 --- a/servers/slapd/back-sql/util.c +++ b/servers/slapd/back-sql/util.c @@ -115,7 +115,14 @@ char* backsql_get_table_spec(char **p) if (**p) *(*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*/ s=q; diff --git a/servers/slapd/config.c b/servers/slapd/config.c index 06016c0a76..2865316814 100644 --- a/servers/slapd/config.c +++ b/servers/slapd/config.c @@ -2222,7 +2222,7 @@ read_config( const char *fname ) if ( rc ) 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, LDAP_OPT_X_TLS_REQUIRE_CERT, diff --git a/servers/slapd/referral.c b/servers/slapd/referral.c index d3caa3ffd4..53edf251fb 100644 --- a/servers/slapd/referral.c +++ b/servers/slapd/referral.c @@ -314,7 +314,7 @@ BerVarray get_entry_referrals( /* 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; break; diff --git a/servers/slapd/schema_init.c b/servers/slapd/schema_init.c index 8695cd8fe6..fb82f181b3 100644 --- a/servers/slapd/schema_init.c +++ b/servers/slapd/schema_init.c @@ -98,11 +98,11 @@ static const struct MatchingRulePtr { }; -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; -- 2.39.5