Article View: news.software.nntp
Article #82592Re: Injection-Info questions
From: D. Stussy
Date: Fri, 15 Jan 2010 09:14
Date: Fri, 15 Jan 2010 09:14
92 lines
5409 bytes
5409 bytes
"Steve Crook" <steve@mixmin.net> wrote in message
news:slrnhkv04b.mgt.steve@news.mixmin.net...
> On Tue, 12 Jan 2010 10:47:54 +0000 (UTC), Steve Crook wrote in
> Message-Id: <slrnhkokqq.mgt.steve@news.mixmin.net>:
>
> > Yes, I hadn't considered the presence of a semi-colon in a
> > quoted-string. It's an invalid atom character but for quoted-strings,
> > any printable ASCII is valid, excluding \ and ". I'll need to think
> > about how to handle that one.
>
> After much cogitating, I've decided this is a nightmare to handle with a
> regex. Quote chars can be in Comments, Comment chars in Quotes and '='
> and semi-colons in both of them. It's easier to parse it on a
> char-by-char basis and then validate the resulting strings against atom,
> dot-atom and quoted-text regexs.
>
> Here's a first stab at it:
> http://www.mixmin.net/cleanfeed/injectinfo
> I can still find ways to break this with malformed data but it's much
> easier to fix than the equivalent monster regexs I've tried.
That is a mess. I'm almost sorry I brought the problem up, but I bet that
someone would probably intrroduce it and it's better to head it off before
it happens. Looks as if you dealt with it well, but there's still a few
issues:
1) Comments regarding "nested bracket": A bracket is "[" and "]".
Parentheses are "(" and ")".
- # Decrement the nested bracket count every time we hit a close bracket
+ # Decrement the nested comment count every time we hit a right
parenthesis.
- if ($char eq ")" and not $quote_flag) {
+ if ($char eq ")" and not $quote_flag and $comment_level) {
$comment_level -= 1;
next;
};
You don't want to lower the count if we find ")" BEFORE "(" i.e.
$comment_level should never go negative. ")" is a regular character if NOT
in a comment.
2)
(my $head, my $body) = split(/=/, $string, 2);
through to
} else {
I think this assumes that there will be an "=" in the string. If the
equals-sign is missing, $body should be unset, and although I think your
conditionals do implicitly check for this, we should make certain in
testing. Is it unset, or is it a null string (""). It looks as if both
regexes require at least one character, so my concern is does comparing an
unset to a regex throw an exception when "strict" is in force? If $string
is null, meaning perhaps ";;" (e.g.) appeared in the data, we don't have a
$head either, so we should probably go to the next character. $string is
already empty but $quoted_string needs to be reset (if we had ';"";').
3) What should we do if either $quote_flag or $comment_level is not zero
when we hit the end of the string? Does the syntax error mean we should
throw all the results away - or should we try to process what we have, even
if it may be wrong?
4) Lastly, does the "Injection-Info:" header permit omitting the semicolon
at the end of the string? If so, we could miss the last parameter.
Likewise, if there are NO semi-colons, does this mean we have the injection
server name only?
RFC 5536, Section 3.2.8. (page 20) - Injection-Info:
injection-info = "Injection-Info:" SP [CFWS] path-identity
[CFWS] *( ";" [CFWS] parameter ) [CFWS] CRLF
PERMITS - no semicolon -> "path-identity" (injecting server name) only.
NO TRAILING semicolon. It separates the optional parameters. It does NOT
terminate them.
Therefore, everything inside " if ($char eq ";" and not $quote_flag) {"
needs to be repeated after the end of the data in @chars EXCEPT for the
last two lines that merely reset for the next parsing loop -- OR [easier -
hint] we could cheat by appending a semicolon to the string end before
entering the foreach loop (like in your sample testing string - although a
trailing null parameter is technically illegal).
+ $injection_info =~ s/$/\;/;
foreach my $char (@chars) {
I wasn't certain if the semicolon inside the expression needed to be
backspace-escaped, so I did so anyway. Adding the trailing semicolon fixes
both problems.
Technical Details
Message-ID:
<hipbl6$is9$1@snarked.org>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.nntp.20141118.mbox.gz!border1.nntp.ams.giganews.com!nntp.giganews.com!xlned.com!feeder3.xlned.com!feeder.news-service.com!weretis.net!feeder2.news.weretis.net!news.snarked.org!not-for-mailReferences:
<slrnhjcc9b.u40.steve@news.mixmin.net> <hicoat$fun$1@news.trigofacile.com> <slrnhkm0mt.lhj.steve@news.mixmin.net> <hig5ra$9lr$1@snarked.org> <slrnhkokqq.mgt.steve@news.mixmin.net> <slrnhkv04b.mgt.steve@news.mixmin.net>Show Full Headers
Complete Article Headers
Message-ID: <hipbl6$is9$1@snarked.org> Subject: Re: Injection-Info questions Date: Fri, 15 Jan 2010 01:14:01 -0800 From: "D. Stussy" <spam+newsgroups@bde-arc.ampr.org> References: <slrnhjcc9b.u40.steve@news.mixmin.net> <hicoat$fun$1@news.trigofacile.com> <slrnhkm0mt.lhj.steve@news.mixmin.net> <hig5ra$9lr$1@snarked.org> <slrnhkokqq.mgt.steve@news.mixmin.net> <slrnhkv04b.mgt.steve@news.mixmin.net> Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.nntp.20141118.mbox.gz!border1.nntp.ams.giganews.com!nntp.giganews.com!xlned.com!feeder3.xlned.com!feeder.news-service.com!weretis.net!feeder2.news.weretis.net!news.snarked.org!not-for-mail Newsgroups: news.software.nntp Lines: 92 Reply-To: "D. Stussy" <replies@newsgroups.kd6lvw.ampr.org> NNTP-Posting-Host: pool-71-118-53-20.lsanca.dsl-w.verizon.net X-Trace: snarked.org 1263546854 19337 71.118.53.20 (15 Jan 2010 09:14:14 GMT) X-Complaints-To: newsmaster+complaints@snarked.org NNTP-Posting-Date: Fri, 15 Jan 2010 09:14:14 +0000 (UTC) X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1478 X-MIMEOLE: Produced By Microsoft MimeOLE V6.00.2800.1478