@@ -228,20 +228,18 @@ int expand_macros(modsec_rec *msr, msc_string *var, msre_rule *rule, apr_pool_t
228
228
msre_var * var_resolved = NULL ;
229
229
230
230
/* Add the text part before the macro to the array. */
231
- if (p != text_start ) {
232
231
part = (msc_string * )apr_pcalloc (mptmp , sizeof (msc_string ));
233
232
if (part == NULL ) return -1 ;
234
233
part -> value_len = p - text_start ;
235
234
part -> value = apr_pstrmemdup (mptmp , text_start , part -> value_len );
236
235
* (msc_string * * )apr_array_push (arr ) = part ;
237
- }
238
236
239
237
/* Resolve the macro and add that to the array. */
240
238
var_resolved = msre_create_var_ex (mptmp , msr -> modsecurity -> msre , var_name , var_value ,
241
239
msr , & my_error_msg );
242
240
if (var_resolved != NULL ) {
243
241
var_generated = generate_single_var (msr , var_resolved , NULL , rule , mptmp );
244
- if (var_generated != NULL && var_generated -> value_len ) {
242
+ if (var_generated != NULL ) {
245
243
part = (msc_string * )apr_pcalloc (mptmp , sizeof (msc_string ));
246
244
if (part == NULL ) return -1 ;
247
245
part -> value_len = var_generated -> value_len ;
@@ -282,11 +280,13 @@ int expand_macros(modsec_rec *msr, msc_string *var, msre_rule *rule, apr_pool_t
282
280
part -> value_len = strlen (part -> value );
283
281
* (msc_string * * )apr_array_push (arr ) = part ;
284
282
}
285
- } while (p != NULL && * next_text_start );
283
+ } while (p != NULL );
286
284
287
- /* Combine text parts into a single string now.
288
- * If no macro was present, we already returned
285
+ /* If there's more than one member of the array that
286
+ * means there was at least one macro present. Combine
287
+ * text parts into a single string now.
289
288
*/
289
+ if (arr -> nelts > 1 ) {
290
290
/* Figure out the required size for the string. */
291
291
var -> value_len = 0 ;
292
292
for (i = 0 ; i < arr -> nelts ; i ++ ) {
@@ -306,6 +306,7 @@ int expand_macros(modsec_rec *msr, msc_string *var, msre_rule *rule, apr_pool_t
306
306
offset += part -> value_len ;
307
307
}
308
308
var -> value [offset ] = '\0' ;
309
+ }
309
310
310
311
return 1 ;
311
312
}
0 commit comments