Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: avoid printing confusing message when input contains special character #495

Merged
merged 5 commits into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/go-c-cpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
- name: golangci-lint
uses: golangci/golangci-lint-action@v4
with:
args: --disable-all -E errcheck
args: --disable-all -E errcheck -E staticcheck
skip-cache: true
skip-pkg-cache: true
skip-build-cache: true
Expand Down Expand Up @@ -81,7 +81,7 @@ jobs:
- name: golangci-lint
uses: golangci/golangci-lint-action@v4
with:
args: --disable-all -E errcheck
args: --disable-all -E errcheck -E staticcheck
skip-cache: true
skip-pkg-cache: true
skip-build-cache: true
Expand Down
9 changes: 4 additions & 5 deletions cli/cmd/gnutls.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func gnuTlsCommandFunc(command *cobra.Command, args []string) {
logger.Printf("ECAPTURE :: %s Version : %s", cliName, GitVersion)
logger.Printf("ECAPTURE :: Pid Info : %d", os.Getpid())
var version kernel.Version
version, err = kernel.HostVersion()
version, _ = kernel.HostVersion() // it's safe to ignore error because we have checked it in func main
logger.Printf("ECAPTURE :: Kernel Info : %s", version.String())
modNames := []string{module.ModuleNameGnutls}

Expand All @@ -85,13 +85,12 @@ func gnuTlsCommandFunc(command *cobra.Command, args []string) {
logger.Printf("ECAPTURE :: \tcant found module: %s", modName)
break
}

var conf config.IConfig
conf = gc
if conf == nil {
if gc == nil {
logger.Printf("ECAPTURE :: \tcant found module %s config info.", mod.Name())
break
}
var conf config.IConfig
conf = gc

conf.SetPid(gConf.Pid)
conf.SetUid(gConf.Uid)
Expand Down
9 changes: 4 additions & 5 deletions cli/cmd/gotls.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,21 +75,20 @@ func goTLSCommandFunc(command *cobra.Command, args []string) {
logger.Printf("ECAPTURE :: %s Version : %s", cliName, GitVersion)
logger.Printf("ECAPTURE :: Pid Info : %d", os.Getpid())
var version kernel.Version
version, err = kernel.HostVersion()
version, _ = kernel.HostVersion() // it's safe to ignore error because we have checked it in func main
logger.Printf("ECAPTURE :: Kernel Info : %s", version.String())

mod := module.GetModuleByName(module.ModuleNameGotls)
if mod == nil {
logger.Printf("ECAPTURE :: \tcant found module: %s", module.ModuleNameGotls)
return
}

var conf config.IConfig
conf = goc
if conf == nil {
if goc == nil {
logger.Printf("ECAPTURE :: \tcant found module %s config info.", mod.Name())
return
}
var conf config.IConfig
conf = goc

conf.SetPid(gConf.Pid)
conf.SetUid(gConf.Uid)
Expand Down
9 changes: 4 additions & 5 deletions cli/cmd/nss.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func nssCommandFunc(command *cobra.Command, args []string) {
logger.Printf("ECAPTURE :: %s Version : %s", cliName, GitVersion)
logger.Printf("ECAPTURE :: Pid Info : %d", os.Getpid())
var version kernel.Version
version, err = kernel.HostVersion()
version, _ = kernel.HostVersion() // it's safe to ignore error because we have checked it in func main
logger.Printf("ECAPTURE :: Kernel Info : %s", version.String())
modNames := []string{module.ModuleNameNspr}

Expand All @@ -85,13 +85,12 @@ func nssCommandFunc(command *cobra.Command, args []string) {
logger.Printf("ECAPTURE :: \tcant found module: %s", modName)
break
}

var conf config.IConfig
conf = nc
if conf == nil {
if nc == nil {
logger.Printf("ECAPTURE :: \tcant found module %s config info.", mod.Name())
break
}
var conf config.IConfig
conf = nc

conf.SetPid(gConf.Pid)
conf.SetUid(gConf.Uid)
Expand Down
13 changes: 5 additions & 8 deletions cli/cmd/tls.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,9 @@ func openSSLCommandFunc(command *cobra.Command, args []string) {
logger.Printf("ECAPTURE :: %s Version : %s", cliName, GitVersion)
logger.Printf("ECAPTURE :: Pid Info : %d", os.Getpid())
var version kernel.Version
version, err = kernel.HostVersion()
version, _ = kernel.HostVersion() // it's safe to ignore err because we have checked it in func main
logger.Printf("ECAPTURE :: Kernel Info : %s", version.String())
modNames := []string{}
modNames = []string{module.ModuleNameOpenssl}
modNames := []string{module.ModuleNameOpenssl}

var runMods uint8
runModules := make(map[string]module.IModule)
Expand All @@ -100,14 +99,12 @@ func openSSLCommandFunc(command *cobra.Command, args []string) {
logger.Printf("ECAPTURE :: \tcant found module: %s", modName)
break
}

var conf config.IConfig
conf = oc

if conf == nil {
if oc == nil {
logger.Printf("ECAPTURE :: \tcant found module %s config info.", mod.Name())
break
}
var conf config.IConfig
conf = oc

conf.SetPid(gConf.Pid)
conf.SetUid(gConf.Uid)
Expand Down
4 changes: 2 additions & 2 deletions pkg/util/ebpf/bpf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func TestBpfConfig(t *testing.T) {
configPaths = []string{
"/xxxxx/proc/config.gz", // android
}
m, e := GetSystemConfig()
_, e := GetSystemConfig()
if e != nil {
// 正常情况 是没有找到配置文件
t.Logf("GetSystemConfig error:%s", e.Error())
Expand All @@ -47,7 +47,7 @@ func TestBpfConfig(t *testing.T) {
configPaths = []string{
"config.gz", // test file from pixel 6 android 12
}
m, e = GetSystemConfig()
m, e := GetSystemConfig()
if e != nil {
t.Fatalf("GetSystemConfig(gzip) error:%s", e.Error())
}
Expand Down
4 changes: 2 additions & 2 deletions user/config/config_gotls.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func (gc *GoTLSConfig) Check() error {
case "amd64":
case "arm64":
default:
err = fmt.Errorf("unsupport CPU arch :%s", goElfArch)
return fmt.Errorf("unsupport CPU arch :%s", goElfArch)
}
gc.goElfArch = goElfArch
gc.goElf = goElf
Expand Down Expand Up @@ -156,7 +156,7 @@ func (gc *GoTLSConfig) findRetOffsets(symbolName string) ([]int, error) {
var offsets []int
var instHex []byte
instHex = elfText[start:end]
offsets, err = gc.decodeInstruction(instHex)
offsets, _ = gc.decodeInstruction(instHex)
if len(offsets) == 0 {
return offsets, ErrorNoRetFound
}
Expand Down
4 changes: 2 additions & 2 deletions user/event/event_bash.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,12 @@ func (be *BashEvent) Decode(payload []byte) (err error) {
}

func (be *BashEvent) String() string {
s := fmt.Sprintf(fmt.Sprintf("PID:%d, UID:%d, \tComm:%s, \tRetvalue:%d, \tLine:\n%s", be.Pid, be.Uid, be.Comm, be.Retval, unix.ByteSliceToString((be.Line[:]))))
s := fmt.Sprintf("PID:%d, UID:%d, \tComm:%s, \tRetvalue:%d, \tLine:\n%s", be.Pid, be.Uid, be.Comm, be.Retval, unix.ByteSliceToString((be.Line[:])))
return s
}

func (be *BashEvent) StringHex() string {
s := fmt.Sprintf(fmt.Sprintf("PID:%d, UID:%d, \tComm:%s, \tRetvalue:%d, \tLine:\n%s,", be.Pid, be.Uid, be.Comm, be.Retval, dumpByteSlice([]byte(unix.ByteSliceToString((be.Line[:]))), "")))
s := fmt.Sprintf("PID:%d, UID:%d, \tComm:%s, \tRetvalue:%d, \tLine:\n%s,", be.Pid, be.Uid, be.Comm, be.Retval, dumpByteSlice([]byte(unix.ByteSliceToString((be.Line[:]))), ""))
return s
}

Expand Down
4 changes: 3 additions & 1 deletion user/event/event_gotls.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ func (ge *GoTLSEvent) Decode(payload []byte) error {
}
if ge.Len > 0 {
ge.Data = make([]byte, ge.Len)
err = binary.Read(r, binary.LittleEndian, &ge.Data)
if err = binary.Read(r, binary.LittleEndian, &ge.Data); err != nil {
return err
}
}
decodedKtime, err := DecodeKtime(int64(ge.TimestampNS), true)
if err == nil {
Expand Down
4 changes: 2 additions & 2 deletions user/event/event_mysqld.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,12 @@ func (me *MysqldEvent) Decode(payload []byte) (err error) {
}

func (me *MysqldEvent) String() string {
s := fmt.Sprintf(fmt.Sprintf(" PID:%d, Comm:%s, Time:%d, length:(%d/%d), return:%s, Line:%s", me.Pid, me.Comm, me.Timestamp, me.Len, me.Alllen, me.Retval, unix.ByteSliceToString((me.Query[:]))))
s := fmt.Sprintf(" PID:%d, Comm:%s, Time:%d, length:(%d/%d), return:%s, Line:%s", me.Pid, me.Comm, me.Timestamp, me.Len, me.Alllen, me.Retval, unix.ByteSliceToString((me.Query[:])))
return s
}

func (me *MysqldEvent) StringHex() string {
s := fmt.Sprintf(fmt.Sprintf(" PID:%d, Comm:%s, Time:%d, length:(%d/%d), return:%s, Line:%s", me.Pid, me.Comm, me.Timestamp, me.Len, me.Alllen, me.Retval, unix.ByteSliceToString((me.Query[:]))))
s := fmt.Sprintf(" PID:%d, Comm:%s, Time:%d, length:(%d/%d), return:%s, Line:%s", me.Pid, me.Comm, me.Timestamp, me.Len, me.Alllen, me.Retval, unix.ByteSliceToString((me.Query[:])))
return s
}

Expand Down
4 changes: 2 additions & 2 deletions user/event/event_postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,12 @@ func (pe *PostgresEvent) Decode(payload []byte) (err error) {
}

func (pe *PostgresEvent) String() string {
s := fmt.Sprintf(fmt.Sprintf(" PID: %d, Comm: %s, Time: %d, Query: %s", pe.Pid, pe.Comm, pe.Timestamp, unix.ByteSliceToString((pe.Query[:]))))
s := fmt.Sprintf(" PID: %d, Comm: %s, Time: %d, Query: %s", pe.Pid, pe.Comm, pe.Timestamp, unix.ByteSliceToString((pe.Query[:])))
return s
}

func (pe *PostgresEvent) StringHex() string {
s := fmt.Sprintf(fmt.Sprintf(" PID: %d, Comm: %s, Time: %d, Query: %s", pe.Pid, pe.Comm, pe.Timestamp, unix.ByteSliceToString((pe.Query[:]))))
s := fmt.Sprintf(" PID: %d, Comm: %s, Time: %d, Query: %s", pe.Pid, pe.Comm, pe.Timestamp, unix.ByteSliceToString((pe.Query[:])))
return s
}

Expand Down
6 changes: 2 additions & 4 deletions user/module/imodule.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,8 @@ func (m *Module) Init(ctx context.Context, logger *log.Logger, conf config.IConf
m.logger = logger
m.processor = event_processor.NewEventProcessor(logger, conf.GetHex())
m.isKernelLess5_2 = false //set false default
kv, err := kernel.HostVersion()
if err != nil {
// nothing to do.
}
kv, _ := kernel.HostVersion()
// it's safe to ignore err because we have checked it in main funcition
if kv < kernel.VersionCode(5, 2, 0) {
m.isKernelLess5_2 = true
}
Expand Down
2 changes: 1 addition & 1 deletion user/module/probe_pcap.go
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ func prepareInsnPatchers(m *manager.Manager, ebpfFuncs []string, pcapFilter stri
}

for _, progSpec := range progSpecs {
progSpec, err = injectPcapFilter(progSpec, pcapFilter)
_, err = injectPcapFilter(progSpec, pcapFilter)
if err != nil {
return fmt.Errorf("failed to inject pcap filter for %s: %w", ebpfFunc, err)
}
Expand Down
Loading