From: Pierangelo Masarati Date: Wed, 19 Apr 2006 23:57:02 +0000 (+0000) Subject: re-fix ITS#4495 working around atoi() limitations X-Git-Tag: OPENLDAP_REL_ENG_2_4_1ALPHA~2^2~164 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=19c5f261e5572b23d11be7e42d2fd0fae08f87a7;p=openldap re-fix ITS#4495 working around atoi() limitations --- diff --git a/servers/slapd/result.c b/servers/slapd/result.c index f91be836ae..11e2c962f3 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( 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( 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;