X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=servers%2Fslapd%2Fresult.c;h=bb27c760f3638cbc3cd7872e5db45e9fea6d416d;hb=d1824b14ae78b128fb9ff6cf73d2ec4a0e756a90;hp=f91be836ae33b5fa181752e6a0b9f618bfd86220;hpb=5181a522c171490eaa3266b52c82079ddcfba21c;p=openldap diff --git a/servers/slapd/result.c b/servers/slapd/result.c index f91be836ae..bb27c760f3 100644 --- a/servers/slapd/result.c +++ b/servers/slapd/result.c @@ -1466,9 +1466,43 @@ str2result( } if ( strncasecmp( s, "code", STRLENOF( "code" ) ) == 0 ) { - if ( c != NULL ) { - *code = atoi( c ); + char *next = NULL; + long retcode; + + if ( c == NULL ) { + Debug( LDAP_DEBUG_ANY, "str2result (%s) missing value\n", + s, 0, 0 ); + rc = -1; + continue; + } + + while ( isspace( (unsigned char) c[ 0 ] ) ) c++; + if ( c[ 0 ] == '\0' ) { + Debug( LDAP_DEBUG_ANY, "str2result (%s) missing or empty value\n", + s, 0, 0 ); + rc = -1; + continue; + } + + retcode = strtol( c, &next, 10 ); + if ( next == NULL || next == c ) { + Debug( LDAP_DEBUG_ANY, "str2result (%s) unable to parse value\n", + s, 0, 0 ); + rc = -1; + continue; } + + while ( isspace( (unsigned char) next[ 0 ] ) ) next++; + if ( next[ 0 ] != '\0' ) { + Debug( LDAP_DEBUG_ANY, "str2result (%s) extra cruft after value\n", + s, 0, 0 ); + rc = -1; + continue; + } + + /* FIXME: what if it's larger that max int? */ + *code = (int)retcode; + } else if ( strncasecmp( s, "matched", STRLENOF( "matched" ) ) == 0 ) { if ( c != NULL ) { *matched = c;