From d34fffcaf9edc00262209fbe6e04bb15805dbd37 Mon Sep 17 00:00:00 2001 From: Pierangelo Masarati Date: Thu, 24 Nov 2005 01:10:05 +0000 Subject: [PATCH] use lutil_ato*() whenever appropriate --- clients/tools/ldapmodify.c | 10 ++- contrib/slapd-modules/smbk5pwd/smbk5pwd.c | 12 ++- include/lutil.h | 13 +++- libraries/libldap/cyrus.c | 4 +- libraries/libldap/url.c | 4 +- libraries/liblutil/utils.c | 16 ++-- libraries/librewrite/config.c | 22 +++++- libraries/librewrite/rewrite-int.h | 2 +- libraries/librewrite/rewrite.c | 5 +- libraries/librewrite/rule.c | 4 +- servers/slapd/acl.c | 5 +- servers/slapd/aclparse.c | 17 ++--- servers/slapd/back-bdb/config.c | 21 +++++- servers/slapd/back-ldap/config.c | 4 +- servers/slapd/back-ldbm/config.c | 32 +++++--- servers/slapd/back-meta/back-meta.h | 4 +- servers/slapd/back-sql/entry-id.c | 81 +++++++++++++------- servers/slapd/back-sql/schema-map.c | 25 ++++--- servers/slapd/back-sql/search.c | 29 ++++++-- servers/slapd/bconfig.c | 64 ++++++++-------- servers/slapd/config.c | 90 ++++++++++++++++++----- servers/slapd/ldapsync.c | 1 - servers/slapd/limits.c | 76 +++++-------------- servers/slapd/main.c | 4 +- servers/slapd/mods.c | 16 +++- servers/slapd/overlays/ppolicy.c | 58 +++++++++------ servers/slapd/overlays/syncprov.c | 27 ++++++- servers/slapd/overlays/translucent.c | 7 +- servers/slapd/result.c | 6 +- servers/slapd/shell-backends/shellutil.c | 21 ++++-- servers/slapd/slapcommon.c | 15 ++-- servers/slapd/user.c | 23 +++++- servers/slapd/value.c | 2 +- servers/slurpd/args.c | 14 +++- servers/slurpd/config.c | 9 ++- servers/slurpd/re.c | 28 +++++-- servers/slurpd/st.c | 12 ++- tests/progs/slapd-addel.c | 17 ++++- tests/progs/slapd-bind.c | 8 +- tests/progs/slapd-modify.c | 17 ++++- tests/progs/slapd-modrdn.c | 17 ++++- tests/progs/slapd-read.c | 17 ++++- tests/progs/slapd-search.c | 17 ++++- tests/progs/slapd-tester.c | 5 +- 44 files changed, 571 insertions(+), 310 deletions(-) diff --git a/clients/tools/ldapmodify.c b/clients/tools/ldapmodify.c index 79e187b2d4..481ff2f9b8 100644 --- a/clients/tools/ldapmodify.c +++ b/clients/tools/ldapmodify.c @@ -467,7 +467,12 @@ process_ldif_rec( char *rbuf, int count ) replicaport = 0; } else { *p++ = '\0'; - replicaport = atoi( p ); + if ( lutil_atoi( &replicaport, p ) != 0 ) { + fprintf( stderr, _("%s: unable to parse replica port \"%s\" (line %d) entry: \"%s\"\n"), + prog, p, linenum, dn == NULL ? "" : dn ); + rc = LDAP_PARAM_ERROR; + break; + } } if ( ldaphost != NULL && strcasecmp( val.bv_val, ldaphost ) == 0 && @@ -478,7 +483,8 @@ process_ldif_rec( char *rbuf, int count ) } else if ( count == 1 && linenum == 1 && strcasecmp( type, T_VERSION_STR ) == 0 ) { - if( val.bv_len == 0 || atoi(val.bv_val) != 1 ) { + int v; + if( val.bv_len == 0 || lutil_atoi( &v, val.bv_val) != 0 || v != 1 ) { fprintf( stderr, _("%s: invalid version %s, line %d (ignored)\n"), prog, val.bv_val, linenum ); diff --git a/contrib/slapd-modules/smbk5pwd/smbk5pwd.c b/contrib/slapd-modules/smbk5pwd/smbk5pwd.c index f5feab2936..a2c176d78f 100644 --- a/contrib/slapd-modules/smbk5pwd/smbk5pwd.c +++ b/contrib/slapd-modules/smbk5pwd/smbk5pwd.c @@ -377,11 +377,19 @@ static int smbk5pwd_exop_passwd( if ( ret ) break; a = attr_find( e->e_attrs, ad_krb5KeyVersionNumber ); + kvno = 0; if ( a ) { - kvno = atoi(a->a_vals[0].bv_val); + if ( lutil_atoi( &kvno, a->a_vals[0].bv_val ) != 0 ) { + Debug( LDAP_DEBUG_ANY, "%s smbk5pwd EXOP: " + "dn=\"%s\" unable to parse krb5KeyVersionNumber=\"%s\"\n", + op->o_log, e->e_name.bv_val, a->a_vals[0].bv_val ); + } + } else { /* shouldn't happen, this is a required attr */ - kvno = 0; + Debug( LDAP_DEBUG_ANY, "%s smbk5pwd EXOP: " + "dn=\"%s\" missing krb5KeyVersionNumber\n", + op->o_log, e->e_name.bv_val, 0 ); } ret = _kadm5_set_keys(kadm_context, &ent, qpw->rs_new.bv_val); diff --git a/include/lutil.h b/include/lutil.h index c1a15b229f..ebe30963f5 100644 --- a/include/lutil.h +++ b/include/lutil.h @@ -274,16 +274,21 @@ lutil_LogStoppedEvent( char *svc ); #endif LDAP_LUTIL_F (int) -lutil_atoi( int *v, const char *s ); +lutil_atoix( int *v, const char *s, int x ); LDAP_LUTIL_F (int) -lutil_atou( unsigned *v, const char *s ); +lutil_atoux( unsigned *v, const char *s, int x ); LDAP_LUTIL_F (int) -lutil_atol( long *v, const char *s ); +lutil_atolx( long *v, const char *s, int x ); LDAP_LUTIL_F (int) -lutil_atoul( unsigned long *v, const char *s ); +lutil_atoulx( unsigned long *v, const char *s, int x ); + +#define lutil_atoi(v, s) lutil_atoix((v), (s), 10) +#define lutil_atou(v, s) lutil_atoux((v), (s), 10) +#define lutil_atol(v, s) lutil_atolx((v), (s), 10) +#define lutil_atoul(v, s) lutil_atoulx((v), (s), 10) LDAP_LUTIL_F (int) lutil_parse_time( const char *in, unsigned long *tp ); diff --git a/libraries/libldap/cyrus.c b/libraries/libldap/cyrus.c index 548f365952..cc372d70fc 100644 --- a/libraries/libldap/cyrus.c +++ b/libraries/libldap/cyrus.c @@ -1026,11 +1026,11 @@ int ldap_pvt_sasl_secprops( if ( strncasecmp( props[i], sprops[j].key.bv_val, sprops[j].key.bv_len )) continue; if ( sprops[j].ival ) { - int v; + unsigned v; char *next = NULL; if ( !isdigit( props[i][sprops[j].key.bv_len] )) continue; v = strtoul( &props[i][sprops[j].key.bv_len], &next, 10 ); - if ( next == NULL || next[ 0 ] != '\0' ) continue; + if ( next == &props[i][sprops[j].key.bv_len] || next[0] != '\0' ) continue; switch( sprops[j].ival ) { case GOT_MINSSF: min_ssf = v; got_min_ssf++; break; diff --git a/libraries/libldap/url.c b/libraries/libldap/url.c index ecfb3808b1..8fe30b911a 100644 --- a/libraries/libldap/url.c +++ b/libraries/libldap/url.c @@ -883,7 +883,7 @@ ldap_url_parse_ext( LDAP_CONST char *url_in, LDAPURLDesc **ludpp ) } ludp->lud_port = strtol( q, &next, 10 ); - if ( next == NULL || next[0] != '\0' ) { + if ( next == q || next[0] != '\0' ) { LDAP_FREE( url ); ldap_free_urldesc( ludp ); return LDAP_URL_ERR_BADURL; @@ -1338,7 +1338,7 @@ ldap_url_parsehosts( *p++ = 0; ldap_pvt_hex_unescape(p); ludp->lud_port = strtol( p, &next, 10 ); - if ( next == NULL || next[0] != '\0' ) { + if ( next == p || next[0] != '\0' ) { return LDAP_PARAM_ERROR; } } diff --git a/libraries/liblutil/utils.c b/libraries/liblutil/utils.c index 2c84ac4afd..f2a1a2c91d 100644 --- a/libraries/liblutil/utils.c +++ b/libraries/liblutil/utils.c @@ -331,7 +331,7 @@ lutil_memrchr(const void *b, int c, size_t n) } int -lutil_atoi( int *v, const char *s ) +lutil_atoix( int *v, const char *s, int x ) { char *next; long i; @@ -339,7 +339,7 @@ lutil_atoi( int *v, const char *s ) assert( s != NULL ); assert( v != NULL ); - i = strtol( s, &next, 10 ); + i = strtol( s, &next, x ); if ( next == s || next[ 0 ] != '\0' ) { return -1; } @@ -354,7 +354,7 @@ lutil_atoi( int *v, const char *s ) } int -lutil_atou( unsigned *v, const char *s ) +lutil_atoux( unsigned *v, const char *s, int x ) { char *next; unsigned long u; @@ -362,7 +362,7 @@ lutil_atou( unsigned *v, const char *s ) assert( s != NULL ); assert( v != NULL ); - u = strtoul( s, &next, 10 ); + u = strtoul( s, &next, x ); if ( next == s || next[ 0 ] != '\0' ) { return -1; } @@ -377,7 +377,7 @@ lutil_atou( unsigned *v, const char *s ) } int -lutil_atol( long *v, const char *s ) +lutil_atolx( long *v, const char *s, int x ) { char *next; long l; @@ -385,7 +385,7 @@ lutil_atol( long *v, const char *s ) assert( s != NULL ); assert( v != NULL ); - l = strtol( s, &next, 10 ); + l = strtol( s, &next, x ); if ( next == s || next[ 0 ] != '\0' ) { return -1; } @@ -396,7 +396,7 @@ lutil_atol( long *v, const char *s ) } int -lutil_atoul( unsigned long *v, const char *s ) +lutil_atoulx( unsigned long *v, const char *s, int x ) { char *next; unsigned long ul; @@ -404,7 +404,7 @@ lutil_atoul( unsigned long *v, const char *s ) assert( s != NULL ); assert( v != NULL ); - ul = strtoul( s, &next, 10 ); + ul = strtoul( s, &next, x ); if ( next == s || next[ 0 ] != '\0' ) { return -1; } diff --git a/libraries/librewrite/config.c b/libraries/librewrite/config.c index b6c729406e..a3956ec923 100644 --- a/libraries/librewrite/config.c +++ b/libraries/librewrite/config.c @@ -104,19 +104,33 @@ rewrite_parse( return -1; } - info->li_max_passes = atoi( argv[ 1 ] ); + if ( lutil_atoi( &info->li_max_passes, argv[ 1 ] ) != 0 ) { + Debug( LDAP_DEBUG_ANY, + "[%s:%d] unable to parse rewriteMaxPasses=\"%s\"\n", + fname, lineno, argv[ 1 ] ); + return -1; + } + if ( info->li_max_passes <= 0 ) { Debug( LDAP_DEBUG_ANY, - "[%s:%d] negative or null rewriteMaxPasses'\n", + "[%s:%d] negative or null rewriteMaxPasses\n", fname, lineno, 0 ); + return -1; } if ( argc > 2 ) { - info->li_max_passes_per_rule = atoi( argv[ 2 ] ); + if ( lutil_atoi( &info->li_max_passes_per_rule, argv[ 2 ] ) != 0 ) { + Debug( LDAP_DEBUG_ANY, + "[%s:%d] unable to parse rewriteMaxPassesPerRule=\"%s\"\n", + fname, lineno, argv[ 2 ] ); + return -1; + } + if ( info->li_max_passes_per_rule <= 0 ) { Debug( LDAP_DEBUG_ANY, - "[%s:%d] negative or null rewriteMaxPassesPerRule'\n", + "[%s:%d] negative or null rewriteMaxPassesPerRule\n", fname, lineno, 0 ); + return -1; } } else { diff --git a/libraries/librewrite/rewrite-int.h b/libraries/librewrite/rewrite-int.h index fb8dbf6ee4..b983af65a4 100644 --- a/libraries/librewrite/rewrite-int.h +++ b/libraries/librewrite/rewrite-int.h @@ -34,7 +34,7 @@ #include #include #include "../libldap/ldap-int.h" - +#include #include #include diff --git a/libraries/librewrite/rewrite.c b/libraries/librewrite/rewrite.c index b040ee7fd2..95976993f8 100644 --- a/libraries/librewrite/rewrite.c +++ b/libraries/librewrite/rewrite.c @@ -30,6 +30,7 @@ #include #include +#include #include int ldap_debug; @@ -127,7 +128,6 @@ main( int argc, char *argv[] ) FILE *fin = NULL; char *rewriteContext = REWRITE_DEFAULT_CONTEXT; int debug = 0; - char *next; while ( 1 ) { int opt = getopt( argc, argv, "d:f:hr:" ); @@ -138,8 +138,7 @@ main( int argc, char *argv[] ) switch ( opt ) { case 'd': - debug = strtol( optarg, &next, 10 ); - if ( next == NULL || next[0] != '\0' ) { + if ( lutil_atoi( &debug, optarg ) != 0 ) { fprintf( stderr, "illegal log level '%s'\n", optarg ); exit( EXIT_FAILURE ); diff --git a/libraries/librewrite/rule.c b/libraries/librewrite/rule.c index 84ff22b417..dcf7503057 100644 --- a/libraries/librewrite/rule.c +++ b/libraries/librewrite/rule.c @@ -233,7 +233,7 @@ rewrite_rule_compile( } d[ 0 ] = strtol( &p[ 2 ], &next, 0 ); - if ( next == NULL || next == &p[ 2 ] || next[0] != '}' ) { + if ( next == &p[ 2 ] || next[0] != '}' ) { /* XXX Need to free stuff */ return REWRITE_ERR; } @@ -275,7 +275,7 @@ rewrite_rule_compile( } max_passes = strtol( &p[ 2 ], &next, 0 ); - if ( next == NULL || next == &p[ 2 ] || next[0] != '}' ) { + if ( next == &p[ 2 ] || next[0] != '}' ) { /* XXX Need to free stuff */ return REWRITE_ERR; } diff --git a/servers/slapd/acl.c b/servers/slapd/acl.c index 5b84f9e304..423f1c92cd 100644 --- a/servers/slapd/acl.c +++ b/servers/slapd/acl.c @@ -1603,12 +1603,9 @@ slap_acl_mask( port = strrchr( ip.bv_val, ':' ); if ( port ) { - char *next; - ip.bv_len = port - ip.bv_val; ++port; - port_number = strtol( port, &next, 10 ); - if ( next[0] != '\0' ) + if ( lutil_atoi( &port_number, port ) != 0 ) continue; } diff --git a/servers/slapd/aclparse.c b/servers/slapd/aclparse.c index 3c52759f70..3cd2d5c9c9 100644 --- a/servers/slapd/aclparse.c +++ b/servers/slapd/aclparse.c @@ -778,8 +778,7 @@ parse_acl( { char *next; - level = strtol( style_level, &next, 10 ); - if ( next[0] != '\0' ) { + if ( lutil_atoi( &level, style_level ) != 0 ) { Debug( LDAP_DEBUG_ANY, "%s: line %d: unable to parse level " "in \"level{n}\"\n", @@ -1385,7 +1384,7 @@ parse_acl( char *end = NULL; b->a_peername_port = strtol( port, &end, 10 ); - if ( end[0] != '}' ) { + if ( end == port || end[0] != '}' ) { /* illegal port */ Debug( LDAP_DEBUG_ANY, "%s: line %d: " "illegal peername port specification " @@ -1700,8 +1699,7 @@ parse_acl( return acl_usage(); } - b->a_authz.sai_ssf = strtol( right, &next, 10 ); - if ( next == NULL || next[0] != '\0' ) { + if ( lutil_atou( &b->a_authz.sai_ssf, right ) != 0 ) { Debug( LDAP_DEBUG_ANY, "%s: line %d: unable to parse ssf value (%s).\n", fname, lineno, right ); @@ -1739,8 +1737,7 @@ parse_acl( return acl_usage(); } - b->a_authz.sai_transport_ssf = strtol( right, &next, 10 ); - if ( next == NULL || next[0] != '\0' ) { + if ( lutil_atou( &b->a_authz.sai_transport_ssf, right ) != 0 ) { Debug( LDAP_DEBUG_ANY, "%s: line %d: " "unable to parse transport_ssf value (%s).\n", fname, lineno, right ); @@ -1778,8 +1775,7 @@ parse_acl( return acl_usage(); } - b->a_authz.sai_tls_ssf = strtol( right, &next, 10 ); - if ( next == NULL || next[0] != '\0' ) { + if ( lutil_atou( &b->a_authz.sai_tls_ssf, right ) != 0 ) { Debug( LDAP_DEBUG_ANY, "%s: line %d: " "unable to parse tls_ssf value (%s).\n", fname, lineno, right ); @@ -1817,8 +1813,7 @@ parse_acl( return acl_usage(); } - b->a_authz.sai_sasl_ssf = strtol( right, &next, 10 ); - if ( next == NULL || next[0] != '\0' ) { + if ( lutil_atou( &b->a_authz.sai_sasl_ssf, right ) != 0 ) { Debug( LDAP_DEBUG_ANY, "%s: line %d: " "unable to parse sasl_ssf value (%s).\n", fname, lineno, right ); diff --git a/servers/slapd/back-bdb/config.c b/servers/slapd/back-bdb/config.c index fa2bf98de5..637bc027ac 100644 --- a/servers/slapd/back-bdb/config.c +++ b/servers/slapd/back-bdb/config.c @@ -484,10 +484,23 @@ bdb_cf_gen(ConfigArgs *c) } switch( c->type ) { - case BDB_CHKPT: + case BDB_CHKPT: { + long l; bdb->bi_txn_cp = 1; - bdb->bi_txn_cp_kbyte = strtol( c->argv[1], NULL, 0 ); - bdb->bi_txn_cp_min = strtol( c->argv[2], NULL, 0 ); + if ( lutil_atolx( &l, c->argv[1], 0 ) != 0 ) { + fprintf( stderr, "%s: " + "invalid kbyte \"%s\" in \"checkpoint\".\n", + c->log, c->argv[1] ); + return 1; + } + bdb->bi_txn_cp_kbyte = l; + if ( lutil_atolx( &l, c->argv[2], 0 ) != 0 ) { + fprintf( stderr, "%s: " + "invalid minutes \"%s\" in \"checkpoint\".\n", + c->log, c->argv[2] ); + return 1; + } + bdb->bi_txn_cp_min = l; /* If we're in server mode and time-based checkpointing is enabled, * submit a task to perform periodic checkpoints. */ @@ -507,7 +520,7 @@ bdb_cf_gen(ConfigArgs *c) LDAP_XSTRING(bdb_checkpoint), c->be->be_suffix[0].bv_val ); } } - break; + } break; case BDB_CONFIG: { char *ptr = c->line; diff --git a/servers/slapd/back-ldap/config.c b/servers/slapd/back-ldap/config.c index da838e3c6c..b3ef34d0e8 100644 --- a/servers/slapd/back-ldap/config.c +++ b/servers/slapd/back-ldap/config.c @@ -1090,12 +1090,10 @@ done_url:; for ( i = 1; i < c->argc; i++ ) { if ( isdigit( c->argv[ i ][ 0 ] ) ) { - char *next; int j; unsigned u; - u = strtoul( c->argv[ i ], &next, 0 ); - if ( next == c->argv[ i ] || next[ 0 ] != '\0' ) { + if ( lutil_atoux( &u, c->argv[ i ], 0 ) != 0 ) { return 1; } diff --git a/servers/slapd/back-ldbm/config.c b/servers/slapd/back-ldbm/config.c index 2a0a5759ee..5309f2e0c3 100644 --- a/servers/slapd/back-ldbm/config.c +++ b/servers/slapd/back-ldbm/config.c @@ -23,6 +23,7 @@ #include "slap.h" #include "back-ldbm.h" +#include "lutil.h" int ldbm_back_db_config( @@ -62,7 +63,12 @@ ldbm_back_db_config( fname, lineno ); return( 1 ); } - li->li_mode = strtol( argv[1], NULL, 0 ); + if ( lutil_atoix( &li->li_mode, argv[1], 0 ) != 0 ) { + fprintf( stderr, + "%s: line %d: unable to parse mode=\"%s\" in \"mode \" line\n", + fname, lineno, argv[1] ); + return( 1 ); + } /* attribute to index */ } else if ( strcasecmp( argv[0], "index" ) == 0 ) { @@ -91,7 +97,12 @@ ldbm_back_db_config( fname, lineno ); return( 1 ); } - li->li_cache.c_maxsize = atoi( argv[1] ); + if ( lutil_atoi( &li->li_cache.c_maxsize, argv[1] ) != 0 ) { + fprintf( stderr, + "%s: line %d: unable to parse cachesize \"%s\"\n", + fname, lineno, argv[1] ); + return( 1 ); + } /* size of each dbcache in bytes */ } else if ( strcasecmp( argv[0], "dbcachesize" ) == 0 ) { @@ -101,7 +112,12 @@ ldbm_back_db_config( fname, lineno ); return( 1 ); } - li->li_dbcachesize = atoi( argv[1] ); + if ( lutil_atoi( &li->li_dbcachesize, argv[1] ) ) { + fprintf( stderr, + "%s: line %d: unable to parse dbcachesize \"%s\"\n", + fname, lineno, argv[1] ); + return( 1 ); + } /* no locking (not safe) */ } else if ( strcasecmp( argv[0], "dbnolocking" ) == 0 ) { @@ -124,9 +140,7 @@ ldbm_back_db_config( return 1; } - i = atoi( argv[1] ); - - if( i < 0 ) { + if ( lutil_atoi( &i, argv[1] ) != 0 || i < 0 ) { Debug( LDAP_DEBUG_ANY, "%s: line %d: frquency value (%d) invalid \"dbsync [ [wait-interval]]\" line\n", fname, lineno, i ); @@ -136,8 +150,7 @@ ldbm_back_db_config( li->li_dbsyncfreq = i; if ( argc > 2 ) { - i = atoi( argv[2] ); - if ( i < 0 ) { + if ( lutil_atoi( &i, argv[2] ) != 0 || i < 0 ) { Debug( LDAP_DEBUG_ANY, "%s: line %d: frquency value (%d) invalid \"dbsync [ [wait-interval]]\" line\n", fname, lineno, i ); @@ -147,8 +160,7 @@ ldbm_back_db_config( } if ( argc > 3 ) { - i = atoi( argv[3] ); - if ( i <= 0 ) { + if ( lutil_atoi( &i, argv[3] ) != 0 || i <= 0 ) { Debug( LDAP_DEBUG_ANY, "%s: line %d: frquency value (%d) invalid \"dbsync [ [wait-interval]]\" line\n", fname, lineno, i ); diff --git a/servers/slapd/back-meta/back-meta.h b/servers/slapd/back-meta/back-meta.h index 89f21d8b31..8ac932bb99 100644 --- a/servers/slapd/back-meta/back-meta.h +++ b/servers/slapd/back-meta/back-meta.h @@ -236,8 +236,8 @@ typedef struct metadncache_t { Avlnode *tree; #define META_DNCACHE_DISABLED (0) -#define META_DNCACHE_FOREVER (-1) - long int ttl; /* seconds; 0: no cache, -1: no expiry */ +#define META_DNCACHE_FOREVER ((time_t)(-1)) + time_t ttl; /* seconds; 0: no cache, -1: no expiry */ } metadncache_t; typedef struct metacandidates_t { diff --git a/servers/slapd/back-sql/entry-id.c b/servers/slapd/back-sql/entry-id.c index 213fd7096c..9d33b9df72 100644 --- a/servers/slapd/back-sql/entry-id.c +++ b/servers/slapd/back-sql/entry-id.c @@ -27,6 +27,7 @@ #include #include "ac/string.h" +#include "lutil.h" #include "slap.h" #include "proto-sql.h" @@ -250,43 +251,52 @@ backsql_dn2id( if ( id != NULL ) { struct berval dn; + id->eid_next = NULL; + #ifdef BACKSQL_ARBITRARY_KEY ber_str2bv_x( row.cols[ 0 ], 0, 1, &id->eid_id, op->o_tmpmemctx ); ber_str2bv_x( row.cols[ 1 ], 0, 1, &id->eid_keyval, op->o_tmpmemctx ); #else /* ! BACKSQL_ARBITRARY_KEY */ - id->eid_id = strtol( row.cols[ 0 ], NULL, 0 ); - id->eid_keyval = strtol( row.cols[ 1 ], NULL, 0 ); + if ( lutil_atoulx( &id->eid_id, row.cols[ 0 ], 0 ) != 0 ) { + res = LDAP_OTHER; + goto done; + } + if ( lutil_atoulx( &id->eid_keyval, row.cols[ 1 ], 0 ) != 0 ) { + res = LDAP_OTHER; + goto done; + } #endif /* ! BACKSQL_ARBITRARY_KEY */ - id->eid_oc_id = strtol( row.cols[ 2 ], NULL, 0 ); + if ( lutil_atoulx( &id->eid_oc_id, row.cols[ 2 ], 0 ) != 0 ) { + res = LDAP_OTHER; + goto done; + } ber_str2bv( row.cols[ 3 ], 0, 0, &dn ); if ( backsql_api_odbc2dn( op, rs, &dn ) ) { res = LDAP_OTHER; - - } else { - res = dnPrettyNormal( NULL, &dn, - &id->eid_dn, &id->eid_ndn, - op->o_tmpmemctx ); - if ( res != LDAP_SUCCESS ) { - Debug( LDAP_DEBUG_TRACE, - " backsql_dn2id(\"%s\"): " - "dnPrettyNormal failed (%d: %s)\n", - realndn.bv_val, res, - ldap_err2string( res ) ); - - /* cleanup... */ - (void)backsql_free_entryID( op, id, 0 ); - } - - if ( dn.bv_val != row.cols[ 3 ] ) { - free( dn.bv_val ); - } + goto done; + } + + res = dnPrettyNormal( NULL, &dn, + &id->eid_dn, &id->eid_ndn, + op->o_tmpmemctx ); + if ( res != LDAP_SUCCESS ) { + Debug( LDAP_DEBUG_TRACE, + " backsql_dn2id(\"%s\"): " + "dnPrettyNormal failed (%d: %s)\n", + realndn.bv_val, res, + ldap_err2string( res ) ); + + /* cleanup... */ + (void)backsql_free_entryID( op, id, 0 ); } - id->eid_next = NULL; + if ( dn.bv_val != row.cols[ 3 ] ) { + free( dn.bv_val ); + } } } else { @@ -408,11 +418,28 @@ backsql_count_children( char *end; *nchildren = strtol( row.cols[ 0 ], &end, 0 ); - if ( end[ 0 ] != '\0' && end[0] != '.' ) { - /* FIXME: braindead RDBMSes return - * a fractional number from COUNT! - */ + if ( end == row.cols[ 0 ] ) { res = LDAP_OTHER; + + } else { + switch ( end[ 0 ] ) { + case '\0': + break; + + case '.': { + unsigned long ul; + + /* FIXME: braindead RDBMSes return + * a fractional number from COUNT! + */ + if ( lutil_atoul( &ul, end + 1 ) != 0 || ul != 0 ) { + res = LDAP_OTHER; + } + } break; + + default: + res = LDAP_OTHER; + } } } else { diff --git a/servers/slapd/back-sql/schema-map.c b/servers/slapd/back-sql/schema-map.c index 11056f039e..24342fcc66 100644 --- a/servers/slapd/back-sql/schema-map.c +++ b/servers/slapd/back-sql/schema-map.c @@ -27,6 +27,7 @@ #include #include "ac/string.h" +#include "lutil.h" #include "slap.h" #include "proto-sql.h" @@ -316,7 +317,6 @@ backsql_oc_get_attr_mapping( void *v_oc, void *v_bas ) backsql_BindRowAsStrings( bas->bas_sth, &at_row ); for ( ; rc = SQLFetch( bas->bas_sth ), BACKSQL_SUCCESS( rc ); ) { const char *text = NULL; - char *next = NULL; struct berval bv; struct berbuf bb = BB_NULL; @@ -377,14 +377,10 @@ backsql_oc_get_attr_mapping( void *v_oc, void *v_bas ) if ( at_row.value_len[ 5 ] > 0 ) { at_map->bam_delete_proc = ch_strdup( at_row.cols[ 5 ] ); } - at_map->bam_param_order = strtol( at_row.cols[ 6 ], - &next, 0 ); - if ( next == at_row.cols[ 6 ] || next[0] != '\0' ) { + if ( lutil_atoix( &at_map->bam_param_order, at_row.cols[ 6 ], 0 ) != 0 ) { /* error */ } - at_map->bam_expect_return = strtol( at_row.cols[ 7 ], - &next, 0 ); - if ( next == at_row.cols[ 7 ] || next[0] != '\0' ) { + if ( lutil_atoix( &at_map->bam_expect_return, at_row.cols[ 7 ], 0 ) != 0 ) { /* error */ } backsql_make_attr_query( bas->bas_bi, oc_map, at_map ); @@ -485,7 +481,12 @@ backsql_load_schema_map( backsql_info *bi, SQLHDBC dbh ) oc_map = (backsql_oc_map_rec *)ch_calloc( 1, sizeof( backsql_oc_map_rec ) ); - oc_map->bom_id = strtol( oc_row.cols[ 0 ], NULL, 0 ); + if ( lutil_atoulx( &oc_map->bom_id, oc_row.cols[ 0 ], 0 ) != 0 ) { + Debug( LDAP_DEBUG_TRACE, "backsql_load_schema_map(): " + "unable to parse id=\"%s\"\n", + oc_row.cols[ 0 ], 0, 0 ); + return LDAP_OTHER; + } oc_map->bom_oc = oc_find( oc_row.cols[ 1 ] ); if ( oc_map->bom_oc == NULL ) { @@ -508,8 +509,12 @@ backsql_load_schema_map( backsql_info *bi, SQLHDBC dbh ) } oc_map->bom_delete_proc = ( oc_row.value_len[ colnum ] < 0 ) ? NULL : ch_strdup( oc_row.cols[ colnum ] ); - oc_map->bom_expect_return = strtol( oc_row.cols[ colnum + 1 ], - NULL, 0 ); + if ( lutil_atoix( &oc_map->bom_expect_return, oc_row.cols[ colnum + 1 ], 0 ) != 0 ) { + Debug( LDAP_DEBUG_TRACE, "backsql_load_schema_map(): " + "unable to parse expect_return=\"%s\" for objectClass \"%s\"\n", + oc_row.cols[ colnum + 1 ], oc_row.cols[ 1 ], 0 ); + return LDAP_OTHER; + } colnum += 2; if ( ( oc_row.ncols > colnum ) && diff --git a/servers/slapd/back-sql/search.c b/servers/slapd/back-sql/search.c index 2fe00acb2c..6045fa9bfe 100644 --- a/servers/slapd/back-sql/search.c +++ b/servers/slapd/back-sql/search.c @@ -28,6 +28,7 @@ #include "ac/string.h" #include "ac/ctype.h" +#include "lutil.h" #include "slap.h" #include "proto-sql.h" @@ -1828,21 +1829,23 @@ backsql_oc_get_candidates( void *v_oc, void *v_bsi ) } if ( bi->sql_baseObject && dn_match( &ndn, &bi->sql_baseObject->e_nname ) ) { - op->o_tmpfree( pdn.bv_val, op->o_tmpmemctx ); - op->o_tmpfree( ndn.bv_val, op->o_tmpmemctx ); - continue; + goto cleanup; } - c_id = (backsql_entryID *)ch_calloc( 1, - sizeof( backsql_entryID ) ); + c_id = (backsql_entryID *)op->o_tmpcalloc( 1, + sizeof( backsql_entryID ), op->o_tmpmemctx ); #ifdef BACKSQL_ARBITRARY_KEY ber_str2bv_x( row.cols[ 0 ], 0, 1, &c_id->eid_id, op->o_tmpmemctx ); ber_str2bv_x( row.cols[ 1 ], 0, 1, &c_id->eid_keyval, op->o_tmpmemctx ); #else /* ! BACKSQL_ARBITRARY_KEY */ - c_id->eid_id = strtol( row.cols[ 0 ], NULL, 0 ); - c_id->eid_keyval = strtol( row.cols[ 1 ], NULL, 0 ); + if ( lutil_atoulx( &c_id->eid_id, row.cols[ 0 ], 0 ) != 0 ) { + goto cleanup; + } + if ( lutil_atoulx( &c_id->eid_keyval, row.cols[ 1 ], 0 ) != 0 ) { + goto cleanup; + } #endif /* ! BACKSQL_ARBITRARY_KEY */ c_id->eid_oc_id = bsi->bsi_oc->bom_id; @@ -1870,6 +1873,18 @@ backsql_oc_get_candidates( void *v_oc, void *v_bsi ) if ( bsi->bsi_n_candidates == -1 ) { break; } + continue; + +cleanup:; + if ( !BER_BVISNULL( &pdn ) ) { + op->o_tmpfree( pdn.bv_val, op->o_tmpmemctx ); + } + if ( !BER_BVISNULL( &ndn ) ) { + op->o_tmpfree( ndn.bv_val, op->o_tmpmemctx ); + } + if ( c_id != NULL ) { + ch_free( c_id ); + } } backsql_FreeRow_x( &row, bsi->bsi_op->o_tmpmemctx ); SQLFreeStmt( sth, SQL_DROP ); diff --git a/servers/slapd/bconfig.c b/servers/slapd/bconfig.c index d02a5816ce..267823b73c 100644 --- a/servers/slapd/bconfig.c +++ b/servers/slapd/bconfig.c @@ -1525,20 +1525,11 @@ config_sizelimit(ConfigArgs *c) { if(!strcasecmp(c->argv[i], "unlimited")) { lim->lms_s_soft = -1; } else { - lim->lms_s_soft = strtol(c->argv[i], &next, 0); - if(next == c->argv[i]) { + if ( lutil_atoix( &lim->lms_s_soft, c->argv[i], 0 ) != 0 ) { snprintf( c->msg, sizeof( c->msg ), "<%s> unable to parse limit", c->argv[0]); Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n", c->log, c->msg, c->argv[i]); return(1); - } else if(next[0] != '\0') { - Debug( SLAPD_DEBUG_CONFIG_ERROR, "%s: " - "trailing chars \"%s\" in \"sizelimit \" line" - SLAPD_CONF_UNKNOWN_IGNORED ".\n", - c->log, next, 0); -#ifdef SLAPD_CONF_UNKNOWN_BAILOUT - return 1; -#endif /* SLAPD_CONF_UNKNOWN_BAILOUT */ } } lim->lms_s_hard = 0; @@ -1582,20 +1573,11 @@ config_timelimit(ConfigArgs *c) { if(!strcasecmp(c->argv[i], "unlimited")) { lim->lms_t_soft = -1; } else { - lim->lms_t_soft = strtol(c->argv[i], &next, 0); - if(next == c->argv[i]) { + if ( lutil_atoix( &lim->lms_t_soft, c->argv[i], 0 ) != 0 ) { snprintf( c->msg, sizeof( c->msg ), "<%s> unable to parse limit", c->argv[0]); Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n", c->log, c->msg, c->argv[i]); return(1); - } else if(next[0] != '\0') { - Debug( SLAPD_DEBUG_CONFIG_ERROR, "%s: " - "trailing chars \"%s\" in \"timelimit \" line" - SLAPD_CONF_UNKNOWN_IGNORED ".\n", - c->log, next, 0); -#ifdef SLAPD_CONF_UNKNOWN_BAILOUT - return 1; -#endif /* SLAPD_CONF_UNKNOWN_BAILOUT */ } } lim->lms_t_hard = 0; @@ -2186,8 +2168,7 @@ config_loglevel(ConfigArgs *c) { int level; if ( isdigit( c->argv[i][0] ) || c->argv[i][0] == '-' ) { - level = strtol( c->argv[i], &next, 10 ); - if ( next == NULL || next[0] != '\0' ) { + if( lutil_atoi( &level, c->argv[i] ) != 0 ) { snprintf( c->msg, sizeof( c->msg ), "<%s> unable to parse level", c->argv[0] ); Debug( LDAP_DEBUG_ANY, "%s: %s \"%s\"\n", c->log, c->msg, c->argv[i]); @@ -2308,8 +2289,7 @@ config_security(ConfigArgs *c) { return(1); } - *tgt = strtol(src, &next, 10); - if(next == NULL || next[0] != '\0' ) { + if ( lutil_atou( tgt, src ) != 0 ) { snprintf( c->msg, sizeof( c->msg ), "<%s> unable to parse factor", c->argv[0] ); Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n", c->log, c->msg, c->argv[i]); @@ -2718,8 +2698,13 @@ config_tls_config(ConfigArgs *c) { return ldap_pvt_tls_set_option( NULL, flag, &i ); } ch_free( c->value_string ); - if(isdigit((unsigned char)c->argv[1][0])) { - i = atoi(c->argv[1]); + if ( isdigit( (unsigned char)c->argv[1][0] ) ) { + if ( lutil_atoi( &i, c->argv[1] ) != 0 ) { + Debug(LDAP_DEBUG_ANY, "%s: " + "unable to parse %s \"%s\"\n", + c->log, c->argv[0], c->argv[1] ); + return 1; + } return(ldap_pvt_tls_set_option(NULL, flag, &i)); } else { return(ldap_int_tls_config(NULL, flag, c->argv[1])); @@ -3202,7 +3187,9 @@ check_name_index( CfEntryInfo *parent, ConfigType ce_type, Entry *e, if ( ptr2-ptr1 == 1) return LDAP_NAMING_VIOLATION; gotindex = 1; - index = atoi(ptr1+1); + if ( lutil_atoi( &index, ptr1 + 1 ) != 0 ) { + return LDAP_NAMING_VIOLATION; + } if ( index < 0 ) { /* Special case, we allow -1 for the frontendDB */ if ( index != -1 || ce_type != Cft_Database || @@ -3750,9 +3737,13 @@ config_modify_internal( CfEntryInfo *ce, Operation *op, SlapReply *rs, } for ( i=0; !BER_BVISNULL( &ml->sml_values[i] ); i++ ) { if ( ml->sml_values[i].bv_val[0] == '{' && - navals >= 0 ) { - int j = strtol( ml->sml_values[i].bv_val+1, NULL, 0 ); - if ( j < navals ) { + navals >= 0 ) + { + char *next, *val = ml->sml_values[i].bv_val + 1; + int j; + + j = strtol( val, &next, 0 ); + if ( next == val || next[ 0 ] != '}' || j < navals ) { rc = LDAP_OTHER; snprintf(ca->msg, sizeof(ca->msg), "cannot insert %s", ml->sml_desc->ad_cname.bv_val ); @@ -3870,10 +3861,17 @@ config_modify_internal( CfEntryInfo *ce, Operation *op, SlapReply *rs, ca->line = ml->sml_values[i].bv_val; ca->valx = -1; if ( ml->sml_desc->ad_type->sat_flags & SLAP_AT_ORDERED && - ca->line[0] == '{' ) { - ptr = strchr( ca->line, '}' ); + ca->line[0] == '{' ) + { + ptr = strchr( ca->line + 1, '}' ); if ( ptr ) { - ca->valx = strtol( ca->line+1, NULL, 0 ); + char *next; + + ca->valx = strtol( ca->line + 1, &next, 0 ); + if ( next == ca->line + 1 || next[ 0 ] != '}' ) { + rc = LDAP_OTHER; + goto out; + } ca->line = ptr+1; } } diff --git a/servers/slapd/config.c b/servers/slapd/config.c index 0c9fc58798..5e57b2703c 100644 --- a/servers/slapd/config.c +++ b/servers/slapd/config.c @@ -191,20 +191,49 @@ int config_check_vals(ConfigTable *Conf, ConfigArgs *c, int check_only ) { int j; iarg = 0; larg = 0; barg = 0; switch(arg_type & ARGS_NUMERIC) { - case ARG_INT: iarg = strtol(c->argv[1], NULL, 0); break; - case ARG_LONG: larg = strtol(c->argv[1], NULL, 0); break; - case ARG_BER_LEN_T: barg = (ber_len_t)atol(c->argv[1]); break; + case ARG_INT: + if ( lutil_atoi( &iarg, c->argv[1] ) != 0 ) { + snprintf( c->msg, sizeof( c->msg ), + "<%s> unable to parse \"%s\" as int", + c->argv[0], c->argv[1] ); + Debug(LDAP_DEBUG_CONFIG, "%s: %s\n", + c->log, c->msg, 0); + return(ARG_BAD_CONF); + } + break; + case ARG_LONG: + if ( lutil_atol( &larg, c->argv[1] ) != 0 ) { + snprintf( c->msg, sizeof( c->msg ), + "<%s> unable to parse \"%s\" as long", + c->argv[0], c->argv[1] ); + Debug(LDAP_DEBUG_CONFIG, "%s: %s\n", + c->log, c->msg, 0); + return(ARG_BAD_CONF); + } + break; + case ARG_BER_LEN_T: { + unsigned long l; + if ( lutil_atoul( &l, c->argv[1] ) != 0 ) { + snprintf( c->msg, sizeof( c->msg ), + "<%s> unable to parse \"%s\" as ber_len_t", + c->argv[0], c->argv[1] ); + Debug(LDAP_DEBUG_CONFIG, "%s: %s\n", + c->log, c->msg, 0); + return(ARG_BAD_CONF); + } + barg = (ber_len_t)l; + } break; case ARG_ON_OFF: - if(c->argc == 1) { + if (c->argc == 1) { iarg = 1; - } else if(!strcasecmp(c->argv[1], "on") || + } else if ( !strcasecmp(c->argv[1], "on") || !strcasecmp(c->argv[1], "true") || - !strcasecmp(c->argv[1], "yes")) + !strcasecmp(c->argv[1], "yes") ) { iarg = 1; - } else if(!strcasecmp(c->argv[1], "off") || + } else if ( !strcasecmp(c->argv[1], "off") || !strcasecmp(c->argv[1], "false") || - !strcasecmp(c->argv[1], "no")) + !strcasecmp(c->argv[1], "no") ) { iarg = 0; } else { @@ -1018,9 +1047,11 @@ slap_cf_aux_table_parse( const char *word, void *dst, slap_cf_aux_table *tab0, L for (tab = tab0; !BER_BVISNULL(&tab->key); tab++ ) { if ( !strncasecmp( word, tab->key.bv_val, tab->key.bv_len )) { - char **cptr, *next; + char **cptr; int *iptr, j; unsigned *uptr; + long *lptr; + unsigned long *ulptr; struct berval *bptr; const char *val = word + tab->key.bv_len; @@ -1051,19 +1082,25 @@ slap_cf_aux_table_parse( const char *word, void *dst, slap_cf_aux_table *tab0, L case 'i': iptr = (int *)((char *)dst + tab->off); - *iptr = strtol( val, &next, 0 ); - if ( next == val || next[ 0 ] != '\0' ) { - rc = 1; - } + rc = lutil_atoix( iptr, val, 0 ); break; case 'u': uptr = (unsigned *)((char *)dst + tab->off); - *uptr = strtoul( val, &next, 0 ); - if ( next == val || next[ 0 ] != '\0' ) { - rc = 1; - } + rc = lutil_atoux( uptr, val, 0 ); + break; + + case 'I': + lptr = (long *)((char *)dst + tab->off); + + rc = lutil_atolx( lptr, val, 0 ); + break; + + case 'U': + ulptr = (unsigned long *)((char *)dst + tab->off); + + rc = lutil_atoulx( ulptr, val, 0 ); break; } @@ -1091,6 +1128,8 @@ slap_cf_aux_table_unparse( void *src, struct berval *bv, slap_cf_aux_table *tab0 char **cptr; int *iptr, i; unsigned *uptr; + long *lptr; + unsigned long *ulptr; struct berval *bptr; cptr = (char **)((char *)src + tab->off); @@ -1136,6 +1175,23 @@ slap_cf_aux_table_unparse( void *src, struct berval *bv, slap_cf_aux_table *tab0 ptr = lutil_strcopy( ptr, tab->key.bv_val ); ptr += snprintf( ptr, sizeof( buf ) - ( ptr - buf ), "%u", *uptr ); break; + + case 'I': + lptr = (long *)((char *)src + tab->off); + *ptr++ = ' '; + ptr = lutil_strcopy( ptr, tab->key.bv_val ); + ptr += snprintf( ptr, sizeof( buf ) - ( ptr - buf ), "%ld", *lptr ); + break; + + case 'U': + ulptr = (unsigned long *)((char *)src + tab->off); + *ptr++ = ' '; + ptr = lutil_strcopy( ptr, tab->key.bv_val ); + ptr += snprintf( ptr, sizeof( buf ) - ( ptr - buf ), "%lu", *ulptr ); + break; + + default: + assert( 0 ); } } tmp.bv_val = buf; diff --git a/servers/slapd/ldapsync.c b/servers/slapd/ldapsync.c index e203781191..f4e80ac873 100644 --- a/servers/slapd/ldapsync.c +++ b/servers/slapd/ldapsync.c @@ -112,7 +112,6 @@ slap_parse_sync_cookie( || rid_ptr > &cookie->octet_str.bv_val[ cookie->octet_str.bv_len - STRLENOF( "rid=" ) ] ) { return -1; - } cookie->rid = strtoul( &rid_ptr[ STRLENOF( "rid=" ) ], &next, 10 ); diff --git a/servers/slapd/limits.c b/servers/slapd/limits.c index 691a116366..053efd90bd 100644 --- a/servers/slapd/limits.c +++ b/servers/slapd/limits.c @@ -650,14 +650,9 @@ limits_parse_one( limit->lms_t_soft = -1; } else { - char *next = NULL; - int soft = strtol( arg, &next, 10 ); + int soft; - if ( next == arg || next[ 0 ] != '\0' ) { - return( 1 ); - } - - if ( soft < -1 ) { + if ( lutil_atoi( &soft, arg ) != 0 || soft < -1 ) { return( 1 ); } @@ -677,14 +672,9 @@ limits_parse_one( limit->lms_t_hard = -1; } else { - char *next = NULL; - int hard = strtol( arg, &next, 10 ); - - if ( next == arg || next[ 0 ] != '\0' ) { - return( 1 ); - } + int hard; - if ( hard < -1 ) { + if ( lutil_atoi( &hard, arg ) != 0 || hard < -1 ) { return( 1 ); } @@ -709,10 +699,9 @@ limits_parse_one( limit->lms_t_soft = -1; } else { - char *next = NULL; - - limit->lms_t_soft = strtol( arg, &next, 10 ); - if ( next == arg || limit->lms_t_soft < -1 ) { + if ( lutil_atoi( &limit->lms_t_soft, arg ) != 0 + || limit->lms_t_soft < -1 ) + { return( 1 ); } } @@ -733,14 +722,9 @@ limits_parse_one( limit->lms_s_soft = -1; } else { - char *next = NULL; - int soft = strtol( arg, &next, 10 ); - - if ( next == arg || next[ 0 ] != '\0' ) { - return( 1 ); - } + int soft; - if ( soft < -1 ) { + if ( lutil_atoi( &soft, arg ) != 0 || soft < -1 ) { return( 1 ); } @@ -760,14 +744,9 @@ limits_parse_one( limit->lms_s_hard = -1; } else { - char *next = NULL; - int hard = strtol( arg, &next, 10 ); + int hard; - if ( next == arg || next[ 0 ] != '\0' ) { - return( 1 ); - } - - if ( hard < -1 ) { + if ( lutil_atoi( &hard, arg ) != 0 || hard < -1 ) { return( 1 ); } @@ -791,14 +770,9 @@ limits_parse_one( limit->lms_s_unchecked = 0; } else { - char *next = NULL; - int unchecked = strtol( arg, &next, 10 ); - - if ( next == arg || next[ 0 ] != '\0' ) { - return( 1 ); - } + int unchecked; - if ( unchecked < -1 ) { + if ( lutil_atoi( &unchecked, arg ) != 0 || unchecked < -1 ) { return( 1 ); } @@ -818,14 +792,9 @@ limits_parse_one( limit->lms_s_pr = -1; } else { - char *next = NULL; - int pr = strtol( arg, &next, 10 ); + int pr; - if ( next == arg || next[ 0 ] != '\0' ) { - return( 1 ); - } - - if ( pr < -1 ) { + if ( lutil_atoi( &pr, arg ) != 0 || pr < -1 ) { return( 1 ); } @@ -849,15 +818,9 @@ limits_parse_one( limit->lms_s_pr_total = 0; } else { - char *next = NULL; int total; - total = strtol( arg, &next, 10 ); - if ( next == arg || next[ 0 ] != '\0' ) { - return( 1 ); - } - - if ( total < -1 ) { + if ( lutil_atoi( &total, arg ) != 0 || total < -1 ) { return( 1 ); } @@ -882,10 +845,9 @@ limits_parse_one( limit->lms_s_soft = -1; } else { - char *next = NULL; - - limit->lms_s_soft = strtol( arg, &next, 10 ); - if ( next == arg || limit->lms_s_soft < -1 ) { + if ( lutil_atoi( &limit->lms_s_soft, arg ) != 0 + || limit->lms_s_soft < -1 ) + { return( 1 ); } } diff --git a/servers/slapd/main.c b/servers/slapd/main.c index fa88c285ee..c47f477893 100644 --- a/servers/slapd/main.c +++ b/servers/slapd/main.c @@ -406,10 +406,8 @@ int main( int argc, char **argv ) slap_debug |= level; } else { int level; - char *next = NULL; - level = strtol( optarg, &next, 0 ); - if ( next == NULL || next[ 0 ] != '\0' ) { + if ( lutil_atoix( &level, optarg, 0 ) != 0 ) { fprintf( stderr, "unrecognized log level " "\"%s\"\n", optarg ); diff --git a/servers/slapd/mods.c b/servers/slapd/mods.c index 40945fd21f..f6ef580d2d 100644 --- a/servers/slapd/mods.c +++ b/servers/slapd/mods.c @@ -28,6 +28,7 @@ #include #include "slap.h" +#include "lutil.h" int modify_add_values( @@ -386,7 +387,12 @@ modify_increment_values( if ( !strcmp( a->a_desc->ad_type->sat_syntax_oid, SLAPD_INTEGER_SYNTAX )) { int i; char str[sizeof(long)*3 + 2]; /* overly long */ - long incr = atol( mod->sm_values[0].bv_val ); + long incr; + + if ( lutil_atol( &incr, mod->sm_values[0].bv_val ) != 0 ) { + *text = "modify/increment: invalid syntax of increment"; + return LDAP_INVALID_SYNTAX; + } /* treat zero and errors as a no-op */ if( incr == 0 ) { @@ -395,13 +401,17 @@ modify_increment_values( for( i = 0; !BER_BVISNULL( &a->a_nvals[i] ); i++ ) { char *tmp; - long value = atol( a->a_nvals[i].bv_val ); + long value; + if ( lutil_atol( &value, a->a_nvals[i].bv_val ) != 0 ) { + *text = "modify/increment: invalid syntax of original value"; + return LDAP_INVALID_SYNTAX; + } size_t strln = snprintf( str, sizeof(str), "%ld", value+incr ); tmp = SLAP_REALLOC( a->a_nvals[i].bv_val, strln+1 ); if( tmp == NULL ) { *text = "modify/increment: reallocation error"; - return LDAP_OTHER;; + return LDAP_OTHER; } a->a_nvals[i].bv_val = tmp; a->a_nvals[i].bv_len = strln; diff --git a/servers/slapd/overlays/ppolicy.c b/servers/slapd/overlays/ppolicy.c index 2a5568add9..a13c406746 100644 --- a/servers/slapd/overlays/ppolicy.c +++ b/servers/slapd/overlays/ppolicy.c @@ -357,30 +357,40 @@ ppolicy_get( Operation *op, Entry *e, PassPolicy *pp ) pp->ad = slap_schema.si_ad_userPassword; #endif - if ((a = attr_find( pe->e_attrs, ad_pwdMinAge ))) - pp->pwdMinAge = atoi(a->a_vals[0].bv_val ); - if ((a = attr_find( pe->e_attrs, ad_pwdMaxAge ))) - pp->pwdMaxAge = atoi(a->a_vals[0].bv_val ); - if ((a = attr_find( pe->e_attrs, ad_pwdInHistory ))) - pp->pwdInHistory = atoi(a->a_vals[0].bv_val ); - if ((a = attr_find( pe->e_attrs, ad_pwdCheckQuality ))) - pp->pwdCheckQuality = atoi(a->a_vals[0].bv_val ); - if ((a = attr_find( pe->e_attrs, ad_pwdMinLength ))) - pp->pwdMinLength = atoi(a->a_vals[0].bv_val ); - if ((a = attr_find( pe->e_attrs, ad_pwdMaxFailure ))) - pp->pwdMaxFailure = atoi(a->a_vals[0].bv_val ); - if ((a = attr_find( pe->e_attrs, ad_pwdGraceAuthNLimit ))) - pp->pwdGraceAuthNLimit = atoi(a->a_vals[0].bv_val ); - if ((a = attr_find( pe->e_attrs, ad_pwdExpireWarning ))) - pp->pwdExpireWarning = atoi(a->a_vals[0].bv_val ); - if ((a = attr_find( pe->e_attrs, ad_pwdFailureCountInterval ))) - pp->pwdFailureCountInterval = atoi(a->a_vals[0].bv_val ); - if ((a = attr_find( pe->e_attrs, ad_pwdLockoutDuration ))) - pp->pwdLockoutDuration = atoi(a->a_vals[0].bv_val ); - - if ((a = attr_find( pe->e_attrs, ad_pwdCheckModule ))) { - strncpy(pp->pwdCheckModule, a->a_vals[0].bv_val, - sizeof(pp->pwdCheckModule)); + if ( ( a = attr_find( pe->e_attrs, ad_pwdMinAge ) ) + && lutil_atoi( &pp->pwdMinAge, a->a_vals[0].bv_val ) != 0 ) + goto defaultpol; + if ( ( a = attr_find( pe->e_attrs, ad_pwdMaxAge ) ) + && lutil_atoi( &pp->pwdMaxAge, a->a_vals[0].bv_val ) != 0 ) + goto defaultpol; + if ( ( a = attr_find( pe->e_attrs, ad_pwdInHistory ) ) + && lutil_atoi( &pp->pwdInHistory, a->a_vals[0].bv_val ) != 0 ) + goto defaultpol; + if ( ( a = attr_find( pe->e_attrs, ad_pwdCheckQuality ) ) + && lutil_atoi( &pp->pwdCheckQuality, a->a_vals[0].bv_val ) != 0 ) + goto defaultpol; + if ( ( a = attr_find( pe->e_attrs, ad_pwdMinLength ) ) + && lutil_atoi( &pp->pwdMinLength, a->a_vals[0].bv_val ) != 0 ) + goto defaultpol; + if ( ( a = attr_find( pe->e_attrs, ad_pwdMaxFailure ) ) + && lutil_atoi( &pp->pwdMaxFailure, a->a_vals[0].bv_val ) != 0 ) + goto defaultpol; + if ( ( a = attr_find( pe->e_attrs, ad_pwdGraceAuthNLimit ) ) + && lutil_atoi( &pp->pwdGraceAuthNLimit, a->a_vals[0].bv_val ) != 0 ) + goto defaultpol; + if ( ( a = attr_find( pe->e_attrs, ad_pwdExpireWarning ) ) + && lutil_atoi( &pp->pwdExpireWarning, a->a_vals[0].bv_val ) != 0 ) + goto defaultpol; + if ( ( a = attr_find( pe->e_attrs, ad_pwdFailureCountInterval ) ) + && lutil_atoi( &pp->pwdFailureCountInterval, a->a_vals[0].bv_val ) != 0 ) + goto defaultpol; + if ( ( a = attr_find( pe->e_attrs, ad_pwdLockoutDuration ) ) + && lutil_atoi( &pp->pwdLockoutDuration, a->a_vals[0].bv_val ) != 0 ) + goto defaultpol; + + if ( ( a = attr_find( pe->e_attrs, ad_pwdCheckModule ) ) ) { + strncpy( pp->pwdCheckModule, a->a_vals[0].bv_val, + sizeof(pp->pwdCheckModule) ); pp->pwdCheckModule[sizeof(pp->pwdCheckModule)-1] = '\0'; } diff --git a/servers/slapd/overlays/syncprov.c b/servers/slapd/overlays/syncprov.c index 70dc6ff9e8..eafb6bf12b 100644 --- a/servers/slapd/overlays/syncprov.c +++ b/servers/slapd/overlays/syncprov.c @@ -2195,8 +2195,31 @@ sp_cf_gen(ConfigArgs *c) } switch ( c->type ) { case SP_CHKPT: - si->si_chkops = atoi( c->argv[1] ); - si->si_chktime = atoi( c->argv[2] ) * 60; + if ( lutil_atoi( &si->si_chkops, c->argv[1] ) != 0 ) { + sprintf( c->msg, "%s unable to parse checkpoint ops # \"%s\"", + c->argv[0], c->argv[1] ); + Debug( LDAP_DEBUG_CONFIG, "%s: %s\n", c->log, c->msg, 0 ); + return ARG_BAD_CONF; + } + if ( si->si_chkops <= 0 ) { + sprintf( c->msg, "%s invalid checkpoint ops # \"%d\"", + c->argv[0], si->si_chkops ); + Debug( LDAP_DEBUG_CONFIG, "%s: %s\n", c->log, c->msg, 0 ); + return ARG_BAD_CONF; + } + if ( lutil_atoi( &si->si_chktime, c->argv[2] ) != 0 ) { + sprintf( c->msg, "%s unable to parse checkpoint time \"%s\"", + c->argv[0], c->argv[1] ); + Debug( LDAP_DEBUG_CONFIG, "%s: %s\n", c->log, c->msg, 0 ); + return ARG_BAD_CONF; + } + if ( si->si_chktime <= 0 ) { + sprintf( c->msg, "%s invalid checkpoint time \"%d\"", + c->argv[0], si->si_chkops ); + Debug( LDAP_DEBUG_CONFIG, "%s: %s\n", c->log, c->msg, 0 ); + return ARG_BAD_CONF; + } + si->si_chktime *= 60; break; case SP_SESSL: { sessionlog *sl; diff --git a/servers/slapd/overlays/translucent.c b/servers/slapd/overlays/translucent.c index 13e37ff9be..1686df0215 100644 --- a/servers/slapd/overlays/translucent.c +++ b/servers/slapd/overlays/translucent.c @@ -29,6 +29,7 @@ #include #include "slap.h" +#include "lutil.h" /* config block */ @@ -620,7 +621,11 @@ static int translucent_config( ov->config->debug = 0xFFFF; rc = 0; } else if(argc == 2) { - ov->config->debug = atoi(argv[1]); + if ( lutil_atoi( &ov->config->debug, argv[1]) != 0 ) { + fprintf(stderr, "%s: line %d: unable to parse debug \"%s\"\n", + fname, lineno, argv[1]); + return 1; + } rc = 0; } else { fprintf(stderr, "%s: line %d: too many arguments (%d) to debug\n", diff --git a/servers/slapd/result.c b/servers/slapd/result.c index 52a67ea2f8..cb9e25ad70 100644 --- a/servers/slapd/result.c +++ b/servers/slapd/result.c @@ -36,6 +36,7 @@ #include #include "slap.h" +#include "lutil.h" const struct berval slap_dummy_bv = BER_BVNULL; @@ -1397,8 +1398,8 @@ str2result( } if ( strncasecmp( s, "code", STRLENOF( "code" ) ) == 0 ) { - if ( c != NULL ) { - *code = atoi( c ); + if ( c != NULL && lutil_atoi( code, c ) != 0 ) { + goto bailout; } } else if ( strncasecmp( s, "matched", STRLENOF( "matched" ) ) == 0 ) { if ( c != NULL ) { @@ -1409,6 +1410,7 @@ str2result( *info = c; } } else { +bailout:; Debug( LDAP_DEBUG_ANY, "str2result (%s) unknown\n", s, 0, 0 ); diff --git a/servers/slapd/shell-backends/shellutil.c b/servers/slapd/shell-backends/shellutil.c index 2731b52b86..b519cf4d5c 100644 --- a/servers/slapd/shell-backends/shellutil.c +++ b/servers/slapd/shell-backends/shellutil.c @@ -185,21 +185,32 @@ parse_input( FILE *ifp, FILE *ofp, struct ldop *op ) op->ldop_dn = estrdup( args ); break; case IP_TYPE_SCOPE: - if (( op->ldop_srch.ldsp_scope = atoi( args )) != LDAP_SCOPE_BASE && + if ( lutil_atoi( &op->ldop_srch.ldsp_scope, args ) != 0 || + ( op->ldop_srch.ldsp_scope != LDAP_SCOPE_BASE && op->ldop_srch.ldsp_scope != LDAP_SCOPE_ONELEVEL && - op->ldop_srch.ldsp_scope != LDAP_SCOPE_SUBTREE ) { + op->ldop_srch.ldsp_scope != LDAP_SCOPE_SUBTREE ) ) + { write_result( ofp, LDAP_OTHER, NULL, "Bad scope" ); return( -1 ); } break; case IP_TYPE_ALIASDEREF: - op->ldop_srch.ldsp_aliasderef = atoi( args ); + if ( lutil_atoi( &op->ldop_srch.ldsp_aliasderef, args ) != 0 ) { + write_result( ofp, LDAP_OTHER, NULL, "Bad alias deref" ); + return( -1 ); + } break; case IP_TYPE_SIZELIMIT: - op->ldop_srch.ldsp_sizelimit = atoi( args ); + if ( lutil_atoi( &op->ldop_srch.ldsp_sizelimit, args ) != 0 ) { + write_result( ofp, LDAP_OTHER, NULL, "Bad size limit" ); + return( -1 ); + } break; case IP_TYPE_TIMELIMIT: - op->ldop_srch.ldsp_timelimit = atoi( args ); + if ( lutil_atoi( &op->ldop_srch.ldsp_timelimit, args ) != 0 ) { + write_result( ofp, LDAP_OTHER, NULL, "Bad time limit" ); + return( -1 ); + } break; case IP_TYPE_FILTER: op->ldop_srch.ldsp_filter = estrdup( args ); diff --git a/servers/slapd/slapcommon.c b/servers/slapd/slapcommon.c index 5026e41de4..ec36850cc6 100644 --- a/servers/slapd/slapcommon.c +++ b/servers/slapd/slapcommon.c @@ -276,16 +276,11 @@ slap_tool_init( exit( EXIT_FAILURE ); } - } else { - char *next = NULL; - - level = strtol( optarg, &next, 0 ); - if ( next == NULL || next[ 0 ] != '\0' ) { - fprintf( stderr, - "unrecognized log level " - "\"%s\"\n", optarg ); - exit( EXIT_FAILURE ); - } + } else if ( lutil_atoi( &level, optarg ) != 0 ) { + fprintf( stderr, + "unrecognized log level " + "\"%s\"\n", optarg ); + exit( EXIT_FAILURE ); } if ( level ) { diff --git a/servers/slapd/user.c b/servers/slapd/user.c index 29aa25b429..7143802f31 100644 --- a/servers/slapd/user.c +++ b/servers/slapd/user.c @@ -34,6 +34,7 @@ #include #include "slap.h" +#include "lutil.h" /* * Set real and effective user id and group id, and group access list @@ -49,9 +50,17 @@ slap_init_user( char *user, char *group ) if ( user ) { struct passwd *pwd; - if ( isdigit( (unsigned char) *user )) { + if ( isdigit( (unsigned char) *user ) ) { + unsigned u; + got_uid = 1; - uid = atoi( user ); + if ( lutil_atou( &u, user ) != 0 ) { + Debug( LDAP_DEBUG_ANY, "Unble to parse user %s\n", + user, 0, 0 ); + + exit( EXIT_FAILURE ); + } + uid = (uid_t)u; #ifdef HAVE_GETPWUID pwd = getpwuid( uid ); goto did_getpw; @@ -86,7 +95,15 @@ slap_init_user( char *user, char *group ) if ( group ) { struct group *grp; if ( isdigit( (unsigned char) *group )) { - gid = atoi( group ); + unsigned g; + + if ( lutil_atou( &g, group ) != 0 ) { + Debug( LDAP_DEBUG_ANY, "Unble to parse group %s\n", + group, 0, 0 ); + + exit( EXIT_FAILURE ); + } + gid = (uid_t)g; #ifdef HAVE_GETGRGID grp = getgrgid( gid ); goto did_group; diff --git a/servers/slapd/value.c b/servers/slapd/value.c index cf2d73075e..2a544c050c 100644 --- a/servers/slapd/value.c +++ b/servers/slapd/value.c @@ -700,7 +700,7 @@ ordered_value_add( k = -1; if ( vals[i].bv_val[0] == '{' ) { - k = strtol( vals[i].bv_val+1, &next, 0 ); + k = strtol( vals[i].bv_val + 1, &next, 0 ); if ( next == vals[i].bv_val + 1 || next[ 0 ] != '}' || next - vals[i].bv_val > vals[i].bv_len ) diff --git a/servers/slurpd/args.c b/servers/slurpd/args.c index 4faaadab55..9d9a6baa2e 100644 --- a/servers/slurpd/args.c +++ b/servers/slurpd/args.c @@ -79,7 +79,8 @@ doargs( while ( (i = getopt( argc, argv, "d:f:n:or:t:V" )) != EOF ) { switch ( i ) { - case 'd': /* set debug level and 'do not detach' flag */ + case 'd': { /* set debug level and 'do not detach' flag */ + int level; g->no_detach = 1; if ( optarg[0] == '?' ) { #ifdef LDAP_DEBUG @@ -108,14 +109,19 @@ doargs( return( -1 ); } #ifdef LDAP_DEBUG - ldap_debug |= atoi( optarg ); + if ( lutil_atoi( &level, optarg ) != 0 ) { + fprintf( stderr, "unable to parse debug flag \"%s\".\n", optarg ); + usage( g->myname ); + return( -1 ); + } + ldap_debug |= level; #else /* !LDAP_DEBUG */ - if ( atoi( optarg ) != 0 ) + if ( lutil_atoi( &level, optarg ) != 0 || level != 0 ) /* can't enable debugging - not built with debug code */ fputs( "must compile with LDAP_DEBUG for debugging\n", stderr ); #endif /* LDAP_DEBUG */ - break; + } break; case 'f': /* slapd config file */ LUTIL_SLASHPATH( optarg ); g->slapd_configfile = strdup( optarg ); diff --git a/servers/slurpd/config.c b/servers/slurpd/config.c index be39480cf5..5e91f405b0 100644 --- a/servers/slurpd/config.c +++ b/servers/slurpd/config.c @@ -193,8 +193,7 @@ slurpd_read_config( return( 1 ); } - c = atoi( cargv[1] ); - if( c < 1 ) { + if ( lutil_atoi( &c, cargv[1] ) != 0 || c < 1 ) { Debug( LDAP_DEBUG_ANY, "%s: line %d: invalid interval " "(%d) in \"replicationinterval \" line\n", fname, lineno, c ); @@ -456,7 +455,11 @@ parse_replica_line( if (( hp = strchr( val, ':' )) != NULL ) { *hp = '\0'; hp++; - ri->ri_port = atoi( hp ); + if ( lutil_atoi( &ri->ri_port, hp ) != 0 ) { + fprintf( stderr, "unable to parse port \"%s\", line %d\n", + hp, lineno ); + return -1; + } } if ( ri->ri_port <= 0 ) { ri->ri_port = LDAP_PORT; diff --git a/servers/slurpd/re.c b/servers/slurpd/re.c index 3633732e5f..eaee503cb2 100644 --- a/servers/slurpd/re.c +++ b/servers/slurpd/re.c @@ -49,6 +49,7 @@ #include "slurp.h" #include "globals.h" +#include "lutil.h" /* Forward references */ static Rh *get_repl_hosts LDAP_P(( char *, int *, char ** )); @@ -187,17 +188,30 @@ Re_parse( re->re_changetype = getchangetype( value ); state |= GOT_CHANGETYPE; break; - case T_TIME: + case T_TIME: { + unsigned long t; + if (( p = strchr( value, '.' )) != NULL ) { /* there was a sequence number */ *p++ = '\0'; } - re->re_timestamp = atol( value ); - if ( p != NULL && isdigit( (unsigned char) *p )) { - re->re_seq = atoi( p ); + if ( lutil_atoul( &t, value ) != 0 ) { + Debug( LDAP_DEBUG_ANY, + "Error: Re_parse: unable to parse timestamp \"%s\"\n", + value, 0, 0 ); + return -1; + } + re->re_timestamp = (time_t)t; + if ( p != NULL && isdigit( (unsigned char) *p ) + && lutil_atoi( &re->re_seq, p ) != 0 ) + { + Debug( LDAP_DEBUG_ANY, + "Error: Re_parse: unable to parse sequence number \"%s\"\n", + p, 0, 0 ); + return -1; } state |= GOT_TIME; - break; + } break; case T_DN: re->re_dn = ch_malloc( len + 1 ); AC_MEMCPY( re->re_dn, value, len ); @@ -325,8 +339,8 @@ get_repl_hosts( if (( p = strchr( value, ':' )) != NULL ) { *p = '\0'; p++; - if ( *p != '\0' ) { - port = atoi( p ); + if ( *p != '\0' && lutil_atoi( &port, p ) != 0 ) { + return( NULL ); } } diff --git a/servers/slurpd/st.c b/servers/slurpd/st.c index cb78c2d9c9..5b31dfb8d5 100644 --- a/servers/slurpd/st.c +++ b/servers/slurpd/st.c @@ -43,6 +43,7 @@ #include "slurp.h" #include "globals.h" +#include "lutil.h" /* * Add information about replica host specified by Ri to list @@ -230,11 +231,16 @@ St_read( found = 0; for ( i = 0; i < sglob->st->st_nreplicas; i++ ) { + int p; if ( !strcmp( hostname, sglob->st->st_data[ i ]->hostname ) && - atoi( port ) == sglob->st->st_data[ i ]->port ) { + lutil_atoi( &p, port ) == 0 && p == sglob->st->st_data[ i ]->port ) + { found = 1; - sglob->st->st_data[ i ]->last = atol( timestamp ); - sglob->st->st_data[ i ]->seq = atoi( seq ); + if ( lutil_atol( &sglob->st->st_data[ i ]->last, timestamp ) != 0 + || lutil_atoi( &sglob->st->st_data[ i ]->seq, seq ) != 0 ) + { + found = 0; + } break; } } diff --git a/tests/progs/slapd-addel.c b/tests/progs/slapd-addel.c index 8acd88a810..07c0d175f0 100644 --- a/tests/progs/slapd-addel.c +++ b/tests/progs/slapd-addel.c @@ -32,6 +32,7 @@ #define LDAP_DEPRECATED 1 #include +#include #define LOOPS 100 #define RETRIES 0 @@ -93,7 +94,9 @@ main( int argc, char **argv ) break; case 'p': /* the servers port */ - port = atoi( optarg ); + if ( lutil_atoi( &port, optarg ) != 0 ) { + usage( argv[0] ); + } break; case 'D': /* the servers manager */ @@ -109,15 +112,21 @@ main( int argc, char **argv ) break; case 'l': /* the number of loops */ - loops = atoi( optarg ); + if ( lutil_atoi( &loops, optarg ) != 0 ) { + usage( argv[0] ); + } break; case 'r': /* number of retries */ - retries = atoi( optarg ); + if ( lutil_atoi( &retries, optarg ) != 0 ) { + usage( argv[0] ); + } break; case 't': /* delay in seconds */ - delay = atoi( optarg ); + if ( lutil_atoi( &delay, optarg ) != 0 ) { + usage( argv[0] ); + } break; default: diff --git a/tests/progs/slapd-bind.c b/tests/progs/slapd-bind.c index 25175590f8..be604834a2 100644 --- a/tests/progs/slapd-bind.c +++ b/tests/progs/slapd-bind.c @@ -90,7 +90,9 @@ main( int argc, char **argv ) break; case 'p': /* the servers port */ - port = atoi( optarg ); + if ( lutil_atoi( &port, optarg ) != 0 ) { + usage( argv[0] ); + } break; case 'D': @@ -102,7 +104,9 @@ main( int argc, char **argv ) break; case 'l': /* the number of loops */ - loops = atoi( optarg ); + if ( lutil_atoi( &loops, optarg ) != 0 ) { + usage( argv[0] ); + } break; case 'f': diff --git a/tests/progs/slapd-modify.c b/tests/progs/slapd-modify.c index 727f1c741e..cfda8b67e3 100644 --- a/tests/progs/slapd-modify.c +++ b/tests/progs/slapd-modify.c @@ -28,6 +28,7 @@ #define LDAP_DEPRECATED 1 #include +#include #define LOOPS 100 #define RETRIES 0 @@ -87,7 +88,9 @@ main( int argc, char **argv ) break; case 'p': /* the servers port */ - port = atoi( optarg ); + if ( lutil_atoi( &port, optarg ) != 0 ) { + usage( argv[0] ); + } break; case 'D': /* the servers manager */ @@ -107,15 +110,21 @@ main( int argc, char **argv ) break; case 'l': /* the number of loops */ - loops = atoi( optarg ); + if ( lutil_atoi( &loops, optarg ) != 0 ) { + usage( argv[0] ); + } break; case 'r': /* number of retries */ - retries = atoi( optarg ); + if ( lutil_atoi( &retries, optarg ) != 0 ) { + usage( argv[0] ); + } break; case 't': /* delay in seconds */ - delay = atoi( optarg ); + if ( lutil_atoi( &delay, optarg ) != 0 ) { + usage( argv[0] ); + } break; default: diff --git a/tests/progs/slapd-modrdn.c b/tests/progs/slapd-modrdn.c index d6c5f9257f..908d189251 100644 --- a/tests/progs/slapd-modrdn.c +++ b/tests/progs/slapd-modrdn.c @@ -32,6 +32,7 @@ #define LDAP_DEPRECATED 1 #include +#include #define LOOPS 100 #define RETRIES 0 @@ -88,7 +89,9 @@ main( int argc, char **argv ) break; case 'p': /* the servers port */ - port = atoi( optarg ); + if ( lutil_atoi( &port, optarg ) != 0 ) { + usage( argv[0] ); + } break; case 'D': /* the servers manager */ @@ -104,15 +107,21 @@ main( int argc, char **argv ) break; case 'l': /* the number of loops */ - loops = atoi( optarg ); + if ( lutil_atoi( &loops, optarg ) != 0 ) { + usage( argv[0] ); + } break; case 'r': /* the number of retries */ - retries = atoi( optarg ); + if ( lutil_atoi( &retries, optarg ) != 0 ) { + usage( argv[0] ); + } break; case 't': /* delay in seconds */ - delay = atoi( optarg ); + if ( lutil_atoi( &delay, optarg ) != 0 ) { + usage( argv[0] ); + } break; default: diff --git a/tests/progs/slapd-read.c b/tests/progs/slapd-read.c index c5cb56ce33..b70ace580f 100644 --- a/tests/progs/slapd-read.c +++ b/tests/progs/slapd-read.c @@ -32,6 +32,7 @@ #define LDAP_DEPRECATED 1 #include +#include #define LOOPS 100 #define RETRIES 0 @@ -77,7 +78,9 @@ main( int argc, char **argv ) break; case 'p': /* the servers port */ - port = atoi( optarg ); + if ( lutil_atoi( &port, optarg ) != 0 ) { + usage( argv[0] ); + } break; case 'e': /* DN to search for */ @@ -85,15 +88,21 @@ main( int argc, char **argv ) break; case 'l': /* the number of loops */ - loops = atoi( optarg ); + if ( lutil_atoi( &loops, optarg ) != 0 ) { + usage( argv[0] ); + } break; case 'r': /* the number of retries */ - retries = atoi( optarg ); + if ( lutil_atoi( &retries, optarg ) != 0 ) { + usage( argv[0] ); + } break; case 't': /* delay in seconds */ - delay = atoi( optarg ); + if ( lutil_atoi( &delay, optarg ) != 0 ) { + usage( argv[0] ); + } break; default: diff --git a/tests/progs/slapd-search.c b/tests/progs/slapd-search.c index 9d9afe1e4f..0f3c1e63a0 100644 --- a/tests/progs/slapd-search.c +++ b/tests/progs/slapd-search.c @@ -32,6 +32,7 @@ #define LDAP_DEPRECATED 1 #include +#include #define LOOPS 100 #define RETRIES 0 @@ -83,7 +84,9 @@ main( int argc, char **argv ) break; case 'p': /* the servers port */ - port = atoi( optarg ); + if ( lutil_atoi( &port, optarg ) != 0 ) { + usage( argv[0] ); + } break; case 'D': /* the servers manager */ @@ -103,15 +106,21 @@ main( int argc, char **argv ) break; case 'l': /* number of loops */ - loops = atoi( optarg ); + if ( lutil_atoi( &loops, optarg ) != 0 ) { + usage( argv[0] ); + } break; case 'r': /* number of retries */ - retries = atoi( optarg ); + if ( lutil_atoi( &retries, optarg ) != 0 ) { + usage( argv[0] ); + } break; case 't': /* delay in seconds */ - delay = atoi( optarg ); + if ( lutil_atoi( &delay, optarg ) != 0 ) { + usage( argv[0] ); + } break; default: diff --git a/tests/progs/slapd-tester.c b/tests/progs/slapd-tester.c index e49947198b..8cf65ef9e7 100644 --- a/tests/progs/slapd-tester.c +++ b/tests/progs/slapd-tester.c @@ -33,6 +33,7 @@ #include "ldap_defaults.h" +#include "lutil.h" #define SEARCHCMD "slapd-search" @@ -159,7 +160,9 @@ main( int argc, char **argv ) break; case 'j': /* the number of parallel clients */ - maxkids = atoi( optarg ); + if ( lutil_atoi( &maxkids, optarg ) != 0 ) { + usage( argv[0] ); + } break; case 'l': /* the number of loops per client */ -- 2.39.5