case REWRITE_MODE_COPY_INPUT:
*result = strdup( string );
- rc = REWRITE_REGEXEC_OK;
+ rc = ( *result != NULL ) ? REWRITE_REGEXEC_OK : REWRITE_REGEXEC_ERR;
goto rc_return;
case REWRITE_MODE_USE_DEFAULT:
*/
l = p - string - 1;
s = calloc( sizeof( char ), l + 1 );
+ if ( s == NULL ) {
+ return NULL;
+ }
AC_MEMCPY( s, string, l );
s[ l ] = 0;
*/
map->lm_type = REWRITE_MAP_SUBCONTEXT;
map->lm_name = strdup( s + 1 );
+ if ( map->lm_name == NULL ) {
+ rc = -1;
+ goto cleanup;
+ }
map->lm_data = rewrite_context_find( info, s + 1 );
if ( map->lm_data == NULL ) {
rc = -1;
map->lm_name = strdup( s + 1 );
}
}
+ if ( map->lm_name == NULL ) {
+ rc = -1;
+ goto cleanup;
+ }
break;
/*
map->lm_type = REWRITE_MAP_GET_OP_VAR;
map->lm_name = strdup( s + 1 );
}
+ if ( map->lm_name == NULL ) {
+ rc = -1;
+ goto cleanup;
+ }
break;
/*
case REWRITE_OPERATOR_PARAM_GET: /* '$' */
map->lm_type = REWRITE_MAP_GET_PARAM;
map->lm_name = strdup( s + 1 );
+ if ( map->lm_name == NULL ) {
+ rc = -1;
+ goto cleanup;
+ }
break;
/*
default:
map->lm_type = REWRITE_MAP_BUILTIN;
map->lm_name = strdup( s );
+ if ( map->lm_name == NULL ) {
+ rc = -1;
+ goto cleanup;
+ }
map->lm_data = rewrite_builtin_map_find( info, s );
if ( map->lm_data == NULL ) {
rc = -1;
rc = rewrite_var_set( &op->lo_vars, map->lm_name,
key->bv_val, 1 )
? REWRITE_SUCCESS : REWRITE_ERR;
- if ( map->lm_type == REWRITE_MAP_SET_OP_VAR ) {
- val->bv_val = strdup( "" );
- } else {
- val->bv_val = strdup( key->bv_val );
- val->bv_len = key->bv_len;
+ if ( rc == REWRITE_SUCCESS ) {
+ if ( map->lm_type == REWRITE_MAP_SET_OP_VAR ) {
+ val->bv_val = strdup( "" );
+ } else {
+ val->bv_val = strdup( key->bv_val );
+ val->bv_len = key->bv_len;
+ }
+ if ( val->bv_val == NULL ) {
+ rc = REWRITE_ERR;
+ }
}
break;
} else {
val->bv_val = strdup( var->lv_value.bv_val );
val->bv_len = var->lv_value.bv_len;
+ if ( val->bv_val == NULL ) {
+ rc = REWRITE_ERR;
+ }
}
break;
}
}
rc = rewrite_session_var_set( info, op->lo_cookie,
map->lm_name, key->bv_val );
- if ( map->lm_type == REWRITE_MAP_SET_SESN_VAR ) {
- val->bv_val = strdup( "" );
- } else {
- val->bv_val = strdup( key->bv_val );
- val->bv_len = key->bv_len;
+ if ( rc == REWRITE_SUCCESS ) {
+ if ( map->lm_type == REWRITE_MAP_SET_SESN_VAR ) {
+ val->bv_val = strdup( "" );
+ } else {
+ val->bv_val = strdup( key->bv_val );
+ val->bv_len = key->bv_len;
+ }
+ if ( val->bv_val == NULL ) {
+ rc = REWRITE_ERR;
+ }
}
break;
)
{
struct rewrite_var *var;
+ int rc = REWRITE_SUCCESS;
assert( info != NULL );
assert( name != NULL );
free( var->lv_value.bv_val );
var->lv_value.bv_val = strdup( value );
var->lv_value.bv_len = strlen( value );
+
} else {
var = rewrite_var_insert( &info->li_params, name, value );
- if ( var == NULL ) {
-#ifdef USE_REWRITE_LDAP_PVT_THREADS
- ldap_pvt_thread_rdwr_wunlock( &info->li_params_mutex );
-#endif /* USE_REWRITE_LDAP_PVT_THREADS */
- return REWRITE_ERR;
- }
+ }
+
+ if ( var == NULL || var->lv_value.bv_val == NULL ) {
+ rc = REWRITE_ERR;
}
#ifdef USE_REWRITE_LDAP_PVT_THREADS
ldap_pvt_thread_rdwr_wunlock( &info->li_params_mutex );
#endif /* USE_REWRITE_LDAP_PVT_THREADS */
- return REWRITE_SUCCESS;
+ return rc;
}
/*
)
{
struct rewrite_var *var;
+ int rc = REWRITE_SUCCESS;
assert( info != NULL );
assert( name != NULL );
#endif /* USE_REWRITE_LDAP_PVT_THREADS */
var = rewrite_var_find( info->li_params, name );
- if ( var == NULL ) {
-
-#ifdef USE_REWRITE_LDAP_PVT_THREADS
- ldap_pvt_thread_rdwr_runlock( &info->li_params_mutex );
-#endif /* USE_REWRITE_LDAP_PVT_THREADS */
-
- return REWRITE_ERR;
- } else {
+ if ( var != NULL ) {
value->bv_val = strdup( var->lv_value.bv_val );
value->bv_len = var->lv_value.bv_len;
}
+
+ if ( var == NULL || value->bv_val == NULL ) {
+ rc = REWRITE_ERR;
+ }
#ifdef USE_REWRITE_LDAP_PVT_THREADS
- ldap_pvt_thread_rdwr_runlock( &info->li_params_mutex );
+ ldap_pvt_thread_rdwr_runlock( &info->li_params_mutex );
#endif /* USE_REWRITE_LDAP_PVT_THREADS */
-
+
return REWRITE_SUCCESS;
}
* REGEX compilation (luckily I don't need to take care of this ...)
*/
if ( regcomp( &rule->lr_regex, ( char * )pattern, flags ) != 0 ) {
- free( rule );
goto fail;
}
rule->lr_pattern = strdup( pattern );
rule->lr_subststring = strdup( result );
rule->lr_flagstring = strdup( flagstring );
+ if ( rule->lr_pattern == NULL
+ || rule->lr_subststring == NULL
+ || rule->lr_flagstring == NULL )
+ {
+ goto fail;
+ }
/*
* Load compiled data into rule
return REWRITE_SUCCESS;
fail:
+ if ( rule ) {
+ if ( rule->lr_pattern ) free( rule->lr_pattern );
+ if ( rule->lr_subststring ) free( rule->lr_subststring );
+ if ( rule->lr_flagstring ) free( rule->lr_flagstring );
+ free( rule );
+ }
destroy_actions( first_action );
free( subst );
return REWRITE_ERR;
{
struct rewrite_session *session;
struct rewrite_var *var;
+ int rc = REWRITE_SUCCESS;
assert( info != NULL );
assert( cookie != NULL );
#endif /* USE_REWRITE_LDAP_PVT_THREADS */
var = rewrite_var_find( session->ls_vars, name );
- if ( var == NULL ) {
-
-#ifdef USE_REWRITE_LDAP_PVT_THREADS
- ldap_pvt_thread_rdwr_runlock( &session->ls_vars_mutex );
-#endif /* USE_REWRITE_LDAP_PVT_THREADS */
-
- rewrite_session_return( info, session );
-
- return REWRITE_ERR;
- } else {
+ if ( var != NULL ) {
value->bv_val = strdup( var->lv_value.bv_val );
value->bv_len = var->lv_value.bv_len;
}
-
+
+ if ( var == NULL || value->bv_val == NULL ) {
+ rc = REWRITE_ERR;
+ }
+
#ifdef USE_REWRITE_LDAP_PVT_THREADS
ldap_pvt_thread_rdwr_runlock( &session->ls_vars_mutex );
#endif /* USE_REWRITE_LDAP_PVT_THREADS */
rewrite_session_return( info, session );
-
- return REWRITE_SUCCESS;
+
+ return rc;
}
static void
subs_len += l;
subs[ nsub ].bv_len = l;
subs[ nsub ].bv_val = malloc( l + 1 );
+ if ( subs[ nsub ].bv_val == NULL ) {
+ free( subs );
+ goto cleanup;
+ }
AC_MEMCPY( subs[ nsub ].bv_val, begin, l );
subs[ nsub ].bv_val[ l ] = '\0';
} else {
int flags
)
{
- ber_len_t len = strlen( value );
+ ber_len_t len;
+
+ assert( value != NULL );
+
+ len = strlen( value );
if ( var->lv_flags & REWRITE_VAR_COPY_VALUE ) {
if ( flags & REWRITE_VAR_COPY_VALUE ) {
}
}
+ if ( var->lv_value.bv_val == NULL ) {
+ return -1;
+ }
+
var->lv_value.bv_len = len;
return 0;
if ( strncasecmp(s, "xpasswd", 7 ) == 0 ) {
map->lm_type = REWRITE_MAP_XPWDMAP;
map->lm_name = strdup( "xpasswd" );
+ if ( map->lm_name == NULL ) {
+ free( map );
+ return NULL;
+ }
assert( s[7] == '}' );
*currpos = s + 8;
l = p - s - c;
filename = calloc( sizeof( char ), l + 1 );
+ if ( filename == NULL ) {
+ free( map );
+ return NULL;
+ }
AC_MEMCPY( filename, s + c, l );
filename[ l ] = '\0';
*/
l = p - s - c;
url = calloc( sizeof( char ), l + 3 );
+ if ( url == NULL ) {
+ free( map );
+ return NULL;
+ }
AC_MEMCPY( url, s + c, l );
url[ l ] = '\0';
int l = strlen( pwd->pw_gecos );
val->bv_val = strdup( pwd->pw_gecos );
- if ( val->bv_val == NULL ) {
-
-#ifdef USE_REWRITE_LDAP_PVT_THREADS
- ldap_pvt_thread_mutex_unlock( &xpasswd_mutex );
-#endif /* USE_REWRITE_LDAP_PVT_THREADS */
-
- rc = REWRITE_ERR;
- break;
- }
val->bv_len = l;
} else
#endif /* HAVE_STRUCT_PASSWD_PW_GECOS */
#ifdef USE_REWRITE_LDAP_PVT_THREADS
ldap_pvt_thread_mutex_unlock( &xpasswd_mutex );
#endif /* USE_REWRITE_LDAP_PVT_THREADS */
-
+
+ if ( val->bv_val == NULL ) {
+ rc = REWRITE_ERR;
+ }
break;
}
#endif /* HAVE_GETPWNAM*/
}
if ( attrsonly == 1 ) {
val->bv_val = ldap_get_dn( ld, entry );
- if ( val->bv_val == NULL ) {
- ldap_msgfree( res );
- ldap_unbind( ld );
- rc = REWRITE_ERR;
- goto rc_return;
- }
+
} else {
values = ldap_get_values( ld, entry,
lud->lud_attrs[0] );
- if ( values == NULL ) {
- ldap_msgfree( res );
- ldap_unbind( ld );
- rc = REWRITE_ERR;
- goto rc_return;
+ if ( values != NULL ) {
+ val->bv_val = strdup( values[ 0 ] );
+ ldap_value_free( values );
}
- val->bv_val = strdup( values[ 0 ] );
- ldap_value_free( values );
}
- val->bv_len = strlen( val->bv_val );
ldap_msgfree( res );
ldap_unbind( ld );
+ if ( val->bv_val == NULL ) {
+ rc = REWRITE_ERR;
+ goto rc_return;
+ }
+ val->bv_len = strlen( val->bv_val );
+
rc = REWRITE_SUCCESS;
- }
+ } break;
}
rc_return:;
while ( a_new != NULL ) {
a_new_desc = a_new->a_desc;
- mod = (Modifications *) malloc( sizeof( Modifications ));
+ mod = (Modifications *) ch_malloc( sizeof( Modifications ));
mod->sml_op = LDAP_MOD_REPLACE;
mod->sml_flags = 0;
count = a_new->a_numvals;
mod->sml_numvals = a_new->a_numvals;
- mod->sml_values = (struct berval*) malloc(
+ mod->sml_values = (struct berval*) ch_malloc(
(count+1) * sizeof( struct berval) );
/* see slap_mods_check() comments...
* in this case, mod->sml_nvalues must be left NULL.
*/
if ( a_new->a_vals != a_new->a_nvals ) {
- mod->sml_nvalues = (struct berval*) malloc(
+ mod->sml_nvalues = (struct berval*) ch_malloc(
(count+1) * sizeof( struct berval) );
} else {
mod->sml_nvalues = NULL;
#if SLAPD_BDB || SLAPD_HDB
#include "alock.h"
+#include "lutil.h"
#include <ac/stdlib.h>
#include <ac/string.h>
if (slot_data->al_appname) free (slot_data->al_appname);
slot_data->al_appname = calloc (1, ALOCK_MAX_APPNAME);
+ if (slot_data->al_appname == NULL) {
+ return -1;
+ }
strncpy (slot_data->al_appname, (char *)slotbuf+32, ALOCK_MAX_APPNAME-1);
(slot_data->al_appname) [ALOCK_MAX_APPNAME-1] = '\0';
char * filename;
int res, max_slot;
int dirty_count, live_count, nosave;
+ char *ptr;
assert (info != NULL);
assert (appname != NULL);
slot_data.al_stamp = time(NULL);
slot_data.al_pid = getpid();
slot_data.al_appname = calloc (1, ALOCK_MAX_APPNAME);
+ if (slot_data.al_appname == NULL) {
+ return ALOCK_UNSTABLE;
+ }
strncpy (slot_data.al_appname, appname, ALOCK_MAX_APPNAME-1);
slot_data.al_appname [ALOCK_MAX_APPNAME-1] = '\0';
filename = calloc (1, strlen (envdir) + strlen ("/alock") + 1);
- strcpy (filename, envdir);
- strcat (filename, "/alock");
+ if (filename == NULL ) {
+ free (slot_data.al_appname);
+ return ALOCK_UNSTABLE;
+ }
+ ptr = lutil_strcopy(filename, envdir);
+ lutil_strcopy(ptr, "/alock");
info->al_fd = open (filename, O_CREAT|O_RDWR, 0666);
free (filename);
if (info->al_fd < 0) {
AttributeDescription *ad_objectClass
= slap_schema.si_ad_objectClass;
AttributeDescription *ad_ref = slap_schema.si_ad_ref;
- e.e_name.bv_val = strdup( op->o_req_dn.bv_val );
+ e.e_name.bv_val = ch_strdup( op->o_req_dn.bv_val );
e.e_name.bv_len = op->o_req_dn.bv_len;
- e.e_nname.bv_val = strdup( op->o_req_ndn.bv_val );
+ e.e_nname.bv_val = ch_strdup( op->o_req_ndn.bv_val );
e.e_nname.bv_len = op->o_req_ndn.bv_len;
e.e_attrs = NULL;
fstr->bv_len = atmp.bv_len + vtmp.bv_len
+ ( sizeof("(=)") - 1 );
- fstr->bv_val = malloc( fstr->bv_len + 1 );
+ fstr->bv_val = ch_malloc( fstr->bv_len + 1 );
snprintf( fstr->bv_val, fstr->bv_len + 1, "(%s=%s)",
atmp.bv_val, vtmp.bv_len ? vtmp.bv_val : "" );
fstr->bv_len = atmp.bv_len + vtmp.bv_len
+ ( sizeof("(>=)") - 1 );
- fstr->bv_val = malloc( fstr->bv_len + 1 );
+ fstr->bv_val = ch_malloc( fstr->bv_len + 1 );
snprintf( fstr->bv_val, fstr->bv_len + 1, "(%s>=%s)",
atmp.bv_val, vtmp.bv_len ? vtmp.bv_val : "" );
fstr->bv_len = atmp.bv_len + vtmp.bv_len
+ ( sizeof("(<=)") - 1 );
- fstr->bv_val = malloc( fstr->bv_len + 1 );
+ fstr->bv_val = ch_malloc( fstr->bv_len + 1 );
snprintf( fstr->bv_val, fstr->bv_len + 1, "(%s<=%s)",
atmp.bv_val, vtmp.bv_len ? vtmp.bv_val : "" );
fstr->bv_len = atmp.bv_len + vtmp.bv_len
+ ( sizeof("(~=)") - 1 );
- fstr->bv_val = malloc( fstr->bv_len + 1 );
+ fstr->bv_val = ch_malloc( fstr->bv_len + 1 );
snprintf( fstr->bv_val, fstr->bv_len + 1, "(%s~=%s)",
atmp.bv_val, vtmp.bv_len ? vtmp.bv_val : "" );
/* cannot be a DN ... */
fstr->bv_len = atmp.bv_len + ( STRLENOF( "(=*)" ) );
- fstr->bv_val = malloc( fstr->bv_len + 128 ); /* FIXME: why 128 ? */
+ fstr->bv_val = ch_malloc( fstr->bv_len + 128 ); /* FIXME: why 128 ? */
snprintf( fstr->bv_val, fstr->bv_len + 1, "(%s=*)",
atmp.bv_val );
}
fstr->bv_len = atmp.bv_len + ( STRLENOF( "(=*)" ) );
- fstr->bv_val = malloc( fstr->bv_len + 1 );
+ fstr->bv_val = ch_malloc( fstr->bv_len + 1 );
snprintf( fstr->bv_val, fstr->bv_len + 1, "(%s=*)",
atmp.bv_val );
case LDAP_FILTER_OR:
case LDAP_FILTER_NOT:
fstr->bv_len = STRLENOF( "(%)" );
- fstr->bv_val = malloc( fstr->bv_len + 128 ); /* FIXME: why 128? */
+ fstr->bv_val = ch_malloc( fstr->bv_len + 128 ); /* FIXME: why 128? */
snprintf( fstr->bv_val, fstr->bv_len + 1, "(%c)",
f->f_choice == LDAP_FILTER_AND ? '&' :
( f->f_mr_dnattrs ? STRLENOF( ":dn" ) : 0 ) +
( !BER_BVISEMPTY( &f->f_mr_rule_text ) ? f->f_mr_rule_text.bv_len + 1 : 0 ) +
vtmp.bv_len + ( STRLENOF( "(:=)" ) );
- fstr->bv_val = malloc( fstr->bv_len + 1 );
+ fstr->bv_val = ch_malloc( fstr->bv_len + 1 );
snprintf( fstr->bv_val, fstr->bv_len + 1, "(%s%s%s%s:=%s)",
atmp.bv_val,
if ( op ) {
*cid = op->o_tmpalloc( sizeof( ComponentId ), op->o_tmpmemctx );
} else {
- *cid = malloc( sizeof( ComponentId ) );
+ *cid = SLAP_MALLOC( sizeof( ComponentId ) );
+ }
+ if (*cid == NULL) {
+ return LDAP_NO_MEMORY;
}
**cid = _cid;
return LDAP_SUCCESS;
ca_comp_ref = op->o_tmpalloc( sizeof( ComponentReference ),
op->o_tmpmemctx );
} else {
- ca_comp_ref = malloc( sizeof( ComponentReference ) );
+ ca_comp_ref = SLAP_MALLOC( sizeof( ComponentReference ) );
}
if ( !ca_comp_ref ) return LDAP_NO_MEMORY;
if ( op )
_ca = op->o_tmpalloc( sizeof( ComponentAssertion ), op->o_tmpmemctx );
else
- _ca = malloc( sizeof( ComponentAssertion ) );
+ _ca = SLAP_MALLOC( sizeof( ComponentAssertion ) );
if ( !_ca ) return LDAP_NO_MEMORY;
if ( op ) {
*filt = op->o_tmpalloc( sizeof(f), op->o_tmpmemctx );
} else {
- *filt = malloc( sizeof(f) );
+ *filt = SLAP_MALLOC( sizeof(f) );
+ }
+ if ( *filt == NULL ) {
+ return LDAP_NO_MEMORY;
}
**filt = f;
}
num_attr_vals++;
/* following malloced will be freed by comp_tree_free () */
- a->a_comp_data = malloc( sizeof( ComponentData ) +
+ a->a_comp_data = SLAP_MALLOC( sizeof( ComponentData ) +
sizeof( ComponentSyntaxInfo* )*num_attr_vals );
if ( !a->a_comp_data ) return LDAP_NO_MEMORY;
num_attr_vals++;/* for NULL termination */
/* following malloced will be freed by comp_tree_free () */
- a->a_comp_data = malloc( sizeof( ComponentData ) + sizeof( ComponentSyntaxInfo* )*num_attr_vals );
+ a->a_comp_data = SLAP_MALLOC( sizeof( ComponentData ) + sizeof( ComponentSyntaxInfo* )*num_attr_vals );
if ( !a->a_comp_data ) {
return LDAP_NO_MEMORY;