Commit 20f2548c authored by Pierangelo Masarati's avatar Pierangelo Masarati
Browse files

fix declarations of buffers for numeric strings; other related cleanup

parent 9ab9162f
......@@ -532,9 +532,9 @@ static int smbk5pwd_exop_passwd(
qpw->rs_mods = ml;
keys = ch_malloc( 2 * sizeof(struct berval) );
keys[0].bv_val = ch_malloc( STRLENOF( "9223372036854775807L" ) + 1 );
keys[0].bv_val = ch_malloc( LDAP_PVT_INTTYPE_CHARS(long) );
keys[0].bv_len = snprintf(keys[0].bv_val,
STRLENOF( "9223372036854775807L" ) + 1,
LDAP_PVT_INTTYPE_CHARS(long),
"%ld", slap_get_time());
BER_BVZERO( &keys[1] );
......@@ -554,9 +554,9 @@ static int smbk5pwd_exop_passwd(
qpw->rs_mods = ml;
keys = ch_malloc( 2 * sizeof(struct berval) );
keys[0].bv_val = ch_malloc( STRLENOF( "9223372036854775807L" ) + 1 );
keys[0].bv_val = ch_malloc( LDAP_PVT_INTTYPE_CHARS(long) );
keys[0].bv_len = snprintf(keys[0].bv_val,
STRLENOF( "9223372036854775807L" ) + 1,
LDAP_PVT_INTTYPE_CHARS(long),
"%ld", slap_get_time() + pi->smb_must_change);
BER_BVZERO( &keys[1] );
......@@ -577,9 +577,9 @@ static int smbk5pwd_exop_passwd(
qpw->rs_mods = ml;
keys = ch_malloc( 2 * sizeof(struct berval) );
keys[0].bv_val = ch_malloc( STRLENOF( "9223372036854775807L" ) + 1 );
keys[0].bv_val = ch_malloc( LDAP_PVT_INTTYPE_CHARS(long) );
keys[0].bv_len = snprintf(keys[0].bv_val,
STRLENOF( "9223372036854775807L" ) + 1,
LDAP_PVT_INTTYPE_CHARS(long),
"%ld", slap_get_time() + pi->smb_can_change);
BER_BVZERO( &keys[1] );
......
......@@ -169,7 +169,7 @@ LDAP_F( int ) ldap_bv2rdn_x LDAP_P((
struct berval *, LDAPRDN *, char **, unsigned flags, void *ctx ));
LDAP_F( int ) ldap_rdn2bv_x LDAP_P((
LDAPRDN rdn, struct berval *bv, unsigned flags, void *ctx ));
#endif
#endif /* LDAP_AVA_NULL */
/* url.c */
LDAP_F (void) ldap_pvt_hex_unescape LDAP_P(( char *s ));
......@@ -225,7 +225,7 @@ LDAP_F (void) ldap_pvt_sasl_remove LDAP_P(( struct sockbuf * ));
#ifndef LDAP_PVT_SASL_LOCAL_SSF
#define LDAP_PVT_SASL_LOCAL_SSF 71 /* SSF for Unix Domain Sockets */
#endif
#endif /* ! LDAP_PVT_SASL_LOCAL_SSF */
struct ldap;
struct ldapmsg;
......@@ -316,6 +316,8 @@ LDAP_END_DECL
* If none is available, unsigned long data is used.
*/
LDAP_BEGIN_DECL
#ifdef USE_MP_BIGNUM
/*
* Use OpenSSL's BIGNUM
......@@ -404,4 +406,15 @@ typedef unsigned long ldap_pvt_mp_t;
#include "ldap_pvt_uc.h"
LDAP_END_DECL
LDAP_BEGIN_DECL
#include <limits.h> /* get CHAR_BIT */
/* Buffer space for sign, decimal digits and \0. Note: log10(2) < 146/485. */
#define LDAP_PVT_INTTYPE_CHARS(type) (((sizeof(type)*CHAR_BIT-1)*146)/485 + 3)
LDAP_END_DECL
#endif /* _LDAP_PVT_H */
......@@ -582,7 +582,7 @@ desc2str_len( LDAPURLDesc *u )
len += sep;
if ( u->lud_port ) {
char buf[] = ":65535";
char buf[ STRLENOF(":65535") + 1 ];
len += snprintf( buf, sizeof( buf ), ":%d", u->lud_port );
if ( u->lud_host && u->lud_host[0] ) {
......
......@@ -17,6 +17,7 @@
#include <stdio.h>
#include <ac/stdlib.h>
#include <ac/stdarg.h>
#include <ac/string.h>
#include <ac/ctype.h>
#include <ac/unistd.h>
......@@ -885,3 +886,53 @@ lutil_unparse_time(
return 0;
}
/*
* formatted print to string
*
* - if return code < 0, the error code returned by vsnprintf(3) is returned
*
* - if return code > 0, the buffer was not long enough;
* - if next is not NULL, *next will be set to buf + bufsize - 1
* - if len is not NULL, *len will contain the required buffer length
*
* - if return code == 0, the buffer was long enough;
* - if next is not NULL, *next will point to the end of the string printed so far
* - if len is not NULL, *len will contain the length of the string printed so far
*/
int
lutil_snprintf( char *buf, ber_len_t bufsize, char **next, ber_len_t *len, LDAP_CONST char *fmt, ... )
{
va_list ap;
int ret;
assert( buf != NULL );
assert( bufsize > 0 );
assert( fmt != NULL );
va_start( ap, fmt );
ret = vsnprintf( buf, bufsize, fmt, ap );
va_end( ap );
if ( ret < 0 ) {
return ret;
}
if ( len ) {
*len = ret;
}
if ( ret >= bufsize ) {
if ( next ) {
*next = &buf[ bufsize - 1 ];
}
return 1;
}
if ( next ) {
*next = &buf[ ret ];
}
return 0;
}
......@@ -1280,7 +1280,7 @@ slap_acl_mask(
/* extract IP and try exact match */
} else if ( b->a_peername_style == ACL_STYLE_IP ) {
char *port;
char buf[] = "255.255.255.255";
char buf[STRLENOF("255.255.255.255") + 1];
struct berval ip;
unsigned long addr;
int port_number = -1;
......@@ -1325,7 +1325,7 @@ slap_acl_mask(
/* extract IPv6 and try exact match */
} else if ( b->a_peername_style == ACL_STYLE_IPV6 ) {
char *port;
char buf[] = "FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF";
char buf[STRLENOF("FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF") + 1];
struct berval ip;
struct in6_addr addr;
int port_number = -1;
......
......@@ -39,7 +39,7 @@
#include "lutil.h"
static const char style_base[] = "base";
char *style_strings[] = {
const char *style_strings[] = {
"regex",
"expand",
"exact",
......
......@@ -236,7 +236,7 @@ monitor_subsys_conn_update(
if ( n != -1 ) {
Attribute *a;
char buf[] = "+9223372036854775807L";
char buf[LDAP_PVT_INTTYPE_CHARS(long)];
ber_len_t len;
a = attr_find( e->e_attrs, mi->mi_ad_monitorCounter );
......
......@@ -162,7 +162,7 @@ monitor_subsys_rww_update(
struct berval nrdn;
Attribute *a;
char buf[] = "+9223372036854775807L";
char buf[LDAP_PVT_INTTYPE_CHARS(long)];
long num = 0;
ber_len_t len;
......
......@@ -794,7 +794,7 @@ backsql_add_attr(
int prc = LDAP_SUCCESS;
/* first parameter #, parameter order */
SQLUSMALLINT pno, po;
char logbuf[] = "val[18446744073709551615UL], id=18446744073709551615UL";
char logbuf[ STRLENOF("val[], id=") + 2*LDAP_PVT_INTTYPE_CHARS(unsigned long)];
/*
* Do not deal with the objectClass that is used
......
......@@ -540,8 +540,8 @@ backsql_db_config(
0, 0 );
} else if ( !strcasecmp( argv[ 0 ], "fetch_attrs" ) ) {
char *str, *s, *next;
char delimstr[] = ",";
char *str, *s, *next;
const char *delimstr = ",";
if ( argc < 2 ) {
Debug( LDAP_DEBUG_TRACE,
......@@ -761,10 +761,10 @@ create_baseObject(
"objectClass: extensibleObject\n"
"description: builtin baseObject for back-sql\n"
"description: all entries mapped "
"in the \"ldap_entries\" table\n"
"description: must have "
"\"" BACKSQL_BASEOBJECT_IDSTR "\" "
"in the \"parent\" column",
"in table \"ldap_entries\" "
"must have "
"\"" BACKSQL_BASEOBJECT_IDSTR "\" "
"in the \"parent\" column",
be->be_suffix[0].bv_val );
bi->sql_baseObject = str2entry( buf );
......
......@@ -235,7 +235,7 @@ int backsql_free_db_conn( Operation *op, SQLHDBC dbh );
* util.c
*/
extern char
extern const char
backsql_def_oc_query[],
backsql_def_needs_select_oc_query[],
backsql_def_at_query[],
......@@ -246,8 +246,7 @@ extern char
backsql_def_subtree_cond[],
backsql_def_upper_subtree_cond[],
backsql_id_query[],
backsql_def_concat_func[];
extern char
backsql_def_concat_func[],
backsql_check_dn_ru_query[];
struct berbuf * backsql_strcat_x( struct berbuf *dest, void *memctx, ... );
......
......@@ -189,7 +189,7 @@ static int
backsql_add_sysmaps( backsql_info *bi, backsql_oc_map_rec *oc_map )
{
backsql_at_map_rec *at_map;
char s[] = "+9223372036854775807L";
char s[LDAP_PVT_INTTYPE_CHARS(long)];
struct berval sbv;
struct berbuf bb;
......@@ -228,13 +228,11 @@ backsql_add_sysmaps( backsql_info *bi, backsql_oc_map_rec *oc_map )
at_map->bam_add_proc = NULL;
{
char tmp[] =
"INSERT INTO ldap_entry_objclasses "
char tmp[STRLENOF("INSERT INTO ldap_entry_objclasses "
"(entry_id,oc_name) VALUES "
"((SELECT id FROM ldap_entries "
"WHERE oc_map_id="
"18446744073709551615UL " /* 64 bit ULONG */
"AND keyval=?),?)";
"WHERE oc_map_id= "
"AND keyval=?),?)") + LDAP_PVT_INTTYPE_CHARS(unsigned long)];
snprintf( tmp, sizeof(tmp),
"INSERT INTO ldap_entry_objclasses "
"(entry_id,oc_name) VALUES "
......@@ -246,12 +244,10 @@ backsql_add_sysmaps( backsql_info *bi, backsql_oc_map_rec *oc_map )
at_map->bam_delete_proc = NULL;
{
char tmp[] =
"DELETE FROM ldap_entry_objclasses "
char tmp[STRLENOF("DELETE FROM ldap_entry_objclasses "
"WHERE entry_id=(SELECT id FROM ldap_entries "
"WHERE oc_map_id="
"18446744073709551615UL " /* 64 bit ULONG */
"AND keyval=?) AND oc_name=?";
"WHERE oc_map_id= "
"AND keyval=?) AND oc_name=?") + LDAP_PVT_INTTYPE_CHARS(unsigned long)];
snprintf( tmp, sizeof(tmp),
"DELETE FROM ldap_entry_objclasses "
"WHERE entry_id=(SELECT id FROM ldap_entries "
......
......@@ -864,7 +864,7 @@ backsql_process_filter( backsql_srch_info *bsi, Filter *f )
struct berval keyval;
#else /* ! BACKSQL_ARBITRARY_KEY */
unsigned long keyval;
char keyvalbuf[] = "18446744073709551615";
char keyvalbuf[LDAP_PVT_INTTYPE_CHARS(unsigned long)];
#endif /* ! BACKSQL_ARBITRARY_KEY */
switch ( f->f_choice ) {
......
......@@ -37,32 +37,32 @@
#define BACKSQL_STR_GROW 256
char backsql_def_oc_query[] =
const char backsql_def_oc_query[] =
"SELECT id,name,keytbl,keycol,create_proc,delete_proc,expect_return "
"FROM ldap_oc_mappings";
char backsql_def_needs_select_oc_query[] =
const char backsql_def_needs_select_oc_query[] =
"SELECT id,name,keytbl,keycol,create_proc,create_keyval,delete_proc,"
"expect_return FROM ldap_oc_mappings";
char backsql_def_at_query[] =
const char backsql_def_at_query[] =
"SELECT name,sel_expr,from_tbls,join_where,add_proc,delete_proc,"
"param_order,expect_return,sel_expr_u FROM ldap_attr_mappings "
"WHERE oc_map_id=?";
char backsql_def_delentry_stmt[] = "DELETE FROM ldap_entries WHERE id=?";
char backsql_def_renentry_stmt[] =
const char backsql_def_delentry_stmt[] = "DELETE FROM ldap_entries WHERE id=?";
const char backsql_def_renentry_stmt[] =
"UPDATE ldap_entries SET dn=?,parent=?,keyval=? WHERE id=?";
char backsql_def_insentry_stmt[] =
const char backsql_def_insentry_stmt[] =
"INSERT INTO ldap_entries (dn,oc_map_id,parent,keyval) "
"VALUES (?,?,?,?)";
char backsql_def_delobjclasses_stmt[] = "DELETE FROM ldap_entry_objclasses "
const char backsql_def_delobjclasses_stmt[] = "DELETE FROM ldap_entry_objclasses "
"WHERE entry_id=?";
char backsql_def_subtree_cond[] = "ldap_entries.dn LIKE CONCAT('%',?)";
char backsql_def_upper_subtree_cond[] = "(ldap_entries.dn) LIKE CONCAT('%',?)";
char backsql_id_query[] = "SELECT id,keyval,oc_map_id,dn FROM ldap_entries WHERE ";
const char backsql_def_subtree_cond[] = "ldap_entries.dn LIKE CONCAT('%',?)";
const char backsql_def_upper_subtree_cond[] = "(ldap_entries.dn) LIKE CONCAT('%',?)";
const char backsql_id_query[] = "SELECT id,keyval,oc_map_id,dn FROM ldap_entries WHERE ";
/* better ?||? or cast(?||? as varchar) */
char backsql_def_concat_func[] = "CONCAT(?,?)";
const char backsql_def_concat_func[] = "CONCAT(?,?)";
/* TimesTen */
char backsql_check_dn_ru_query[] = "SELECT dn_ru FROM ldap_entries";
const char backsql_check_dn_ru_query[] = "SELECT dn_ru FROM ldap_entries";
struct berbuf *
backsql_strcat_x( struct berbuf *dest, void *memctx, ... )
......
......@@ -121,7 +121,7 @@ typedef struct config_args_s {
char *tline;
const char *fname;
int lineno;
char log[MAXPATHLEN + STRLENOF(": line 18446744073709551615") + 1];
char log[MAXPATHLEN + STRLENOF(": line ") + LDAP_PVT_INTTYPE_CHARS(unsigned long)];
#define cr_msg reply.msg
ConfigReply reply;
int depth;
......
......@@ -1058,7 +1058,7 @@ get_url_perms(
S_IRGRP, S_IWGRP, S_IXGRP,
S_IROTH, S_IWOTH, S_IXOTH
};
static char c[] = "-rwxrwxrwx";
static const char c[] = "-rwxrwxrwx";
if ( value[ j ] == c[ j ] ) {
p |= m[ j ];
......
......@@ -395,7 +395,7 @@ dds_op_add( Operation *op, SlapReply *rs )
/* handle dynamic object operational attr(s) */
if ( is_dynamicObject ) {
time_t ttl, expire;
char ttlbuf[] = "31557600";
char ttlbuf[STRLENOF("31557600") + 1];
char tsbuf[ LDAP_LUTIL_GENTIME_BUFSIZE ];
struct berval bv;
......@@ -414,10 +414,12 @@ dds_op_add( Operation *op, SlapReply *rs )
ttl = DDS_DEFAULT_TTL( di );
/* assert because should be checked at configure */
assert( ttl <= DDS_RF2589_MAX_TTL );
bv.bv_val = ttlbuf;
bv.bv_len = snprintf( ttlbuf, sizeof( ttlbuf ), "%ld", ttl );
assert( bv.bv_len < sizeof( ttlbuf ) );
/* FIXME: apparently, values in op->ora_e are malloc'ed
* on the thread's slab; works fine by chance,
......@@ -1004,7 +1006,7 @@ dds_op_extended( Operation *op, SlapReply *rs )
slap_callback sc = { 0 };
Modifications ttlmod = { { 0 } };
struct berval ttlvalues[ 2 ];
char ttlbuf[] = "31557600";
char ttlbuf[STRLENOF("31557600") + 1];
rs->sr_err = slap_parse_refresh( op->ore_reqdata, NULL, &ttl,
&rs->sr_text, NULL );
......
......@@ -98,7 +98,7 @@ LDAP_SLAPD_F (int) acl_string_expand LDAP_P((
/*
* aclparse.c
*/
LDAP_SLAPD_V (char *) style_strings[];
LDAP_SLAPD_V (LDAP_CONST char *) style_strings[];
LDAP_SLAPD_F (int) parse_acl LDAP_P(( Backend *be,
const char *fname, int lineno,
......@@ -2039,7 +2039,7 @@ LDAP_SLAPD_F (int) fe_access_allowed LDAP_P((
# define UI2BVX(bv,ui,ctx) \
do { \
char buf[] = "+9223372036854775807L"; \
char buf[LDAP_PVT_INTTYPE_CHARS(long)]; \
ber_len_t len; \
len = snprintf( buf, sizeof( buf ), UI2BV_FORMAT, (ui) ); \
if ( len > (bv)->bv_len ) { \
......
......@@ -2446,7 +2446,7 @@ typedef struct Opheader {
slap_counters_t *oh_counters;
char oh_log_prefix[ /* sizeof("conn=18446744073709551615 op=18446744073709551615") */ SLAP_TEXT_BUFLEN ];
char oh_log_prefix[ /* sizeof("conn= op=") + 2*LDAP_PVT_INTTYPE_CHARS(unsigned long) */ SLAP_TEXT_BUFLEN ];
#ifdef LDAP_SLAPI
void *oh_extensions; /* NS-SLAPI plugin */
......
......@@ -3522,7 +3522,7 @@ parse_syncrepl_line(
si->si_anfile = attr_fname;
} else {
char *str, *s, *next;
char delimstr[] = " ,\t";
const char *delimstr = " ,\t";
str = ch_strdup( val );
for ( s = ldap_pvt_strtok( str, delimstr, &next );
s != NULL;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment