From 8d1c56e7c4b7943c205e866af3f3764d543a35be Mon Sep 17 00:00:00 2001 From: Didier Roche Date: Tue, 22 Oct 2024 13:34:55 +0200 Subject: [PATCH] Fix overflow data conversion --- internal/authorizer/authorizer.go | 8 +++++++- internal/smbsafe/smbsafe_test.go | 4 ++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/internal/authorizer/authorizer.go b/internal/authorizer/authorizer.go index 19ddb27ac..28e3a5774 100644 --- a/internal/authorizer/authorizer.go +++ b/internal/authorizer/authorizer.go @@ -176,10 +176,16 @@ func (a Authorizer) isAllowed(ctx context.Context, action Action, pid int32, uid return err } + // polkit requests an uint32 on dbus + var upid uint32 + if pid > 0 { + upid = uint32(pid) + } + subject := authSubject{ Kind: "unix-process", Details: map[string]dbus.Variant{ - "pid": dbus.MakeVariant(uint32(pid)), // polkit requests an uint32 on dbus + "pid": dbus.MakeVariant(upid), "start-time": dbus.MakeVariant(startTime), "uid": dbus.MakeVariant(uid), }, diff --git a/internal/smbsafe/smbsafe_test.go b/internal/smbsafe/smbsafe_test.go index 81194b11f..40b209949 100644 --- a/internal/smbsafe/smbsafe_test.go +++ b/internal/smbsafe/smbsafe_test.go @@ -126,11 +126,11 @@ func TestMultipleSmbLocksOnlyReleaseOnLast(t *testing.T) { func shouldHaveWaited(t *testing.T, startpoint time.Time) { t.Helper() - require.Less(t, uint64(waitTime-time.Millisecond), uint64(time.Since(startpoint)), "Should have waited") + require.Less(t, int64(waitTime-time.Millisecond), int64(time.Since(startpoint)), "Should have waited") } func shouldNotHaveWaited(t *testing.T, startpoint time.Time) { t.Helper() - require.Less(t, uint64(time.Since(startpoint)), uint64(waitTime+time.Millisecond), "Shouldn’t have waited") + require.WithinDuration(t, time.Now(), startpoint, waitTime, "Shouldn’t have waited") }