nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: miekg/dns
Pull request #1212 (2021-01-30 05:17:33)

Fix potentially truncated int casts in $GENERATE code
These were flagged by GitHub CodeQL code scanning as potential vulnerabilities or issues. Fixing them is easy and they are incorrect. The triggered rule is `go/incorrect-integer-conversion`.

Adding tests is less easy because int is 64-bits on most systems, including those we test on, so we can't consistently provoke a failure here.


Patch:
diff --git a/generate.go b/generate.go
index f713074a..ac8df34d 100644
--- a/generate.go
+++ b/generate.go
@@ -75,10 +75,10 @@ func (zp *ZoneParser) generate(l lex) (RR, bool) {
 	r := &generateReader{
 		s: s,
 
-		cur:   int(start),
-		start: int(start),
-		end:   int(end),
-		step:  int(step),
+		cur:   start,
+		start: start,
+		end:   end,
+		step:  step,
 
 		file: zp.file,
 		lex:  &l,
@@ -94,10 +94,10 @@ type generateReader struct {
 	s  string
 	si int
 
-	cur   int
-	start int
-	end   int
-	step  int
+	cur   int64
+	start int64
+	end   int64
+	step  int64
 
 	mod bytes.Buffer
 
@@ -173,7 +173,7 @@ func (r *generateReader) ReadByte() (byte, error) {
 			return '$', nil
 		}
 
-		var offset int
+		var offset int64
 
 		// Search for { and }
 		if r.s[si+1] == '{' {
@@ -188,7 +188,7 @@ func (r *generateReader) ReadByte() (byte, error) {
 			if errMsg != "" {
 				return 0, r.parseError(errMsg, si+3+sep)
 			}
-			if r.start+offset < 0 || int64(r.end) + int64(offset) > 1<<31-1 {
+			if r.start+offset < 0 || r.end+offset > 1<<31-1 {
 				return 0, r.parseError("bad offset in $GENERATE", si+3+sep)
 			}
 
@@ -208,7 +208,7 @@ func (r *generateReader) ReadByte() (byte, error) {
 }
 
 // Convert a $GENERATE modifier 0,0,d to something Printf can deal with.
-func modToPrintf(s string) (string, int, string) {
+func modToPrintf(s string) (string, int64, string) {
 	// Modifier is { offset [ ,width [ ,base ] ] } - provide default
 	// values for optional width and type, if necessary.
 	var offStr, widthStr, base string
@@ -240,8 +240,8 @@ func modToPrintf(s string) (string, int, string) {
 	}
 
 	if width == 0 {
-		return "%" + base, int(offset), ""
+		return "%" + base, offset, ""
 	}
 
-	return "%0" + widthStr + base, int(offset), ""
+	return "%0" + widthStr + base, offset, ""
 }


Test patch:
diff --git a/generate_test.go b/generate_test.go
index cd161c1f..f0feb86a 100644
--- a/generate_test.go
+++ b/generate_test.go
@@ -162,7 +162,7 @@ func TestGenerateModToPrintf(t *testing.T) {
 	tests := []struct {
 		mod        string
 		wantFmt    string
-		wantOffset int
+		wantOffset int64
 		wantErr    bool
 	}{
 		{"0,0,d", "%d", 0, false},
Repository: miekg/dns
Pull request #1234 (2021-03-01 13:09:49)

loc: use float64 to get enough precision
Fixes: #1232

Signed-off-by: Miek Gieben <miek@miek.nl>



Patch:
diff --git a/scan_rr.go b/scan_rr.go
index a19ba4ae..05765aed 100644
--- a/scan_rr.go
+++ b/scan_rr.go
@@ -609,7 +609,7 @@ func (rr *LOC) parse(c *zlexer, o string) *ParseError {
 
 	c.Next() // zBlank
 	l, _ = c.Next()
-	if i, err := strconv.ParseFloat(l.token, 32); err != nil || l.err || i < 0 || i >= 60 {
+	if i, err := strconv.ParseFloat(l.token, 64); err != nil || l.err || i < 0 || i >= 60 {
 		return &ParseError{"", "bad LOC Latitude seconds", l}
 	} else {
 		rr.Latitude += uint32(1000 * i)
@@ -645,7 +645,7 @@ East:
 	}
 	c.Next() // zBlank
 	l, _ = c.Next()
-	if i, err := strconv.ParseFloat(l.token, 32); err != nil || l.err || i < 0 || i >= 60 {
+	if i, err := strconv.ParseFloat(l.token, 64); err != nil || l.err || i < 0 || i >= 60 {
 		return &ParseError{"", "bad LOC Longitude seconds", l}
 	} else {
 		rr.Longitude += uint32(1000 * i)
@@ -864,7 +864,7 @@ func (rr *ZONEMD) parse(c *zlexer, o string) *ParseError {
 
 	c.Next() // zBlank
 	l, _ = c.Next()
-	i, err := strconv.ParseUint(l.token, 10, 8); 
+	i, err := strconv.ParseUint(l.token, 10, 8)
 	if err != nil || l.err {
 		return &ParseError{"", "bad ZONEMD Hash Algorithm", l}
 	}


Test patch:
diff --git a/parse_test.go b/parse_test.go
index 1d5bf6f9..6c55a74a 100644
--- a/parse_test.go
+++ b/parse_test.go
@@ -378,6 +378,8 @@ func TestParseLOC(t *testing.T) {
 		// Exercise boundary cases
 		"SW1A2AA.find.me.uk.	LOC	90 0 0.0 N 180 0 0.0 W 42849672.95 90000000.00m 90000000.00m 90000000.00m": "SW1A2AA.find.me.uk.\t3600\tIN\tLOC\t90 00 0.000 N 180 00 0.000 W 42849672.95m 90000000m 90000000m 90000000m",
 		"SW1A2AA.find.me.uk.	LOC	89 59 59.999 N 179 59 59.999 W -100000 90000000.00m 90000000.00m 90000000m": "SW1A2AA.find.me.uk.\t3600\tIN\tLOC\t89 59 59.999 N 179 59 59.999 W -100000m 90000000m 90000000m 90000000m",
+		// use float64 to have enough precision.
+		"example.com. LOC 42 21 43.952 N 71 5 6.344 W -24m 1m 200m 10m": "example.com.\t3600\tIN\tLOC\t42 21 43.952 N 71 05 6.344 W -24m 1m 200m 10m",
 	}
 	for i, o := range lt {
 		rr, err := NewRR(i)
Repository: miekg/dns
Pull request #1280 (2021-07-13 10:12:03)

fix Msg.Used TTL must be zero
Prerequisite Section RRset Exist Value Dependent TTL must be zero.

```
   2.4.2 - RRset Exists (Value Dependent)

   A set of RRs with a specified NAME and TYPE exists and has the same
   members with the same RDATAs as the RRset specified here in this
   section.  While RRset ordering is undefined and therefore not
   significant to this comparison, the sets be identical in their
   extent.

   For this prerequisite, a requestor adds to the section an entire
   RRset whose preexistence is required.  NAME and TYPE are that of the
   RRset being denoted.  CLASS is that of the zone.  TTL must be
   specified as zero (0) and is ignored when comparing RRsets for
   identity.
``


Patch:
diff --git a/update.go b/update.go
index 69dd3865..16f9ee85 100644
--- a/update.go
+++ b/update.go
@@ -32,7 +32,9 @@ func (u *Msg) Used(rr []RR) {
 		u.Answer = make([]RR, 0, len(rr))
 	}
 	for _, r := range rr {
-		r.Header().Class = u.Question[0].Qclass
+		hdr := r.Header()
+		hdr.Class = u.Question[0].Qclass
+		hdr.Ttl = 0
 		u.Answer = append(u.Answer, r)
 	}
 }


Test patch:
diff --git a/update_test.go b/update_test.go
index 380376c9..5522ddb6 100644
--- a/update_test.go
+++ b/update_test.go
@@ -135,7 +135,7 @@ func TestPreReqAndRemovals(t *testing.T) {
 name_used.	0	CLASS255	ANY	
 name_not_used.	0	NONE	ANY	
 rrset_used1.	0	CLASS255	A	
-rrset_used2.	3600	IN	A	127.0.0.1
+rrset_used2.	0	IN	A	127.0.0.1
 rrset_not_used.	0	NONE	A	
 
 ;; AUTHORITY SECTION:
Repository: miekg/dns
Pull request #1376 (2022-05-24 18:57:01)

Disallow names that start with '.' in IsDomainName()
We noticed that `IsDomainName()` was allowing names that start with at `.`. This is an error, which this PR fixes.

tmthrgd: 	// XXX: The logic in this function was copied from packDomainName and
	// should be kept in sync with that function.
	
^See the comment at the start of the function. 
shane-kerr: > ```
> // XXX: The logic in this function was copied from packDomainName and
> // should be kept in sync with that function.
> ```
> 
> ^See the comment at the start of the function.

Ah, okay. I've updated `packDomainName()`. I didn't see any relevant tests in `msg_test.go` and I also didn't add any. Hopefully that is okay.
miekg: thanks both, comment is acted upon. merging

Patch:
diff --git a/defaults.go b/defaults.go
index d47b0b1f..f2cdbf43 100644
--- a/defaults.go
+++ b/defaults.go
@@ -218,6 +218,11 @@ func IsDomainName(s string) (labels int, ok bool) {
 
 			wasDot = false
 		case '.':
+			if i == 0 && len(s) > 1 {
+				// leading dots are not legal except for the root zone
+				return labels, false
+			}
+
 			if wasDot {
 				// two dots back to back is not legal
 				return labels, false
diff --git a/msg.go b/msg.go
index 60a2e8c3..89ebb64a 100644
--- a/msg.go
+++ b/msg.go
@@ -265,6 +265,11 @@ loop:
 
 			wasDot = false
 		case '.':
+			if i == 0 && len(s) > 1 {
+				// leading dots are not legal except for the root zone
+				return len(msg), ErrRdata
+			}
+
 			if wasDot {
 				// two dots back to back is not legal
 				return len(msg), ErrRdata


Test patch:
diff --git a/labels_test.go b/labels_test.go
index 3e672fec..dbe9a229 100644
--- a/labels_test.go
+++ b/labels_test.go
@@ -176,7 +176,10 @@ func TestIsDomainName(t *testing.T) {
 		lab int
 	}
 	names := map[string]*ret{
-		"..":                     {false, 1},
+		".":                      {true, 1},
+		"..":                     {false, 0},
+		"double-dot..test":       {false, 1},
+		".leading-dot.test":      {false, 0},
 		"@.":                     {true, 1},
 		"www.example.com":        {true, 3},
 		"www.e%ample.com":        {true, 3},
Repository: miekg/dns
Pull request #1378 (2022-06-08 11:48:41)

Add back support for *net.UnixCon with seqpacket type
This was broken by PR: https://github.com/miekg/dns/pull/1322


Patch:
diff --git a/client.go b/client.go
index 31bf5759..fde5b5e3 100644
--- a/client.go
+++ b/client.go
@@ -24,7 +24,7 @@ func isPacketConn(c net.Conn) bool {
 	}
 
 	if ua, ok := c.LocalAddr().(*net.UnixAddr); ok {
-		return ua.Net == "unixgram"
+		return ua.Net == "unixgram" || ua.Net == "unixpacket"
 	}
 
 	return true


Test patch:
diff --git a/client_test.go b/client_test.go
index 83d5af70..ff0c2187 100644
--- a/client_test.go
+++ b/client_test.go
@@ -68,6 +68,27 @@ func TestIsPacketConn(t *testing.T) {
 		t.Error("Unix datagram connection (wrapped type) should be a packet conn")
 	}
 
+	// Unix Seqpacket
+	shutChan, addrstr, err := RunLocalUnixSeqPacketServer(filepath.Join(t.TempDir(), "unixpacket.sock"))
+	if err != nil {
+		t.Fatalf("unable to run test server: %v", err)
+	}
+
+	defer func() {
+		shutChan <- &struct{}{}
+	}()
+	c, err = net.Dial("unixpacket", addrstr)
+	if err != nil {
+		t.Fatalf("failed to dial: %v", err)
+	}
+	defer c.Close()
+	if !isPacketConn(c) {
+		t.Error("Unix datagram connection should be a packet conn")
+	}
+	if !isPacketConn(struct{ *net.UnixConn }{c.(*net.UnixConn)}) {
+		t.Error("Unix datagram connection (wrapped type) should be a packet conn")
+	}
+
 	// Unix stream
 	s, addrstr, _, err = RunLocalUnixServer(filepath.Join(t.TempDir(), "unixstream.sock"))
 	if err != nil {
diff --git a/server_test.go b/server_test.go
index 85da176d..aaaca704 100644
--- a/server_test.go
+++ b/server_test.go
@@ -159,6 +159,21 @@ func RunLocalUnixGramServer(laddr string, opts ...func(*Server)) (*Server, strin
 	return RunLocalServer(pc, nil, opts...)
 }
 
+func RunLocalUnixSeqPacketServer(laddr string) (chan interface{}, string, error) {
+	pc, err := net.Listen("unixpacket", laddr)
+	if err != nil {
+		return nil, "", err
+	}
+
+	shutdownChan := make(chan interface{})
+	go func() {
+		pc.Accept()
+		<-shutdownChan
+	}()
+
+	return shutdownChan, pc.Addr().String(), nil
+}
+
 func TestServing(t *testing.T) {
 	for _, tc := range []struct {
 		name      string
Repository: miekg/dns
Pull request #1439 (2023-03-15 22:18:37)

Update readme
Once again, thank you for this project. Some housekeeping... replaces the dns-over-websocket experiment link with a more useful link pointing to a collection of free tools/services all making use of this library.


Patch:
diff --git a/README.md b/README.md
index ec954039..06bea9fa 100644
--- a/README.md
+++ b/README.md
@@ -78,7 +78,7 @@ A not-so-up-to-date-list-that-may-be-actually-current:
 * https://fleetdeck.io/
 * https://github.com/markdingo/autoreverse
 * https://github.com/slackhq/nebula
-* https://github.com/dnschecktool/dow-proxy
+* https://addr.tools/
 * https://dnscheck.tools/
 * https://github.com/egbakou/domainverifier
 
diff --git a/types.go b/types.go
index 1c7dc097..03afeccd 100644
--- a/types.go
+++ b/types.go
@@ -198,7 +198,7 @@ const (
 	_CD = 1 << 4  // checking disabled
 )
 
-// Various constants used in the LOC RR. See RFC 1887.
+// Various constants used in the LOC RR. See RFC 1876.
 const (
 	LOC_EQUATOR       = 1 << 31 // RFC 1876, Section 2.
 	LOC_PRIMEMERIDIAN = 1 << 31 // RFC 1876, Section 2.
@@ -792,7 +792,10 @@ type LOC struct {
 
 // cmToM takes a cm value expressed in RFC 1876 SIZE mantissa/exponent
 // format and returns a string in m (two decimals for the cm).
-func cmToM(m, e uint8) string {
+func cmToM(x uint8) string {
+	m := x & 0xf0 >> 4
+	e := x & 0x0f
+
 	if e < 2 {
 		if e == 1 {
 			m *= 10
@@ -848,10 +851,9 @@ func (rr *LOC) String() string {
 		s += fmt.Sprintf("%.0fm ", alt)
 	}
 
-	s += cmToM(rr.Size&0xf0>>4, rr.Size&0x0f) + "m "
-	s += cmToM(rr.HorizPre&0xf0>>4, rr.HorizPre&0x0f) + "m "
-	s += cmToM(rr.VertPre&0xf0>>4, rr.VertPre&0x0f) + "m"
-
+	s += cmToM(rr.Size) + "m "
+	s += cmToM(rr.HorizPre) + "m "
+	s += cmToM(rr.VertPre) + "m"
 	return s
 }
 


Test patch:
diff --git a/types_test.go b/types_test.go
index b3f5583f..32df35bf 100644
--- a/types_test.go
+++ b/types_test.go
@@ -5,37 +5,37 @@ import (
 )
 
 func TestCmToM(t *testing.T) {
-	s := cmToM(0, 0)
+	s := cmToM((0 << 4) + 0)
 	if s != "0.00" {
 		t.Error("0, 0")
 	}
 
-	s = cmToM(1, 0)
+	s = cmToM((1 << 4) + 0)
 	if s != "0.01" {
 		t.Error("1, 0")
 	}
 
-	s = cmToM(3, 1)
+	s = cmToM((3 << 4) + 1)
 	if s != "0.30" {
 		t.Error("3, 1")
 	}
 
-	s = cmToM(4, 2)
+	s = cmToM((4 << 4) + 2)
 	if s != "4" {
 		t.Error("4, 2")
 	}
 
-	s = cmToM(5, 3)
+	s = cmToM((5 << 4) + 3)
 	if s != "50" {
 		t.Error("5, 3")
 	}
 
-	s = cmToM(7, 5)
+	s = cmToM((7 << 4) + 5)
 	if s != "7000" {
 		t.Error("7, 5")
 	}
 
-	s = cmToM(9, 9)
+	s = cmToM((9 << 4) + 9)
 	if s != "90000000" {
 		t.Error("9, 9")
 	}
Repository: miekg/dns
Pull request #1440 (2023-03-15 22:32:29)

Updates to LOC type RFC1876
https://www.rfc-editor.org/rfc/rfc1876


Patch:
diff --git a/types.go b/types.go
index 1c7dc097..03afeccd 100644
--- a/types.go
+++ b/types.go
@@ -198,7 +198,7 @@ const (
 	_CD = 1 << 4  // checking disabled
 )
 
-// Various constants used in the LOC RR. See RFC 1887.
+// Various constants used in the LOC RR. See RFC 1876.
 const (
 	LOC_EQUATOR       = 1 << 31 // RFC 1876, Section 2.
 	LOC_PRIMEMERIDIAN = 1 << 31 // RFC 1876, Section 2.
@@ -792,7 +792,10 @@ type LOC struct {
 
 // cmToM takes a cm value expressed in RFC 1876 SIZE mantissa/exponent
 // format and returns a string in m (two decimals for the cm).
-func cmToM(m, e uint8) string {
+func cmToM(x uint8) string {
+	m := x & 0xf0 >> 4
+	e := x & 0x0f
+
 	if e < 2 {
 		if e == 1 {
 			m *= 10
@@ -848,10 +851,9 @@ func (rr *LOC) String() string {
 		s += fmt.Sprintf("%.0fm ", alt)
 	}
 
-	s += cmToM(rr.Size&0xf0>>4, rr.Size&0x0f) + "m "
-	s += cmToM(rr.HorizPre&0xf0>>4, rr.HorizPre&0x0f) + "m "
-	s += cmToM(rr.VertPre&0xf0>>4, rr.VertPre&0x0f) + "m"
-
+	s += cmToM(rr.Size) + "m "
+	s += cmToM(rr.HorizPre) + "m "
+	s += cmToM(rr.VertPre) + "m"
 	return s
 }
 


Test patch:
diff --git a/types_test.go b/types_test.go
index b3f5583f..32df35bf 100644
--- a/types_test.go
+++ b/types_test.go
@@ -5,37 +5,37 @@ import (
 )
 
 func TestCmToM(t *testing.T) {
-	s := cmToM(0, 0)
+	s := cmToM((0 << 4) + 0)
 	if s != "0.00" {
 		t.Error("0, 0")
 	}
 
-	s = cmToM(1, 0)
+	s = cmToM((1 << 4) + 0)
 	if s != "0.01" {
 		t.Error("1, 0")
 	}
 
-	s = cmToM(3, 1)
+	s = cmToM((3 << 4) + 1)
 	if s != "0.30" {
 		t.Error("3, 1")
 	}
 
-	s = cmToM(4, 2)
+	s = cmToM((4 << 4) + 2)
 	if s != "4" {
 		t.Error("4, 2")
 	}
 
-	s = cmToM(5, 3)
+	s = cmToM((5 << 4) + 3)
 	if s != "50" {
 		t.Error("5, 3")
 	}
 
-	s = cmToM(7, 5)
+	s = cmToM((7 << 4) + 5)
 	if s != "7000" {
 		t.Error("7, 5")
 	}
 
-	s = cmToM(9, 9)
+	s = cmToM((9 << 4) + 9)
 	if s != "90000000" {
 		t.Error("9, 9")
 	}
Repository: miekg/dns
Pull request #1456 (2023-04-27 17:57:21)

Allow RRSIG algorithm mnemonics
Java outputs these *and* the RFC says we should parse them, so parse
them. We'll never output them though. Throwback to the "be lenient to
what you accept, but strict with what you output". Anyhow the diff is
tiny and it helps interop.

Fixes: #1447

Signed-off-by: Miek Gieben <miek@miek.nl>



Patch:
diff --git a/scan_rr.go b/scan_rr.go
index 2d44a398..d08c8e6a 100644
--- a/scan_rr.go
+++ b/scan_rr.go
@@ -904,11 +904,18 @@ func (rr *RRSIG) parse(c *zlexer, o string) *ParseError {
 
 	c.Next() // zBlank
 	l, _ = c.Next()
-	i, e := strconv.ParseUint(l.token, 10, 8)
-	if e != nil || l.err {
+	if l.err {
 		return &ParseError{"", "bad RRSIG Algorithm", l}
 	}
-	rr.Algorithm = uint8(i)
+	i, e := strconv.ParseUint(l.token, 10, 8)
+	rr.Algorithm = uint8(i) // if 0 we'll check the mnemonic in the if
+	if e != nil {
+		v, ok := StringToAlgorithm[l.token]
+		if !ok {
+			return &ParseError{"", "bad RRSIG Algorithm", l}
+		}
+		rr.Algorithm = v
+	}
 
 	c.Next() // zBlank
 	l, _ = c.Next()


Test patch:
diff --git a/parse_test.go b/parse_test.go
index 6ea85495..364e7be4 100644
--- a/parse_test.go
+++ b/parse_test.go
@@ -1975,3 +1975,26 @@ func TestParseOPENPGPKEY(t *testing.T) {
 		}
 	}
 }
+
+func TestParseRRSIGAlgNames(t *testing.T) {
+	tests := map[string]uint8{
+		`miek.nl.  IN RRSIG SOA RSASHA1 2 43200 20140210031301 20140111031301 12051 miek.nl. MVZUyrYwq0iZhMFDDnVXD2Bvu7pcBoc=`:         RSASHA1,
+		`miek.nl.  IN RRSIG SOA RSAMD5 2 43200 20140210031301 20140111031301 12051 miek.nl. MVZUyrYwq0iZhMFDDnVXD2Bvu7pcBoc=`:          RSAMD5,
+		`miek.nl.  IN RRSIG SOA ECC-GOST 2 43200 20140210031301 20140111031301 12051 miek.nl. MVZUyrYwq0iZhMFDDnVXD2Bvu7pcBoc=`:        ECCGOST,
+		`miek.nl.  IN RRSIG SOA ED448 2 43200 20140210031301 20140111031301 12051 miek.nl. MVZUyrYwq0iZhMFDDnVXD2Bvu7pcBoc=`:           ED448,
+		`miek.nl.  IN RRSIG SOA ECDSAP256SHA256 2 43200 20140210031301 20140111031301 12051 miek.nl. MVZUyrYwq0iZhMFDDnVXD2Bvu7pcBoc=`: ECDSAP256SHA256,
+		`miek.nl.  IN RRSIG SOA INDIRECT 2 43200 20140210031301 20140111031301 12051 miek.nl. MVZUyrYwq0iZhMFDDnVXD2Bvu7pcBoc=`:        INDIRECT,
+		`miek.nl.  IN RRSIG SOA BLA 2 43200 20140210031301 20140111031301 12051 miek.nl. MVZUyrYwq0iZhMFDDnVXD2Bvu7pcBoc=`:             0,
+		`miek.nl.  IN RRSIG SOA - 2 43200 20140210031301 20140111031301 12051 miek.nl. MVZUyrYwq0iZhMFDDnVXD2Bvu7pcBoc=`:               0,
+	}
+	for r, alg := range tests {
+		rr, err := NewRR(r)
+		if alg != 0 && err != nil {
+			t.Error(err)
+			continue
+		}
+		if alg != 0 && rr.(*RRSIG).Algorithm != alg {
+			t.Errorf("expecting alg %d, got %d", alg, rr.(*RRSIG).Algorithm)
+		}
+	}
+}