From 47568051bf51e11a6eaaf1c62dd5baf4e63703af Mon Sep 17 00:00:00 2001 From: adlyq <2833154405@qq.com> Date: Thu, 28 Apr 2022 11:51:40 +0800 Subject: [PATCH] fix: problems caused when uid is 0 --- constant/metadata.go | 10 +++++----- rule/common/uid.go | 6 +++--- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/constant/metadata.go b/constant/metadata.go index fe1b7c50..4ddb1bd9 100644 --- a/constant/metadata.go +++ b/constant/metadata.go @@ -83,7 +83,7 @@ type Metadata struct { AddrType int `json:"-"` Host string `json:"host"` DNSMode DNSMode `json:"dnsMode"` - Uid int32 `json:"uid"` + Uid *int32 `json:"uid"` Process string `json:"process"` ProcessPath string `json:"processPath"` } @@ -101,10 +101,10 @@ func (m *Metadata) SourceDetail() string { return fmt.Sprintf("[%s]", ClashName) } - if m.Process != "" && m.Uid != 0 { - return fmt.Sprintf("%s(%s, uid=%d)", m.SourceAddress(), m.Process, m.Uid) - } else if m.Uid != 0 { - return fmt.Sprintf("%s(%d)", m.SourceAddress(), m.Uid) + if m.Process != "" && m.Uid != nil { + return fmt.Sprintf("%s(%s, uid=%d)", m.SourceAddress(), m.Process, *m.Uid) + } else if m.Uid != nil { + return fmt.Sprintf("%s(%d)", m.SourceAddress(), *m.Uid) } else if m.Process != "" { return fmt.Sprintf("%s(%s)", m.SourceAddress(), m.Process) } else { diff --git a/rule/common/uid.go b/rule/common/uid.go index 2ab1beb6..00f0c3d8 100644 --- a/rule/common/uid.go +++ b/rule/common/uid.go @@ -72,10 +72,10 @@ func (u *Uid) Match(metadata *C.Metadata) bool { return false } var uid int32 - if metadata.Uid != 0 { - uid = metadata.Uid + if metadata.Uid != nil { + uid = *metadata.Uid } else if uid, err = process.FindUid(metadata.NetWork.String(), metadata.SrcIP, srcPort); err == nil { - metadata.Uid = uid + metadata.Uid = &uid } else { log.Warnln("[UID] could not get uid from %s", metadata.String()) return false