@@ -228,20 +228,18 @@ int expand_macros(modsec_rec *msr, msc_string *var, msre_rule *rule, apr_pool_t
228228 msre_var * var_resolved = NULL ;
229229
230230 /* Add the text part before the macro to the array. */
231- if (p != text_start ) {
232231 part = (msc_string * )apr_pcalloc (mptmp , sizeof (msc_string ));
233232 if (part == NULL ) return -1 ;
234233 part -> value_len = p - text_start ;
235234 part -> value = apr_pstrmemdup (mptmp , text_start , part -> value_len );
236235 * (msc_string * * )apr_array_push (arr ) = part ;
237- }
238236
239237 /* Resolve the macro and add that to the array. */
240238 var_resolved = msre_create_var_ex (mptmp , msr -> modsecurity -> msre , var_name , var_value ,
241239 msr , & my_error_msg );
242240 if (var_resolved != NULL ) {
243241 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 ) {
245243 part = (msc_string * )apr_pcalloc (mptmp , sizeof (msc_string ));
246244 if (part == NULL ) return -1 ;
247245 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
282280 part -> value_len = strlen (part -> value );
283281 * (msc_string * * )apr_array_push (arr ) = part ;
284282 }
285- } while (p != NULL && * next_text_start );
283+ } while (p != NULL );
286284
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.
289288 */
289+ if (arr -> nelts > 1 ) {
290290 /* Figure out the required size for the string. */
291291 var -> value_len = 0 ;
292292 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
306306 offset += part -> value_len ;
307307 }
308308 var -> value [offset ] = '\0' ;
309+ }
309310
310311 return 1 ;
311312}
0 commit comments