From 19c5f261e5572b23d11be7e42d2fd0fae08f87a7 Mon Sep 17 00:00:00 2001 From: Pierangelo Masarati Date: Wed, 19 Apr 2006 23:57:02 +0000 Subject: [PATCH] re-fix ITS#4495 working around atoi() limitations --- servers/slapd/result.c | 38 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) 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; -- 2.39.5