mirror of
https://github.com/mjl-/mox.git
synced 2025-01-13 16:58:49 +03:00
fix two parsing bugs in imapserver
these could cause the parser to reject correct commands. the first bug is about the allowed chars for an "atom", we were accepting too many. this probably isn't easily triggered in practice. the second bug is about how numbers (digits) are parsed. when gathering digits to parse as number, we didn't consider only the directly upcoming digits that make up the number, but continued looking for digits later on in the command. then we tried to parse a string that was too long as a number, which would fail because of additional characters. this could have been triggered with commands containing two numbers. this is possible with e.g. "tag search or larger 123 smaller 123", the "or" takes two search keys again, each with a number. not too common, but can happen. found while writing tests for upcoming condstore/qresync implementation.
This commit is contained in:
parent
4819180de1
commit
142b2498bf
3 changed files with 15 additions and 9 deletions
|
@ -12,12 +12,13 @@ import (
|
|||
)
|
||||
|
||||
var (
|
||||
listWildcards = "%*"
|
||||
char = charRange('\x01', '\x7f')
|
||||
ctl = charRange('\x01', '\x19')
|
||||
atomChar = charRemove(char, "(){ "+listWildcards+ctl)
|
||||
respSpecials = atomChar + "]"
|
||||
astringChar = atomChar + respSpecials
|
||||
listWildcards = "%*"
|
||||
char = charRange('\x01', '\x7f')
|
||||
ctl = charRange('\x01', '\x19')
|
||||
quotedSpecials = `"\`
|
||||
respSpecials = "]"
|
||||
atomChar = charRemove(char, "(){ "+ctl+listWildcards+quotedSpecials+respSpecials)
|
||||
astringChar = atomChar + respSpecials
|
||||
)
|
||||
|
||||
func charRange(first, last rune) string {
|
||||
|
@ -122,7 +123,7 @@ func (p *parser) take(s string) bool {
|
|||
|
||||
func (p *parser) xtake(s string) {
|
||||
if !p.take(s) {
|
||||
p.xerrorf("expected %q", s)
|
||||
p.xerrorf("expected %s", s)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -201,9 +202,10 @@ func (p *parser) xspace() {
|
|||
func (p *parser) digits() string {
|
||||
var n int
|
||||
for _, c := range p.upper[p.o:] {
|
||||
if c >= '0' && c <= '9' {
|
||||
n++
|
||||
if c < '0' || c > '9' {
|
||||
break
|
||||
}
|
||||
n++
|
||||
}
|
||||
if n == 0 {
|
||||
return ""
|
||||
|
|
|
@ -212,6 +212,9 @@ func TestSearch(t *testing.T) {
|
|||
tc.transactf("ok", `search uid 5`)
|
||||
tc.xsearch(1)
|
||||
|
||||
tc.transactf("ok", `search or larger 1000000 smaller 1`)
|
||||
tc.xsearch()
|
||||
|
||||
tc.transactf("ok", `search undraft`)
|
||||
tc.xsearch(1, 2)
|
||||
|
||||
|
|
|
@ -191,6 +191,7 @@ func (tc *testconn) xcodeArg(v any) {
|
|||
}
|
||||
|
||||
func (tc *testconn) xuntagged(exps ...any) {
|
||||
tc.t.Helper()
|
||||
tc.xuntaggedCheck(true, exps...)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue