Skip to content

Commit 6a01307

Browse files
aiharosoktalz
authored andcommitted
BUG/MEDIUM: dgram-bind: fix IPv6 address parsing and serialization
ParseDgramBind used a naive strings.Split(path, ":") to separate address and port, which broke on IPv6 addresses like [fd66:c3ec:c7fc::7c]:123 because the colons in the IPv6 address were treated as delimiters. Use misc.ParseBindAddress() (already used by ParseBind for TCP binds) which properly handles IPv6 bracketed notation, prefix forms (ipv6@, udp6@), and unix socket paths. Similarly, SerializeDgramBind now uses misc.SanitizeIPv6Address() to wrap IPv6 addresses in brackets before appending the port, matching the SerializeBind implementation.
1 parent e34b8ab commit 6a01307

File tree

3 files changed

+387
-36
lines changed

3 files changed

+387
-36
lines changed

.aspell.yml

Lines changed: 205 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,205 @@
1+
---
2+
mode: commit
3+
min_length: 3
4+
allowed:
5+
- acls
6+
- adfs
7+
- addons
8+
- apitest
9+
- apikey
10+
- apk
11+
- aspell
12+
- attrs
13+
- auth
14+
- autofill
15+
- aws
16+
- axios
17+
- backend
18+
- backends
19+
- backport
20+
- bmarkovic
21+
- botmgmt
22+
- botmgtupdate
23+
- browserslist
24+
- bvue
25+
- bwlim
26+
- caniuse
27+
- casbin
28+
- chmigrate
29+
- cli
30+
- clickhouse
31+
- cnt
32+
- composable
33+
- cond
34+
- conf
35+
- config
36+
- conns
37+
- const
38+
- cpu
39+
- crd
40+
- cronjob
41+
- crt
42+
- cve
43+
- cwe
44+
- dapi
45+
- dataplane
46+
- dataplaneapi
47+
- dataplanes
48+
- datepicker
49+
- dereference
50+
- dgram
51+
- discoverability
52+
- durations
53+
- dns
54+
- dom
55+
- dpapi
56+
- dpapis
57+
- dropdowns
58+
- dsn
59+
- e2e
60+
- entrypoint
61+
- enum
62+
- env
63+
- eol
64+
- epoll
65+
- escaper
66+
- eslint
67+
- failsafe
68+
- fbt
69+
- fcgi
70+
- usefcgiapp
71+
- formatter
72+
- formatters
73+
- frontend
74+
- frontends
75+
- fullpage
76+
- gentype
77+
- github
78+
- gitlab
79+
- godaddy
80+
- gokc
81+
- golang
82+
- golangci
83+
- gorm
84+
- goroutines
85+
- govulncheck
86+
- gotoolchain
87+
- gpc
88+
- gpt
89+
- gptstr
90+
- hapee
91+
- haproxy
92+
- healthcheck
93+
- healthz
94+
- hostname
95+
- html
96+
- http
97+
- https
98+
- httpCLF
99+
- iana
100+
- ineffassign
101+
- infos
102+
- ipam
103+
- istanbul
104+
- jose
105+
- json
106+
- jsonpath
107+
- jwt
108+
- kasbin
109+
- kpi
110+
- kubebuilder
111+
- kubernetes
112+
- lifecycle
113+
- linter
114+
- linters
115+
- lowercased
116+
- lookups
117+
- lts
118+
- makefile
119+
- maxconn
120+
- mexchanger
121+
- migrator
122+
- minimalistic
123+
- minsize
124+
- mixin
125+
- mkdir
126+
- mpxs
127+
- multipartsearch
128+
- multiselect
129+
- mutex
130+
- mutexes
131+
- namespace
132+
- namespaces
133+
- oidc
134+
- omitempty
135+
- openapi
136+
- optim
137+
- packagetag
138+
- param
139+
- params
140+
- parallelize
141+
- passthrough
142+
- placholder
143+
- podman
144+
- pre
145+
- quic
146+
- rbac
147+
- readme
148+
- recursivity
149+
- recv
150+
- redispatch
151+
- redoc
152+
- reimplement
153+
- releaser
154+
- repo
155+
- repos
156+
- req
157+
- rsync
158+
- ruleset
159+
- rulesets
160+
- saml
161+
- sanitization
162+
- schemas
163+
- scrollbar
164+
- scss
165+
- searchselect
166+
- sni
167+
- spammy
168+
- ssl
169+
- sslv
170+
- sso
171+
- struct
172+
- subnet
173+
- subresource
174+
- subresources
175+
- sudo
176+
- symlinks
177+
- syslog
178+
- textarea
179+
- tcp
180+
- timeseries
181+
- tls
182+
- tooltip
183+
- tsconfig
184+
- typings
185+
- ubuntu
186+
- uniq
187+
- unix
188+
- unmarshalling
189+
- unsub
190+
- uri
191+
- url
192+
- userlist
193+
- userlists
194+
- utils
195+
- vfg
196+
- vite
197+
- vrrp
198+
- vue
199+
- waf
200+
- wafadvanced
201+
- workdir
202+
- yaml
203+
- async
204+
- rehaul
205+
- XXXX

configuration/dgram_bind.go

Lines changed: 21 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
parser_errors "github.com/haproxytech/client-native/v5/config-parser/errors"
2727
"github.com/haproxytech/client-native/v5/config-parser/params"
2828
"github.com/haproxytech/client-native/v5/config-parser/types"
29+
"github.com/haproxytech/client-native/v5/misc"
2930

3031
"github.com/haproxytech/client-native/v5/models"
3132
)
@@ -187,43 +188,27 @@ func ParseDgramBinds(logForward string, p parser.Parser) (models.DgramBinds, err
187188

188189
func ParseDgramBind(ondiskDgramBind types.DgramBind) *models.DgramBind {
189190
b := &models.DgramBind{}
190-
if strings.HasPrefix(ondiskDgramBind.Path, "/") {
191-
b.Address = ondiskDgramBind.Path
192-
} else {
193-
addSlice := strings.Split(ondiskDgramBind.Path, ":")
194-
switch n := len(addSlice); {
195-
case n == 0:
196-
return nil
197-
case n == 4: // :::443
198-
b.Address = "::"
199-
if addSlice[3] != "" {
200-
p, err := strconv.ParseInt(addSlice[3], 10, 64)
201-
if err == nil {
202-
b.Port = &p
203-
}
204-
}
205-
case n > 1:
206-
b.Address = addSlice[0]
207-
ports := strings.Split(addSlice[1], "-")
208-
209-
// *:<port>
210-
if ports[0] != "" {
211-
port, err := strconv.ParseInt(ports[0], 10, 64)
212-
if err == nil {
213-
b.Port = &port
214-
}
191+
address, port, err := misc.ParseBindAddress(ondiskDgramBind.Path)
192+
if err != nil {
193+
return nil
194+
}
195+
b.Address = address
196+
if port != "" {
197+
ports := strings.Split(port, "-")
198+
// *:<port>
199+
if ports[0] != "" {
200+
p, err := strconv.ParseInt(ports[0], 10, 64)
201+
if err == nil {
202+
b.Port = &p
215203
}
216-
// *:<port-first>-<port-last>
217-
if b.Port != nil && len(ports) == 2 {
218-
portRangeEnd, err := strconv.ParseInt(ports[1], 10, 64)
219-
// Deny inverted interval.
220-
if err == nil && (*b.Port < portRangeEnd) {
221-
b.PortRangeEnd = &portRangeEnd
222-
}
204+
}
205+
// *:<port-first>-<port-last>
206+
if b.Port != nil && len(ports) == 2 {
207+
portRangeEnd, err := strconv.ParseInt(ports[1], 10, 64)
208+
// Deny inverted interval.
209+
if err == nil && (*b.Port < portRangeEnd) {
210+
b.PortRangeEnd = &portRangeEnd
223211
}
224-
case n > 0:
225-
b.Address = addSlice[0]
226-
227212
}
228213
}
229214
for _, p := range ondiskDgramBind.Params {
@@ -254,7 +239,7 @@ func SerializeDgramBind(b models.DgramBind) types.DgramBind {
254239
Params: []params.DgramBindOption{},
255240
}
256241
if b.Port != nil {
257-
dBind.Path = b.Address + ":" + strconv.FormatInt(*b.Port, 10)
242+
dBind.Path = misc.SanitizeIPv6Address(b.Address) + ":" + strconv.FormatInt(*b.Port, 10)
258243
if b.PortRangeEnd != nil {
259244
dBind.Path = dBind.Path + "-" + strconv.FormatInt(*b.PortRangeEnd, 10)
260245
}

0 commit comments

Comments
 (0)