Skip to content

Commit bced8d2

Browse files
committed
address pr comments
1 parent 05399ec commit bced8d2

3 files changed

Lines changed: 14 additions & 8 deletions

File tree

audit.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -598,16 +598,18 @@ type AuditStatus struct {
598598
BacklogWaitTimeActual uint32 // Time the kernel has spent waiting while the backlog limit is exceeded.
599599
}
600600

601+
const sizeofAuditStatus = int(unsafe.Sizeof(AuditStatus{}))
602+
601603
func (s AuditStatus) toWireFormat() []byte {
602-
return (*[unsafe.Sizeof(AuditStatus{})]byte)(unsafe.Pointer(&s))[:]
604+
return (*[sizeofAuditStatus]byte)(unsafe.Pointer(&s))[:]
603605
}
604606

605607
// FromWireFormat unmarshals the given buffer to an AuditStatus object. Due to
606608
// changes in the audit_status struct in the kernel source this method does
607609
// not return an error if the buffer is smaller than the sizeof our AuditStatus
608610
// struct.
609611
func (s *AuditStatus) FromWireFormat(buf []byte) error {
610-
if len(buf) < int(unsafe.Sizeof(AuditStatus{})) {
612+
if len(buf) < sizeofAuditStatus {
611613
return io.ErrUnexpectedEOF
612614
}
613615
copy((*[unsafe.Sizeof(AuditStatus{})]byte)(unsafe.Pointer(s))[:], buf)

rule/binary.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ type WireFormat []byte
3636
// AUDIT_LIST_RULES requests.
3737
// https://github.com/linux-audit/audit-kernel/blob/v3.15/include/uapi/linux/audit.h#L423-L437
3838
type auditRuleData struct {
39+
auditRuleHeader
40+
Buf []byte // String fields.
41+
}
42+
43+
type auditRuleHeader struct {
3944
Flags filter
4045
Action action
4146
FieldCount uint32
@@ -44,10 +49,9 @@ type auditRuleData struct {
4449
Values [maxFields]uint32
4550
FieldFlags [maxFields]operator
4651
BufLen uint32 // Total length of buffer used for string fields.
47-
Buf []byte // String fields.
4852
}
4953

50-
const ruleHeaderSize = int(unsafe.Sizeof(auditRuleData{}) - unsafe.Sizeof([]byte(nil)))
54+
const ruleHeaderSize = int(unsafe.Sizeof(auditRuleHeader{}))
5155

5256
func (r auditRuleData) toWireFormat() WireFormat {
5357
n := ruleHeaderSize + len(r.Buf)

rule/rule.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -390,11 +390,11 @@ type ruleData struct {
390390
}
391391

392392
func (d ruleData) toAuditRuleData() (*auditRuleData, error) {
393-
rule := &auditRuleData{
393+
rule := &auditRuleData{auditRuleHeader: auditRuleHeader{
394394
Flags: d.flags,
395395
Action: d.action,
396396
FieldCount: uint32(len(d.fields)),
397-
}
397+
}}
398398

399399
if d.allSyscalls {
400400
for i := 0; i < len(rule.Mask)-1; i++ {
@@ -725,7 +725,7 @@ func addFilter(rule *ruleData, lhs, comparator, rhs string) error {
725725
return err
726726
}
727727
rule.values = append(rule.values, arg)
728-
//case SessionIDField:
728+
// case SessionIDField:
729729
case inodeField:
730730
// Flag must be FilterExit.
731731
if rule.flags != exitFilter {
@@ -832,7 +832,7 @@ func getExitCode(exit string) (int32, error) {
832832
}
833833

834834
func getArch(arch string) (string, uint32, error) {
835-
var realArch = arch
835+
realArch := arch
836836
switch strings.ToLower(arch) {
837837
case "b64":
838838
runtimeArch, err := getRuntimeArch()

0 commit comments

Comments
 (0)