Better fuzzing test and NSAP fix

rr can be nil when parsed, if it, for instance only contains a
comment.

NSAP parsing need some parens to make the if-then logic work.
This commit is contained in:
Miek Gieben 2015-08-07 12:17:16 +02:00
parent 1e6d260018
commit 69d043f8ab
2 changed files with 7 additions and 3 deletions

View File

@ -3,11 +3,15 @@ package dns
import "testing"
func TestFuzzString(t *testing.T) {
testcases := []string{"", " MINFO ", " RP ", " NSEC 0 0", " \" NSEC 0 0\"", " \" MINFO \""}
testcases := []string{"", " MINFO ", " RP ", " NSEC 0 0", " \" NSEC 0 0\"", " \" MINFO \"",
";a ", ";a<><61><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>",
" NSAP O ", " NSAP N ",
}
for i, tc := range testcases {
rr, err := NewRR(tc)
if err == nil {
if tc == "" { // special case...
// rr can still be nil because we can (for instance) just parse a comment
if rr == nil {
continue
}
t.Fatalf("parsed mailformed RR %d: %s", i, rr.String)

View File

@ -1635,7 +1635,7 @@ func setNSAP(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) {
if len(s) == 0 {
return rr, nil, c1
}
if len(s[0]) >= 2 && s[0][0:2] == "0x" || s[0][0:2] == "0X" {
if len(s[0]) >= 2 && ( s[0][0:2] == "0x" || s[0][0:2] == "0X" ) {
// although RFC only suggests 0x there is no clarification that X is not allowed
rr.Nsap = strings.Join(s, "")[2:]
} else {