mirror of
https://github.com/netbirdio/netbird.git
synced 2026-09-27 17:19:08 +02:00
Reject out-of-range listen_port and split service meta scan
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"math"
|
||||||
"net"
|
"net"
|
||||||
"net/netip"
|
"net/netip"
|
||||||
"net/url"
|
"net/url"
|
||||||
@@ -2373,21 +2374,7 @@ func scanService(row pgx.CollectableRow) (*rpservice.Service, error) {
|
|||||||
s.Private = private.Bool
|
s.Private = private.Bool
|
||||||
}
|
}
|
||||||
|
|
||||||
s.Meta = rpservice.Meta{}
|
s.Meta = serviceMetaFromRow(createdAt, certIssuedAt, lastRenewedAt, status)
|
||||||
if createdAt.Valid {
|
|
||||||
s.Meta.CreatedAt = createdAt.Time
|
|
||||||
}
|
|
||||||
if certIssuedAt.Valid {
|
|
||||||
t := certIssuedAt.Time
|
|
||||||
s.Meta.CertificateIssuedAt = &t
|
|
||||||
}
|
|
||||||
if lastRenewedAt.Valid {
|
|
||||||
t := lastRenewedAt.Time
|
|
||||||
s.Meta.LastRenewedAt = &t
|
|
||||||
}
|
|
||||||
if status.Valid {
|
|
||||||
s.Meta.Status = status.String
|
|
||||||
}
|
|
||||||
if proxyCluster.Valid {
|
if proxyCluster.Valid {
|
||||||
s.ProxyCluster = proxyCluster.String
|
s.ProxyCluster = proxyCluster.String
|
||||||
}
|
}
|
||||||
@@ -2413,12 +2400,34 @@ func scanService(row pgx.CollectableRow) (*rpservice.Service, error) {
|
|||||||
s.PortAutoAssigned = portAutoAssigned.Bool
|
s.PortAutoAssigned = portAutoAssigned.Bool
|
||||||
}
|
}
|
||||||
if listenPort.Valid {
|
if listenPort.Valid {
|
||||||
|
if listenPort.Int64 < 0 || listenPort.Int64 > math.MaxUint16 {
|
||||||
|
return nil, fmt.Errorf("listen_port %d out of range", listenPort.Int64)
|
||||||
|
}
|
||||||
s.ListenPort = uint16(listenPort.Int64)
|
s.ListenPort = uint16(listenPort.Int64)
|
||||||
}
|
}
|
||||||
s.Targets = []*rpservice.Target{}
|
s.Targets = []*rpservice.Target{}
|
||||||
return &s, nil
|
return &s, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func serviceMetaFromRow(createdAt, certIssuedAt, lastRenewedAt sql.NullTime, status sql.NullString) rpservice.Meta {
|
||||||
|
meta := rpservice.Meta{}
|
||||||
|
if createdAt.Valid {
|
||||||
|
meta.CreatedAt = createdAt.Time
|
||||||
|
}
|
||||||
|
if certIssuedAt.Valid {
|
||||||
|
t := certIssuedAt.Time
|
||||||
|
meta.CertificateIssuedAt = &t
|
||||||
|
}
|
||||||
|
if lastRenewedAt.Valid {
|
||||||
|
t := lastRenewedAt.Time
|
||||||
|
meta.LastRenewedAt = &t
|
||||||
|
}
|
||||||
|
if status.Valid {
|
||||||
|
meta.Status = status.String
|
||||||
|
}
|
||||||
|
return meta
|
||||||
|
}
|
||||||
|
|
||||||
func (s *SqlStore) getServiceTargets(ctx context.Context, serviceIDs []string) ([]*rpservice.Target, error) {
|
func (s *SqlStore) getServiceTargets(ctx context.Context, serviceIDs []string) ([]*rpservice.Target, error) {
|
||||||
const targetsQuery = `SELECT ` + targetSelectColumns + ` FROM targets WHERE service_id = ANY($1)`
|
const targetsQuery = `SELECT ` + targetSelectColumns + ` FROM targets WHERE service_id = ANY($1)`
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user