From aea52e5bc94fca809e4f5b19da5f9783c533469f Mon Sep 17 00:00:00 2001 From: Pierangelo Masarati Date: Sat, 31 Aug 2002 10:48:02 +0000 Subject: [PATCH] define macros for appropriate sizing of lutil buffers --- include/lutil.h | 6 ++++++ libraries/liblutil/csn.c | 2 +- servers/slapd/back-bdb/init.c | 2 +- servers/slapd/back-monitor/conn.c | 10 +++++----- servers/slapd/back-monitor/time.c | 5 +++-- servers/slapd/modify.c | 6 +++--- servers/slapd/tools/slapadd.c | 8 ++++---- 7 files changed, 23 insertions(+), 16 deletions(-) diff --git a/include/lutil.h b/include/lutil.h index 4c8f425543..4a53306b81 100644 --- a/include/lutil.h +++ b/include/lutil.h @@ -120,6 +120,8 @@ lutil_strncopy LDAP_P(( char *dst, const char *src, size_t n )); struct tm; +/* use this macro to statically allocate buffer for lutil_gentime */ +#define LDAP_LUTIL_GENTIME_BUFSIZE 22 LDAP_LUTIL_F( size_t ) lutil_gentime LDAP_P(( char *s, size_t max, const struct tm *tm )); @@ -133,10 +135,14 @@ LDAP_LUTIL_F( int ) lutil_pair( ber_socket_t sd[2] ); /* uuid.c */ +/* use this macro to allocate buffer for lutil_uuidstr */ +#define LDAP_LUTIL_UUIDSTR_BUFSIZE 40 LDAP_LUTIL_F( size_t ) lutil_uuidstr( char *buf, size_t len ); /* csn.c */ +/* use this macro to allocate buffer for lutil_csnstr */ +#define LDAP_LUTIL_CSNSTR_BUFSIZE 64 LDAP_LUTIL_F( size_t ) lutil_csnstr( char *buf, size_t len, unsigned int replica, unsigned int mod ); diff --git a/libraries/liblutil/csn.c b/libraries/liblutil/csn.c index 0a18918b3b..752ee35f89 100644 --- a/libraries/liblutil/csn.c +++ b/libraries/liblutil/csn.c @@ -65,7 +65,7 @@ lutil_csnstr(char *buf, size_t len, unsigned int replica, unsigned int mod) int main(int argc, char **argv) { - char buf[256]; + char buf[ LDAP_LUTIL_CSNSTR_BUFSIZE ]; if ( ! lutil_csnstr( buf, (size_t) 10, 0, 0 ) ) { fprintf(stderr, "failed lutil_csnstr\n"); diff --git a/servers/slapd/back-bdb/init.c b/servers/slapd/back-bdb/init.c index 978835bd91..f5e9b4ead3 100644 --- a/servers/slapd/back-bdb/init.c +++ b/servers/slapd/back-bdb/init.c @@ -612,7 +612,7 @@ bdb_initialize( db_env_set_func_yield( ldap_pvt_thread_yield ); { - static char uuidbuf[40]; + static char uuidbuf[ LDAP_LUTIL_UUIDSTR_BUFSIZE ]; bdb_uuid.bv_len = lutil_uuidstr( uuidbuf, sizeof( uuidbuf )); bdb_uuid.bv_val = uuidbuf; diff --git a/servers/slapd/back-monitor/conn.c b/servers/slapd/back-monitor/conn.c index 070f8524f9..5bbaca74e1 100644 --- a/servers/slapd/back-monitor/conn.c +++ b/servers/slapd/back-monitor/conn.c @@ -253,9 +253,9 @@ conn_create( { struct monitorentrypriv *mp; struct tm *ltm; - char buf[1024]; - char buf2[22]; - char buf3[22]; + char buf[ 1024 ]; + char buf2[ LDAP_LUTIL_GENTIME_BUFSIZE ]; + char buf3[ LDAP_LUTIL_GENTIME_BUFSIZE ]; struct berval bv[2]; @@ -293,10 +293,10 @@ conn_create( ldap_pvt_thread_mutex_lock( &gmtime_mutex ); ltm = gmtime( &c->c_starttime ); - lutil_gentime( buf2, sizeof(buf2), ltm ); + lutil_gentime( buf2, sizeof( buf2 ), ltm ); ltm = gmtime( &c->c_activitytime ); - lutil_gentime( buf3, sizeof(buf2), ltm ); + lutil_gentime( buf3, sizeof( buf3 ), ltm ); ldap_pvt_thread_mutex_unlock( &gmtime_mutex ); diff --git a/servers/slapd/back-monitor/time.c b/servers/slapd/back-monitor/time.c index 7a950b5934..abc29e366a 100644 --- a/servers/slapd/back-monitor/time.c +++ b/servers/slapd/back-monitor/time.c @@ -59,7 +59,7 @@ monitor_subsys_time_init( struct monitorentrypriv *mp; char buf[1024]; struct tm *tms; - char tmbuf[20]; + char tmbuf[ LDAP_LUTIL_GENTIME_BUFSIZE ]; /* * Note: ltmbuf, ltm are used only if HACK_LOCAL_TIME is defined @@ -220,7 +220,8 @@ monitor_subsys_time_update( Entry *e ) { - char stmbuf[20], ctmbuf[20]; + char stmbuf[ LDAP_LUTIL_GENTIME_BUFSIZE ], + ctmbuf[ LDAP_LUTIL_GENTIME_BUFSIZE ]; struct tm *stm, *ctm; Attribute *a; ber_len_t len; diff --git a/servers/slapd/modify.c b/servers/slapd/modify.c index d0b81b15c7..799aefee93 100644 --- a/servers/slapd/modify.c +++ b/servers/slapd/modify.c @@ -547,8 +547,8 @@ int slap_mods_opattrs( char *textbuf, size_t textlen ) { struct berval name, timestamp, csn; - char timebuf[22]; - char csnbuf[64]; + char timebuf[ LDAP_LUTIL_GENTIME_BUFSIZE ]; + char csnbuf[ LDAP_LUTIL_CSNSTR_BUFSIZE ]; Modifications *mod; int mop = op->o_tag == LDAP_REQ_ADD @@ -603,7 +603,7 @@ int slap_mods_opattrs( } if( SLAP_LASTMOD(be) ) { - char uuidbuf[40]; + char uuidbuf[ LDAP_LUTIL_UUIDSTR_BUFSIZE ]; tmpval.bv_len = lutil_uuidstr( uuidbuf, sizeof( uuidbuf ) ); tmpval.bv_val = uuidbuf; diff --git a/servers/slapd/tools/slapadd.c b/servers/slapd/tools/slapadd.c index e993da5fa8..7e6470ca6f 100644 --- a/servers/slapd/tools/slapadd.c +++ b/servers/slapd/tools/slapadd.c @@ -152,12 +152,12 @@ main( int argc, char **argv ) if ( SLAP_LASTMOD(be) ) { struct tm *ltm; time_t now = slap_get_time(); - char uuidbuf[40]; - struct berval vals[2]; + char uuidbuf[ LDAP_LUTIL_UUIDSTR_BUFSIZE ]; + struct berval vals[ 2 ]; struct berval name, timestamp, csn; - char timebuf[22]; - char csnbuf[64]; + char timebuf[ LDAP_LUTIL_GENTIME_BUFSIZE ]; + char csnbuf[ LDAP_LUTIL_CSNSTR_BUFSIZE ]; ltm = gmtime(&now); lutil_gentime( timebuf, sizeof(timebuf), ltm ); -- 2.39.5