Improve: check uid on process search & fix typo (#824)

This commit is contained in:
Kr328 2020-07-22 20:22:34 +08:00 committed by GitHub
parent 4f73410618
commit 6521acf8f1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -36,7 +36,7 @@ type ProcessNameResolver func(inode, uid int) (name string, err error)
// export for android
var (
DefaultSocketResolver SocketResolver = resolveSocketByNetlink
DefaultProcessNameResolver ProcessNameResolver = resolveProcessNameByProcSeach
DefaultProcessNameResolver ProcessNameResolver = resolveProcessNameByProcSearch
)
type Process struct {
@ -225,7 +225,7 @@ func unpackSocketDiagResponse(msg *syscall.NetlinkMessage) (inode, uid uint32) {
return
}
func resolveProcessNameByProcSeach(inode, _ int) (string, error) {
func resolveProcessNameByProcSearch(inode, uid int) (string, error) {
files, err := ioutil.ReadDir(pathProc)
if err != nil {
return "", err
@ -235,7 +235,11 @@ func resolveProcessNameByProcSeach(inode, _ int) (string, error) {
socket := []byte(fmt.Sprintf("socket:[%d]", inode))
for _, f := range files {
if !isPid(f.Name()) {
if !f.IsDir() || !isPid(f.Name()) {
continue
}
if f.Sys().(*syscall.Stat_t).Uid != uint32(uid) {
continue
}