From: Dominik Csapak <d.csapak@proxmox.com>
To: Stoiko Ivanov <s.ivanov@proxmox.com>
Cc: pmg-devel@lists.proxmox.com
Subject: Re: [pmg-devel] [PATCH pmg-api v2 1/2] fix #4811: rule db: test regex validity on save
Date: Mon, 18 Dec 2023 14:33:07 +0100 [thread overview]
Message-ID: <4ad662c1-cd20-42f6-9c51-0fd6fb7b58df@proxmox.com> (raw)
In-Reply-To: <ZXyCY2sdhuJznlOv@rosa.proxmox.com>
On 12/15/23 17:44, Stoiko Ivanov wrote:
> Thanks for the patch, this definitely improves UX!
>
> one tiny nit in-line (I'll gladly change that upon applying directly, but
> just don't want to miss anything):
>
> On Fri, Jun 30, 2023 at 10:27:47AM +0200, Dominik Csapak wrote:
>> and warn only when it's an invalid regex on execution, because users may
>> have previously had such rules. Otherwise, pmg-smtp-filter will restart
>> every time it encounters such a rule.
>>
>> do so for every rule type that uses a regex to match
>>
>> Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
>> ---
>> changes from v1:
>> ..snip..
>> diff --git a/src/PMG/RuleDB/MatchArchiveFilename.pm b/src/PMG/RuleDB/MatchArchiveFilename.pm
>> index 2ef3543..5b1cb6d 100644
>> --- a/src/PMG/RuleDB/MatchArchiveFilename.pm
>> +++ b/src/PMG/RuleDB/MatchArchiveFilename.pm
>> @@ -25,6 +25,13 @@ sub parse_entity {
>>
>> my $res;
>>
>> + # test regex for validity
>> + eval { "" =~ m|^$self->{fname}$|i; };
>> + if (my $err = $@) {
>> + warn "invalid regex: $err\n";
>> + return $res;
>> + }
>> +
>> if (my $id = $entity->head->mime_attr('x-proxmox-tmp-aid')) {
>> chomp $id;
>>
>> ..snip..
>> diff --git a/src/PMG/RuleDB/WhoRegex.pm b/src/PMG/RuleDB/WhoRegex.pm
>> index 5c13604..1db6418 100644
>> --- a/src/PMG/RuleDB/WhoRegex.pm
>> +++ b/src/PMG/RuleDB/WhoRegex.pm
>> @@ -60,6 +60,11 @@ sub save {
>> defined($self->{address}) || die "undefined address: ERROR";
>>
>> my $adr = $self->{address};
>> +
>> + # test regex for validity
>> + eval { "" =~ /^$adr$/i; };
>> + die "invalid regex: $@\n" if $@;
>> +
>> $adr =~ s/\\/\\\\/g;
>> $adr = encode('UTF-8', $adr);
>>
>> @@ -100,7 +105,12 @@ sub who_match {
>>
>> my $t = $self->address;
>>
>> - return $addr =~ m/^$t$/i;
>> + my $res = '';
> we use the result as condition in an if (pmg-smtp-filter apply_rules),
> I'd rather leave it as undef instead of '' - for consistency with the
> other objects (see diff-context above) - as I asked myself a bit too long
> why this needs to be an '' here instead of undef..
> or am I missing something?
nope, returning undef is better, i'll send a v3
>
>
>> + eval {
>> + $res = $addr =~ m/^$t$/i;
>> + };
>> + warn "invalid regex: $@\n" if $@;
>> + return $res;
>> }
>>
>> sub address {
>> --
>> 2.30.2
>>
>>
>>
>> _______________________________________________
>> pmg-devel mailing list
>> pmg-devel@lists.proxmox.com
>> https://lists.proxmox.com/cgi-bin/mailman/listinfo/pmg-devel
>>
>>
prev parent reply other threads:[~2023-12-18 13:33 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-30 8:27 Dominik Csapak
2023-06-30 8:27 ` [pmg-devel] [PATCH pmg-api v2 2/2] statistics: fix update virusinfo Dominik Csapak
2023-06-30 13:41 ` [pmg-devel] applied: " Stoiko Ivanov
2023-12-15 16:44 ` [pmg-devel] [PATCH pmg-api v2 1/2] fix #4811: rule db: test regex validity on save Stoiko Ivanov
2023-12-15 17:06 ` Stoiko Ivanov
2023-12-18 13:34 ` Dominik Csapak
2023-12-18 13:33 ` Dominik Csapak [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4ad662c1-cd20-42f6-9c51-0fd6fb7b58df@proxmox.com \
--to=d.csapak@proxmox.com \
--cc=pmg-devel@lists.proxmox.com \
--cc=s.ivanov@proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox