5 // TestPacketDataNsec tests generated using fuzz.go and with a message pack
6 // containing the following bytes: 0000\x00\x00000000\x00\x002000000\x0060000\x00\x130000000000000000000"
7 // That bytes sequence created the overflow error and further permutations of that sequence were able to trigger
8 // the other code paths.
9 func TestPackDataNsec(t *testing.T) {
26 8962, 8963, 8970, 8971, 8978, 8979,
27 8986, 8987, 8994, 8995, 9002, 9003,
28 9010, 9011, 9018, 9019, 9026, 9027,
29 9034, 9035, 9042, 9043, 9050, 9051,
33 48, 48, 48, 48, 0, 0, 0,
34 1, 0, 0, 0, 0, 0, 0, 50,
35 48, 48, 48, 48, 48, 48,
36 0, 54, 48, 48, 48, 48,
42 wantErrMsg: "dns: overflow packing nsec",
46 name: "disordered nsec bits",
53 48, 48, 48, 48, 0, 0, 0, 1, 0, 0, 0, 0,
54 0, 0, 50, 48, 48, 48, 48, 48, 48, 0, 54, 48,
55 48, 48, 48, 0, 19, 48, 48, 48, 48, 48, 48, 0,
56 0, 0, 1, 0, 0, 0, 0, 0, 0, 50, 48, 48,
57 48, 48, 48, 48, 0, 54, 48, 48, 48, 48, 0, 19,
58 48, 48, 48, 48, 48, 48, 0, 0, 0, 1, 0, 0,
59 0, 0, 0, 0, 50, 48, 48, 48, 48, 48, 48, 0,
60 54, 48, 48, 48, 48, 0, 19, 48, 48, 48, 48, 48,
61 48, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 50,
62 48, 48, 48, 48, 48, 48, 0, 54, 48, 48, 48, 48,
63 0, 19, 48, 48, 48, 48, 48, 48, 0, 0, 0, 1,
64 0, 0, 0, 0, 0, 0, 50, 48, 48, 48, 48, 48,
65 48, 0, 54, 48, 48, 48, 48, 0, 19, 48, 48,
70 wantErrMsg: "dns: nsec bits out of order",
74 name: "simple message with only one window",
83 48, 48, 48, 0, 54, 48,
84 48, 48, 48, 0, 19, 48, 48,
92 for _, tt := range tests {
93 t.Run(tt.name, func(t *testing.T) {
94 got, err := packDataNsec(tt.args.bitmap, tt.args.msg, tt.args.off)
95 if (err != nil) != tt.wantErr {
96 t.Errorf("packDataNsec() error = %v, wantErr %v", err, tt.wantErr)
99 if err != nil && tt.wantErrMsg != err.Error() {
100 t.Errorf("packDataNsec() error msg = %v, wantErrMsg %v", err.Error(), tt.wantErrMsg)
104 t.Errorf("packDataNsec() = %v, want %v", got, tt.want)
110 func TestUnpackString(t *testing.T) {
111 msg := []byte("\x00abcdef\x0f\\\"ghi\x04mmm\x7f")
112 msg[0] = byte(len(msg) - 1)
114 got, _, err := unpackString(msg, 0)
119 if want := `abcdef\015\\\"ghi\004mmm\127`; want != got {
120 t.Errorf("expected %q, got %q", want, got)
124 func BenchmarkUnpackString(b *testing.B) {
125 msg := []byte("\x00abcdef\x0f\\\"ghi\x04mmm")
126 msg[0] = byte(len(msg) - 1)
128 for n := 0; n < b.N; n++ {
129 got, _, err := unpackString(msg, 0)
134 if want := `abcdef\015\\\"ghi\004mmm`; want != got {
135 b.Errorf("expected %q, got %q", want, got)