nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: scionproto/scion
Pull request #4377 (2023-08-16 09:41:59)

slayers: unmap IPv4-mapped IPv6 addresses
The Go standard library can produce IPv4-mapped IPv6 addresses when resolving IP addresses. These IP addresses need to be unmapped before putting them on the wire.

Before this patch, we could observe the following with tshark:

    Len=1304 SCION 1-ff00:0:110,[::ffff:172.20.2.2] -> 1-ff00:0:111,[::ffff:172.20.3.2] UDP 32769 -> 32768 1208

The regression was introduced in #4346, which removed the unmapping behavior in slayers.PackAddr. This patch restores the behavior to ensure only unmapped IPv4 addresses make it on the wire.

<!-- Reviewable:start -->
- - -
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/scionproto/scion/4377)
<!-- Reviewable:end -->



Patch:
diff --git a/pkg/slayers/scion.go b/pkg/slayers/scion.go
index 7e24772f1..66ff20c75 100644
--- a/pkg/slayers/scion.go
+++ b/pkg/slayers/scion.go
@@ -394,15 +394,16 @@ func ParseAddr(addrType AddrType, raw []byte) (addr.Host, error) {
 func PackAddr(host addr.Host) (AddrType, []byte, error) {
 	switch host.Type() {
 	case addr.HostTypeIP:
-		ip := host.IP()
+		// The IP is potentially IPv4-in-IPv6. We need to unmap it to ensure
+		// we only have true IPv4 or IPv6 addresses.
+		ip := host.IP().Unmap()
 		if !ip.IsValid() {
 			break
 		}
-		t := T4Ip
 		if ip.Is6() {
-			t = T16Ip
+			return T16Ip, ip.AsSlice(), nil
 		}
-		return t, ip.AsSlice(), nil
+		return T4Ip, ip.AsSlice(), nil
 	case addr.HostTypeSVC:
 		raw := make([]byte, 4)
 		binary.BigEndian.PutUint16(raw, uint16(host.SVC()))


Test patch:
diff --git a/pkg/slayers/scion_test.go b/pkg/slayers/scion_test.go
index 06d496755..a79458761 100644
--- a/pkg/slayers/scion_test.go
+++ b/pkg/slayers/scion_test.go
@@ -33,10 +33,11 @@ import (
 )
 
 var (
-	ip6Addr = addr.MustParseHost("2001:db8::68")
-	ip4Addr = addr.MustParseHost("10.0.0.100")
-	svcAddr = addr.MustParseHost("Wildcard")
-	rawPath = func() []byte {
+	ip6Addr    = addr.MustParseHost("2001:db8::68")
+	ip4Addr    = addr.MustParseHost("10.0.0.100")
+	ip4in6Addr = addr.MustParseHost("::ffff:10.0.0.100")
+	svcAddr    = addr.MustParseHost("Wildcard")
+	rawPath    = func() []byte {
 		return []byte("\x00\x00\x20\x80\x00\x00\x01\x11\x00\x00\x01\x00\x01\x00\x02\x22\x00" +
 			"\x00\x01\x00\x00\x3f\x00\x01\x00\x00\x01\x02\x03\x04\x05\x06\x00\x3f\x00\x03\x00" +
 			"\x02\x01\x02\x03\x04\x05\x06\x00\x3f\x00\x00\x00\x02\x01\x02\x03\x04\x05\x06\x00" +
@@ -311,6 +312,12 @@ func TestPackAddr(t *testing.T) {
 			rawAddr:   ip4Addr.IP().AsSlice(),
 			errorFunc: assert.NoError,
 		},
+		"pack IPv4-mapped IPv6": {
+			addr:      ip4in6Addr,
+			addrType:  slayers.T4Ip,
+			rawAddr:   []byte{0xa, 0x0, 0x0, 0x64},
+			errorFunc: assert.NoError,
+		},
 		"pack IPv6": {
 			addr:      ip6Addr,
 			addrType:  slayers.T16Ip,
Repository: scionproto/scion
Pull request #4648 (2024-10-30 10:39:23)

pkg/snet: format UDPAddr to comply with net.SplitHostPort
Change the snet.UDPAddr.String() method to return the address in a format that is compatible with net.SplitHostPort. This will allow non SCION aware applications to extract the host and port part without the need to understand it is a SCION address.

jiceatscion: 

<!-- Reviewable:start -->
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/scionproto/scion/4648)
<!-- Reviewable:end -->

jiceatscion: No objection, but... does SplitHostPort understand something like [**1-ff00:0:320,**2001::1%some-zone]:20000 anyway?


Patch:
diff --git a/pkg/snet/udpaddr.go b/pkg/snet/udpaddr.go
index 5987cf1ac..e1b74df22 100644
--- a/pkg/snet/udpaddr.go
+++ b/pkg/snet/udpaddr.go
@@ -15,10 +15,10 @@
 package snet
 
 import (
-	"fmt"
 	"net"
 	"net/netip"
 	"regexp"
+	"strconv"
 	"strings"
 
 	"github.com/scionproto/scion/pkg/addr"
@@ -117,7 +117,15 @@ func (a *UDPAddr) Network() string {
 
 // String implements net.Addr interface.
 func (a *UDPAddr) String() string {
-	return fmt.Sprintf("%v,%s", a.IA, a.Host.String())
+	host, port, suffix := "<nil>", "0", ""
+	if a.Host != nil {
+		host = a.Host.IP.String()
+		port = strconv.Itoa(a.Host.Port)
+		if a.Host.Zone != "" {
+			suffix = "%" + a.Host.Zone
+		}
+	}
+	return net.JoinHostPort(a.IA.String()+","+host+suffix, port)
 }
 
 // GetPath returns a path with attached metadata.


Test patch:
diff --git a/pkg/snet/udpaddr_test.go b/pkg/snet/udpaddr_test.go
index 490fba601..c93bd68fb 100644
--- a/pkg/snet/udpaddr_test.go
+++ b/pkg/snet/udpaddr_test.go
@@ -37,32 +37,32 @@ func TestUDPAddrString(t *testing.T) {
 	}{
 		"empty": {
 			input: &snet.UDPAddr{},
-			want:  "0-0,<nil>",
+			want:  "0-0,<nil>:0",
 		},
 		"empty host": {
 			input: &snet.UDPAddr{Host: &net.UDPAddr{}},
-			want:  "0-0,:0",
+			want:  "0-0,<nil>:0",
 		},
 		"ipv4": {
 			input: &snet.UDPAddr{
 				IA:   addr.MustParseIA("1-ff00:0:320"),
 				Host: &net.UDPAddr{IP: net.IPv4(1, 2, 3, 4), Port: 10000},
 			},
-			want: "1-ff00:0:320,1.2.3.4:10000",
+			want: "[1-ff00:0:320,1.2.3.4]:10000",
 		},
 		"ipv6": {
 			input: &snet.UDPAddr{
 				IA:   addr.MustParseIA("1-ff00:0:320"),
 				Host: &net.UDPAddr{IP: net.ParseIP("2001::1"), Port: 20000},
 			},
-			want: "1-ff00:0:320,[2001::1]:20000",
+			want: "[1-ff00:0:320,2001::1]:20000",
 		},
 		"ipv6-zone": {
 			input: &snet.UDPAddr{
 				IA:   addr.MustParseIA("1-ff00:0:320"),
 				Host: &net.UDPAddr{IP: net.ParseIP("2001::1"), Port: 20000, Zone: "some-zone"},
 			},
-			want: "1-ff00:0:320,[2001::1%some-zone]:20000",
+			want: "[1-ff00:0:320,2001::1%some-zone]:20000",
 		},
 	}
 	for n, tc := range tests {
Repository: clap-rs/clap
Pull request #4459 (2022-11-07 12:08:45)

fix(derive): Allow defaulted value parser for '()' fields
Inspired by #4458

This is a compatible change because it turns a compiler error into a working case.

<!--
Thanks for helping out!

Please link the appropriate issue from your PR.

If you don't have an issue, we'd recommend starting with one first so the PR can focus on the
implementation (unless its an obvious bug or documentation fix that will have
little conversation).
-->



Patch:
diff --git a/clap_derive/src/derives/args.rs b/clap_derive/src/derives/args.rs
index 15f676be..ad2a6463 100644
--- a/clap_derive/src/derives/args.rs
+++ b/clap_derive/src/derives/args.rs
@@ -233,9 +233,9 @@ pub fn gen_augment(
 
                 let implicit_methods = match **ty {
                     Ty::Unit => {
+                        // Leaving out `value_parser` as it will always fail
                         quote_spanned! { ty.span()=>
                             .value_name(#value_name)
-                            #value_parser
                             #action
                         }
                     }


Test patch:
diff --git a/tests/derive/flags.rs b/tests/derive/flags.rs
index 63fb216a..12eb7d51 100644
--- a/tests/derive/flags.rs
+++ b/tests/derive/flags.rs
@@ -281,3 +281,54 @@ fn override_implicit_from_flag_positional() {
         Opt::try_parse_from(&["test", "true"]).unwrap()
     );
 }
+
+#[test]
+fn unit_for_negation() {
+    #[derive(Parser, PartialEq, Eq, Debug)]
+    struct Opt {
+        #[arg(long)]
+        arg: bool,
+        #[arg(long, action = ArgAction::SetTrue, overrides_with = "arg")]
+        no_arg: (),
+    }
+
+    assert_eq!(
+        Opt {
+            arg: false,
+            no_arg: ()
+        },
+        Opt::try_parse_from(&["test"]).unwrap()
+    );
+
+    assert_eq!(
+        Opt {
+            arg: true,
+            no_arg: ()
+        },
+        Opt::try_parse_from(&["test", "--arg"]).unwrap()
+    );
+
+    assert_eq!(
+        Opt {
+            arg: false,
+            no_arg: ()
+        },
+        Opt::try_parse_from(&["test", "--no-arg"]).unwrap()
+    );
+
+    assert_eq!(
+        Opt {
+            arg: true,
+            no_arg: ()
+        },
+        Opt::try_parse_from(&["test", "--no-arg", "--arg"]).unwrap()
+    );
+
+    assert_eq!(
+        Opt {
+            arg: false,
+            no_arg: ()
+        },
+        Opt::try_parse_from(&["test", "--arg", "--no-arg"]).unwrap()
+    );
+}
Repository: clap-rs/clap
Pull request #4463 (2022-11-07 16:37:30)

fix(help): Update auto-next-line to use new padding
In clap v4, we changed the padding from 4 to 2 but we didn't update our
calculation for when to switch to next-line-help as it was a magic
number (we tried to catch all of these).

When updating the tests, we also missed that a test was being wrapped
too narrowly

This was found while discussing #3300


Patch:
diff --git a/src/output/help_template.rs b/src/output/help_template.rs
index 078a9a9b..3cf693fa 100644
--- a/src/output/help_template.rs
+++ b/src/output/help_template.rs
@@ -689,7 +689,11 @@ impl<'cmd, 'writer> HelpTemplate<'cmd, 'writer> {
             // force_next_line
             let h = arg.get_help().unwrap_or_default();
             let h_w = h.display_width() + display_width(spec_vals);
-            let taken = longest + 12;
+            let taken = if arg.is_positional() {
+                longest + TAB_WIDTH * 2
+            } else {
+                longest + TAB_WIDTH * 2 + 4 // See `fn short` for the 4
+            };
             self.term_w >= taken
                 && (taken as f32 / self.term_w as f32) > 0.40
                 && h_w > (self.term_w - taken)
@@ -925,7 +929,7 @@ impl<'cmd, 'writer> HelpTemplate<'cmd, 'writer> {
             // force_next_line
             let h = cmd.get_about().unwrap_or_default();
             let h_w = h.display_width() + display_width(spec_vals);
-            let taken = longest + 12;
+            let taken = longest + TAB_WIDTH * 2;
             self.term_w >= taken
                 && (taken as f32 / self.term_w as f32) > 0.40
                 && h_w > (self.term_w - taken)
@@ -939,7 +943,7 @@ impl<'cmd, 'writer> HelpTemplate<'cmd, 'writer> {
         self.none(TAB);
         self.writer.extend(sc_str.into_iter());
         if !next_line_help {
-            self.spaces(width.max(longest + TAB_WIDTH) - width);
+            self.spaces(longest + TAB_WIDTH - width);
         }
     }
 }


Test patch:
diff --git a/tests/builder/help.rs b/tests/builder/help.rs
index 1bd8a286..400085e5 100644
--- a/tests/builder/help.rs
+++ b/tests/builder/help.rs
@@ -355,17 +355,14 @@ fn wrapped_help() {
 Usage: test [OPTIONS]
 
 Options:
-  -a, --all
-          Also do versioning for private crates (will not be
-          published)
-      --exact
-          Specify inter dependency version numbers exactly with `=`
-      --no-git-commit
-          Do not commit version changes
-      --no-git-push
-          Do not push generated commit and tags to git remote
-  -h, --help
-          Print help information
+  -a, --all            Also do versioning for private crates (will
+                       not be published)
+      --exact          Specify inter dependency version numbers
+                       exactly with `=`
+      --no-git-commit  Do not commit version changes
+      --no-git-push    Do not push generated commit and tags to git
+                       remote
+  -h, --help           Print help information
 ";
     let cmd = Command::new("test")
         .term_width(67)
Repository: clap-rs/clap
Pull request #4717 (2023-02-19 00:42:31)

docs: Remove remaining references to clap attribute
Noticed via [reddit](https://www.reddit.com/r/rust/comments/115wovh/clap_documentation/)


Patch:
diff --git a/clap_complete/examples/completion-derive.rs b/clap_complete/examples/completion-derive.rs
index 9ca70f76..6b90f0a5 100644
--- a/clap_complete/examples/completion-derive.rs
+++ b/clap_complete/examples/completion-derive.rs
@@ -24,7 +24,7 @@ struct Opt {
     // If provided, outputs the completion file for given shell
     #[arg(long = "generate", value_enum)]
     generator: Option<Shell>,
-    #[clap(subcommand)]
+    #[command(subcommand)]
     command: Option<Commands>,
 }
 
diff --git a/examples/derive_ref/hand_subcommand.rs b/examples/derive_ref/hand_subcommand.rs
index 4836e47e..ebaa60d5 100644
--- a/examples/derive_ref/hand_subcommand.rs
+++ b/examples/derive_ref/hand_subcommand.rs
@@ -69,7 +69,7 @@ impl Subcommand for CliSub {
 struct Cli {
     #[arg(short, long)]
     top_level: bool,
-    #[clap(subcommand)]
+    #[command(subcommand)]
     subcommand: CliSub,
 }
 


Test patch:
diff --git a/tests/derive/groups.rs b/tests/derive/groups.rs
index 88f674a5..1c9bcb50 100644
--- a/tests/derive/groups.rs
+++ b/tests/derive/groups.rs
@@ -73,9 +73,9 @@ fn skip_group_avoids_duplicate_ids() {
     #[derive(clap::Args, Debug)]
     #[group(skip)]
     pub struct Compose<L: clap::Args, R: clap::Args> {
-        #[clap(flatten)]
+        #[command(flatten)]
         pub left: L,
-        #[clap(flatten)]
+        #[command(flatten)]
         pub right: R,
     }
 
@@ -108,9 +108,9 @@ fn helpful_panic_on_duplicate_groups() {
 
     #[derive(clap::Args, Debug)]
     pub struct Compose<L: clap::Args, R: clap::Args> {
-        #[clap(flatten)]
+        #[command(flatten)]
         pub left: L,
-        #[clap(flatten)]
+        #[command(flatten)]
         pub right: R,
     }