Skip to content

Don't crash when preg_match returns empty array#30

Merged
erikyo merged 1 commit intowp-blocks:mainfrom
mirekdlugosz:preg_match_empty
Jan 27, 2023
Merged

Don't crash when preg_match returns empty array#30
erikyo merged 1 commit intowp-blocks:mainfrom
mirekdlugosz:preg_match_empty

Conversation

@mirekdlugosz
Copy link
Copy Markdown
Contributor

CF7 additional settings can be arbitrary strings, with constants around tags. Following are perfectly correct additional settings:

flamingo_email: "[user-email]"
flamingo_name: "[first-name] [last-name]"
flamingo_subject: "Message from [user-email]"
flamingo_message: "[user-message]" 
skip_mail: on

However, if you have such form and try to mark inbound message as spam / ham, cf7-antispam will crash with message similar to:

Warning: Undefined array key 1 in /var/www/html/wp-content/plugins/cf7-antispam/includes/cf7a-antispam-flamingo.php on line 281 Warning: Undefined array key 2 in /var/www/html/wp-content/plugins/cf7-antispam/includes/cf7a-antispam-flamingo.php on line 281

The reason is, flamingo_subject line does not match provided regular expression, but code assumes that regex will always match.

With this patch, such line will be skipped.


In general, there are few cases that CF7 will consider valid, but this plugin will not (space between key and colon, unquoted value, value starting with constant string). But since plugin only ever cares about flamingo_message, which can reasonably be assumed to contain only variable(s) placeholder(s), I decided to apply the least intrusive fix.

@erikyo erikyo merged commit cf63321 into wp-blocks:main Jan 27, 2023
@erikyo
Copy link
Copy Markdown
Collaborator

erikyo commented Jan 27, 2023

You are absolutely right and your patch solves the issue. I will publish soon a new version with your patch (of course you will be among the credits for this version). thank you again!

@mirekdlugosz
Copy link
Copy Markdown
Contributor Author

Credit does not concern me too much, but I appreciate this!

If you are able to cut the new release over the weekend, that would be really great!

@erikyo
Copy link
Copy Markdown
Collaborator

erikyo commented Feb 1, 2023

HI @mirekdlugosz,
sorry for the delay in publishing the new version but I was not able to work on it (and test it correctly) until this afternoon!

The new version also includes a couple of other fixes that were necessary to resolve two small bugs. In addition, I tried to replicate a bug that a wp-forum user had reported concerning automatic honeypots and the latest version of cf7, but despite trying various ways I was never able to reproduce his problem.

I hope that cf7 antispam will be increasingly useful to you and thank you again for your contribution!

@mirekdlugosz
Copy link
Copy Markdown
Contributor Author

@erikyo thank you! Don't worry about the delay :) .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants