From 1a0660f4fa2da22a6918078442afffba51c8c225 Mon Sep 17 00:00:00 2001 From: Rich Megginson <rmeggins@xxxxxxxxxx> Date: Thu, 17 Nov 2011 09:41:06 -0700 Subject: [PATCH] use slapi_hexchar2int and slapi_str_to_u8 everywhere uniqueid code was using local str2Byte - use slapi_str_to_u8 instead there were several places using a copy of the old hexchar2int - change them to use slapi_hexchar2int instead --- ldap/servers/plugins/cos/cos_cache.c | 23 +----------- ldap/servers/slapd/dn.c | 23 ++---------- ldap/servers/slapd/proto-slap.h | 1 - ldap/servers/slapd/str2filter.c | 4 +- ldap/servers/slapd/uniqueid.c | 67 +++++++++------------------------- ldap/servers/slapd/util.c | 6 +-- 6 files changed, 28 insertions(+), 96 deletions(-) diff --git a/ldap/servers/plugins/cos/cos_cache.c b/ldap/servers/plugins/cos/cos_cache.c index 6265728..b2237ee 100644 --- a/ldap/servers/plugins/cos/cos_cache.c +++ b/ldap/servers/plugins/cos/cos_cache.c @@ -326,8 +326,6 @@ static int cos_cache_vattr_compare(vattr_sp_handle *handle, vattr_context *c, Sl static int cos_cache_vattr_types(vattr_sp_handle *handle,Slapi_Entry *e,vattr_type_list_context *type_context,int flags); static int cos_cache_query_attr(cos_cache *ptheCache, vattr_context *context, Slapi_Entry *e, char *type, Slapi_ValueSet **out_attr, Slapi_Value *test_this, int *result, int *ops); -static int hexchar2int( char c ); - /* compares s2 to s1 starting from end of string until the beginning of either matches result in the s2 value being clipped from s1 with a NULL char @@ -1986,8 +1984,8 @@ static int cos_cache_add_tmpl(cosTemplates **pTemplates, cosAttrValue *dn, cosAt if ((index+2 <= lastindex) && isxdigit(dn->val[index+1]) && isxdigit(dn->val[index+2])) { /* Convert ESC HEX HEX to a real char */ - int n = hexchar2int(dn->val[index+1]); - int n2 = hexchar2int(dn->val[index+2]); + int n = slapi_hexchar2int(dn->val[index+1]); + int n2 = slapi_hexchar2int(dn->val[index+2]); n = (n << 4) + n2; if (n == 0) { /* don't change \00 */ grade[grade_index] = dn->val[index++]; /* '\\' */ @@ -3648,20 +3646,3 @@ static int cos_cache_entry_is_cos_related( Slapi_Entry *e) { } return(rc); } - -/* copied from dn.c */ -static int -hexchar2int( char c ) -{ - if ( '0' <= c && c <= '9' ) { - return( c - '0' ); - } - if ( 'a' <= c && c <= 'f' ) { - return( c - 'a' + 10 ); - } - if ( 'A' <= c && c <= 'F' ) { - return( c - 'A' + 10 ); - } - return( -1 ); -} - diff --git a/ldap/servers/slapd/dn.c b/ldap/servers/slapd/dn.c index ec92790..4c04ae5 100644 --- a/ldap/servers/slapd/dn.c +++ b/ldap/servers/slapd/dn.c @@ -62,21 +62,6 @@ static int rdn_av_cmp( struct berval *av1, struct berval *av2 ); static void rdn_av_swap( struct berval *av1, struct berval *av2, int escape ); -int -hexchar2int( char c ) -{ - if ( '0' <= c && c <= '9' ) { - return( c - '0' ); - } - if ( 'a' <= c && c <= 'f' ) { - return( c - 'a' + 10 ); - } - if ( 'A' <= c && c <= 'F' ) { - return( c - 'A' + 10 ); - } - return( -1 ); -} - #define ISBLANK(c) ((c) == ' ') #define ISBLANKSTR(s) (((*(s)) == '2') && (*((s)+1) == '0')) #define ISSPACE(c) (ISBLANK(c) || ((c) == '\n') || ((c) == '\r')) /* XXX 518524 */ @@ -398,9 +383,9 @@ substr_dn_normalize_orig( char *dn, char *end ) } else { gotesc = 1; if ( s+2 < end ) { - int n = hexchar2int( s[1] ); + int n = slapi_hexchar2int( s[1] ); if ( n >= 0 && n < 16 ) { - int n2 = hexchar2int( s[2] ); + int n2 = slapi_hexchar2int( s[2] ); if ( n2 >= 0 ) { n = (n << 4) + n2; if (n == 0) { /* don't change \00 */ @@ -841,8 +826,8 @@ slapi_dn_normalize_ext(char *src, size_t src_len, char **dest, size_t *dest_len) } else if (s + 2 < ends && isxdigit(*(s+1)) && isxdigit(*(s+2))) { /* esc hexpair ==> real character */ - int n = hexchar2int(*(s+1)); - int n2 = hexchar2int(*(s+2)); + int n = slapi_hexchar2int(*(s+1)); + int n2 = slapi_hexchar2int(*(s+2)); n = (n << 4) + n2; if (n == 0) { /* don't change \00 */ *d++ = *++s; diff --git a/ldap/servers/slapd/proto-slap.h b/ldap/servers/slapd/proto-slap.h index 69a7554..9964043 100644 --- a/ldap/servers/slapd/proto-slap.h +++ b/ldap/servers/slapd/proto-slap.h @@ -571,7 +571,6 @@ void raise_process_limits( void ); * dn.c */ char *substr_dn_normalize( char *dn, char *end ); -int hexchar2int( char c ); /* diff --git a/ldap/servers/slapd/str2filter.c b/ldap/servers/slapd/str2filter.c index 9ffcf24..e6a9996 100644 --- a/ldap/servers/slapd/str2filter.c +++ b/ldap/servers/slapd/str2filter.c @@ -213,7 +213,7 @@ filt_unescape_str(const char *instr, char *outstr, size_t outsize, size_t* outle { if (! *(++inp)) return 0; /* fail */ - if (((ival = hexchar2int(inp[0])) < 0) || (hexchar2int(inp[1]) < 0)) + if (((ival = slapi_hexchar2int(inp[0])) < 0) || (slapi_hexchar2int(inp[1]) < 0)) { /* LDAPv2 (RFC1960) escape sequence */ *outp++ = *inp; @@ -224,7 +224,7 @@ filt_unescape_str(const char *instr, char *outstr, size_t outsize, size_t* outle /* LDAPv3 hex escape sequence */ if (! *(++inp)) return 0; /* fail */ - *outp = (ival << 4) | hexchar2int(*inp); + *outp = (ival << 4) | slapi_hexchar2int(*inp); if ((!binary) && (!*outp)) return 0; /* fail: "\00" not allowed unless it's binary */ outp++; diff --git a/ldap/servers/slapd/uniqueid.c b/ldap/servers/slapd/uniqueid.c index 7764465..979e06b 100644 --- a/ldap/servers/slapd/uniqueid.c +++ b/ldap/servers/slapd/uniqueid.c @@ -221,25 +221,25 @@ int slapi_uniqueIDScan (Slapi_UniqueID *uId, const char *buff){ return UID_BADDATA; } - ((PRUint8 *) &uId->time_low)[0] = str2Byte (&(buff[0])); - ((PRUint8 *) &uId->time_low)[1] = str2Byte (&(buff[2])); - ((PRUint8 *) &uId->time_low)[2] = str2Byte (&(buff[4])); - ((PRUint8 *) &uId->time_low)[3] = str2Byte (&(buff[6])); + ((PRUint8 *) &uId->time_low)[0] = slapi_str_to_u8 (&(buff[0])); + ((PRUint8 *) &uId->time_low)[1] = slapi_str_to_u8 (&(buff[2])); + ((PRUint8 *) &uId->time_low)[2] = slapi_str_to_u8 (&(buff[4])); + ((PRUint8 *) &uId->time_low)[3] = slapi_str_to_u8 (&(buff[6])); /* next field is at 9 because we skip the - */ - ((PRUint8 *) &uId->time_mid)[0] = str2Byte (&(buff[9])); - ((PRUint8 *) &uId->time_mid)[1] = str2Byte (&(buff[11])); - ((PRUint8 *) &uId->time_hi_and_version)[0] = str2Byte (&(buff[13])); - ((PRUint8 *) &uId->time_hi_and_version)[1] = str2Byte (&(buff[15])); + ((PRUint8 *) &uId->time_mid)[0] = slapi_str_to_u8 (&(buff[9])); + ((PRUint8 *) &uId->time_mid)[1] = slapi_str_to_u8 (&(buff[11])); + ((PRUint8 *) &uId->time_hi_and_version)[0] = slapi_str_to_u8 (&(buff[13])); + ((PRUint8 *) &uId->time_hi_and_version)[1] = slapi_str_to_u8 (&(buff[15])); /* next field is at 18 because we skip the - */ - uId->clock_seq_hi_and_reserved = str2Byte (&(buff[18])); - uId->clock_seq_low = str2Byte (&(buff[20])); - uId->node[0] = str2Byte (&(buff[22])); - uId->node[1] = str2Byte (&(buff[24])); + uId->clock_seq_hi_and_reserved = slapi_str_to_u8 (&(buff[18])); + uId->clock_seq_low = slapi_str_to_u8 (&(buff[20])); + uId->node[0] = slapi_str_to_u8 (&(buff[22])); + uId->node[1] = slapi_str_to_u8 (&(buff[24])); /* next field is at 27 because we skip the - */ - uId->node[2] = str2Byte (&(buff[27])); - uId->node[3] = str2Byte (&(buff[29])); - uId->node[4] = str2Byte (&(buff[31])); - uId->node[5] = str2Byte (&(buff[33])); + uId->node[2] = slapi_str_to_u8 (&(buff[27])); + uId->node[3] = slapi_str_to_u8 (&(buff[29])); + uId->node[4] = slapi_str_to_u8 (&(buff[31])); + uId->node[5] = slapi_str_to_u8 (&(buff[33])); uId->time_low = ntohl(uId->time_low); uId->time_mid = ntohs(uId->time_mid); @@ -288,49 +288,18 @@ Slapi_UniqueID* slapi_uniqueIDDup (Slapi_UniqueID *uId) /* helper functions */ -static char hexDigits[] = {'0', '1', '2', '3', '4', '5', '6', '7', - '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', '\0'}; -/* this function converts a string representation of a byte in hex into - an actual byte. For instance: "AB" -> 171 */ -static PRUint8 str2Byte (const char *str) -{ - char letter1 = str[0]; - char letter2 = str[1]; - PRUint8 num = 0; - int i = 0; - - while (hexDigits[i] != '\0') - { - if (letter1 == hexDigits[i] || toupper (letter1) == hexDigits[i]) - { - num |= (i << 4); - } - - if (letter2 == hexDigits[i] || toupper (letter2) == hexDigits[i]) - { - num |= i; - } - - i++; - } - - return num; -} - static char* format = "XXXXXXXX-XXXXXXXX-XXXXXXXX-XXXXXXXX"; +static size_t format_len = 35; /* This function verifies that buff contains data in the correct format (specified above). */ static int isValidFormat (const char * buff) { - int len; int i; if (strlen (buff) != strlen (format)) return UID_BADDATA; - len = strlen (format); - - for (i = 0; i < len; i++) + for (i = 0; i < format_len; i++) { if (format[i] == '-' && buff [i] != '-') return 0; diff --git a/ldap/servers/slapd/util.c b/ldap/servers/slapd/util.c index 58d4dfa..fd5ebcb 100644 --- a/ldap/servers/slapd/util.c +++ b/ldap/servers/slapd/util.c @@ -231,9 +231,9 @@ strcpy_unescape_value( char *d, const char *s ) case '\\': gotesc = 1; if ( s+2 < end ) { - int n = hexchar2int( s[1] ); + int n = slapi_hexchar2int( s[1] ); if ( n >= 0 && n < 16 ) { - int n2 = hexchar2int( s[2] ); + int n2 = slapi_hexchar2int( s[2] ); if ( n2 >= 0 ) { n = (n << 4) + n2; if (n == 0) { /* don't change \00 */ @@ -1024,8 +1024,6 @@ static const int char2intarray[] = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }; -static const int char2intarray_size = sizeof(char2intarray)/sizeof(char2intarray[0]); - int slapi_hexchar2int(char c) { -- 1.7.1
-- 389-devel mailing list 389-devel@xxxxxxxxxxxxxxxxxxxxxxx https://admin.fedoraproject.org/mailman/listinfo/389-devel