]> ruderich.org/simon Gitweb - linux-network-namespace-labs/linux-network-namespace-labs.git/commitdiff
Disallow node names which are numbers
authorSimon Ruderich <simon@ruderich.org>
Tue, 5 Nov 2024 06:46:17 +0000 (07:46 +0100)
committerSimon Ruderich <simon@ruderich.org>
Tue, 5 Nov 2024 06:46:17 +0000 (07:46 +0100)
config.go

index d3239b434a21c99b3cbac7ba3dfab36aead27c88..66cefc07e6c5738c5dbdc13196e14988a18fc8a9 100644 (file)
--- a/config.go
+++ b/config.go
@@ -10,6 +10,7 @@ import (
        "fmt"
        "net/netip"
        "os"
+       "strconv"
        "strings"
 )
 
@@ -155,6 +156,13 @@ func parseConfigNode(cfg *Config, args []string) error {
        res := Node{
                Name: args[0],
        }
+       _, err := strconv.Atoi(res.Name)
+       if err == nil {
+               // `ip` "netns" option uses the PID's namespace when given a number
+               // but we need the namespace name.
+               return fmt.Errorf("invalid name %q (must not be a number)",
+                       res.Name)
+       }
        if cfg.Nodes[res.Name] != nil {
                return fmt.Errorf("%q already exists", res.Name)
        }