@@ -228,18 +228,20 @@ 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 ) {
231
232
part = (msc_string * )apr_pcalloc (mptmp , sizeof (msc_string ));
232
233
if (part == NULL ) return -1 ;
233
234
part -> value_len = p - text_start ;
234
235
part -> value = apr_pstrmemdup (mptmp , text_start , part -> value_len );
235
236
* (msc_string * * )apr_array_push (arr ) = part ;
237
+ }
236
238
237
239
/* Resolve the macro and add that to the array. */
238
240
var_resolved = msre_create_var_ex (mptmp , msr -> modsecurity -> msre , var_name , var_value ,
239
241
msr , & my_error_msg );
240
242
if (var_resolved != NULL ) {
241
243
var_generated = generate_single_var (msr , var_resolved , NULL , rule , mptmp );
242
- if (var_generated != NULL ) {
244
+ if (var_generated != NULL && var_generated -> value_len ) {
243
245
part = (msc_string * )apr_pcalloc (mptmp , sizeof (msc_string ));
244
246
if (part == NULL ) return -1 ;
245
247
part -> value_len = var_generated -> value_len ;
@@ -280,13 +282,11 @@ int expand_macros(modsec_rec *msr, msc_string *var, msre_rule *rule, apr_pool_t
280
282
part -> value_len = strlen (part -> value );
281
283
* (msc_string * * )apr_array_push (arr ) = part ;
282
284
}
283
- } while (p != NULL );
285
+ } while (p != NULL && * next_text_start );
284
286
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.
287
+ /* Combine text parts into a single string now.
288
+ * If no macro was present, we already returned
288
289
*/
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,7 +306,6 @@ 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
- }
310
309
311
310
return 1 ;
312
311
}
0 commit comments