Skip to content

Commit 7fbb79f

Browse files
committed
Fix unsafe uses of unsafe.Pointer (#1438)
Per rule 4 of unsafe.Pointer usage, conversion of a unsafe.Pointer to a uinptr to pass to the syscall.Syscall family should only be done in the argument list. We had a couple spots where we were passing it in as an argument to a small wrapper function until it reached the underlying syscall.Syscall*. https://pkg.go.dev/unsafe#Pointer Signed-off-by: Daniel Canter <[email protected]> (cherry picked from commit 1ec8cad) Signed-off-by: Daniel Canter <[email protected]>
1 parent 52a4ea9 commit 7fbb79f

7 files changed

Lines changed: 16 additions & 15 deletions

File tree

internal/jobcontainers/jobcontainer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,7 @@ func systemProcessInformation() ([]*winapi.SYSTEM_PROCESS_INFORMATION, error) {
575575
systemProcInfo = (*winapi.SYSTEM_PROCESS_INFORMATION)(unsafe.Pointer(&b[0]))
576576
status := winapi.NtQuerySystemInformation(
577577
winapi.SystemProcessInformation,
578-
uintptr(unsafe.Pointer(systemProcInfo)),
578+
unsafe.Pointer(systemProcInfo),
579579
size,
580580
&size,
581581
)

internal/jobobject/jobobject.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ func (job *JobObject) Pids() ([]uint32, error) {
339339
err := winapi.QueryInformationJobObject(
340340
job.handle,
341341
winapi.JobObjectBasicProcessIdList,
342-
uintptr(unsafe.Pointer(&info)),
342+
unsafe.Pointer(&info),
343343
uint32(unsafe.Sizeof(info)),
344344
nil,
345345
)
@@ -365,7 +365,7 @@ func (job *JobObject) Pids() ([]uint32, error) {
365365
if err = winapi.QueryInformationJobObject(
366366
job.handle,
367367
winapi.JobObjectBasicProcessIdList,
368-
uintptr(unsafe.Pointer(&buf[0])),
368+
unsafe.Pointer(&buf[0]),
369369
uint32(len(buf)),
370370
nil,
371371
); err != nil {
@@ -393,7 +393,7 @@ func (job *JobObject) QueryMemoryStats() (*winapi.JOBOBJECT_MEMORY_USAGE_INFORMA
393393
if err := winapi.QueryInformationJobObject(
394394
job.handle,
395395
winapi.JobObjectMemoryUsageInformation,
396-
uintptr(unsafe.Pointer(&info)),
396+
unsafe.Pointer(&info),
397397
uint32(unsafe.Sizeof(info)),
398398
nil,
399399
); err != nil {
@@ -415,7 +415,7 @@ func (job *JobObject) QueryProcessorStats() (*winapi.JOBOBJECT_BASIC_ACCOUNTING_
415415
if err := winapi.QueryInformationJobObject(
416416
job.handle,
417417
winapi.JobObjectBasicAccountingInformation,
418-
uintptr(unsafe.Pointer(&info)),
418+
unsafe.Pointer(&info),
419419
uint32(unsafe.Sizeof(info)),
420420
nil,
421421
); err != nil {
@@ -441,7 +441,7 @@ func (job *JobObject) QueryStorageStats() (*winapi.JOBOBJECT_IO_ATTRIBUTION_INFO
441441
if err := winapi.QueryInformationJobObject(
442442
job.handle,
443443
winapi.JobObjectIoAttribution,
444-
uintptr(unsafe.Pointer(&info)),
444+
unsafe.Pointer(&info),
445445
uint32(unsafe.Sizeof(info)),
446446
nil,
447447
); err != nil {
@@ -487,7 +487,7 @@ func (job *JobObject) QueryPrivateWorkingSet() (uint64, error) {
487487
status := winapi.NtQueryInformationProcess(
488488
h,
489489
winapi.ProcessVmCounters,
490-
uintptr(unsafe.Pointer(&vmCounters)),
490+
unsafe.Pointer(&vmCounters),
491491
uint32(unsafe.Sizeof(vmCounters)),
492492
nil,
493493
)

internal/jobobject/limits.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ func (job *JobObject) getExtendedInformation() (*windows.JOBOBJECT_EXTENDED_LIMI
202202
if err := winapi.QueryInformationJobObject(
203203
job.handle,
204204
windows.JobObjectExtendedLimitInformation,
205-
uintptr(unsafe.Pointer(&info)),
205+
unsafe.Pointer(&info),
206206
uint32(unsafe.Sizeof(info)),
207207
nil,
208208
); err != nil {
@@ -224,7 +224,7 @@ func (job *JobObject) getCPURateControlInformation() (*winapi.JOBOBJECT_CPU_RATE
224224
if err := winapi.QueryInformationJobObject(
225225
job.handle,
226226
windows.JobObjectCpuRateControlInformation,
227-
uintptr(unsafe.Pointer(&info)),
227+
unsafe.Pointer(&info),
228228
uint32(unsafe.Sizeof(info)),
229229
nil,
230230
); err != nil {

internal/winapi/jobobject.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ type JOBOBJECT_ASSOCIATE_COMPLETION_PORT struct {
175175
// LPDWORD lpReturnLength
176176
// );
177177
//
178-
//sys QueryInformationJobObject(jobHandle windows.Handle, infoClass uint32, jobObjectInfo uintptr, jobObjectInformationLength uint32, lpReturnLength *uint32) (err error) = kernel32.QueryInformationJobObject
178+
//sys QueryInformationJobObject(jobHandle windows.Handle, infoClass uint32, jobObjectInfo unsafe.Pointer, jobObjectInformationLength uint32, lpReturnLength *uint32) (err error) = kernel32.QueryInformationJobObject
179179

180180
// HANDLE OpenJobObjectW(
181181
// DWORD dwDesiredAccess,

internal/winapi/process.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const ProcessVmCounters = 3
1818
// [out, optional] PULONG ReturnLength
1919
// );
2020
//
21-
//sys NtQueryInformationProcess(processHandle windows.Handle, processInfoClass uint32, processInfo uintptr, processInfoLength uint32, returnLength *uint32) (status uint32) = ntdll.NtQueryInformationProcess
21+
//sys NtQueryInformationProcess(processHandle windows.Handle, processInfoClass uint32, processInfo unsafe.Pointer, processInfoLength uint32, returnLength *uint32) (status uint32) = ntdll.NtQueryInformationProcess
2222

2323
// typedef struct _VM_COUNTERS_EX
2424
// {

internal/winapi/system.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ const STATUS_INFO_LENGTH_MISMATCH = 0xC0000004
1212
// ULONG SystemInformationLength,
1313
// PULONG ReturnLength
1414
// );
15-
//sys NtQuerySystemInformation(systemInfoClass int, systemInformation uintptr, systemInfoLength uint32, returnLength *uint32) (status uint32) = ntdll.NtQuerySystemInformation
15+
//
16+
//sys NtQuerySystemInformation(systemInfoClass int, systemInformation unsafe.Pointer, systemInfoLength uint32, returnLength *uint32) (status uint32) = ntdll.NtQuerySystemInformation
1617

1718
type SYSTEM_PROCESS_INFORMATION struct {
1819
NextEntryOffset uint32 // ULONG

internal/winapi/zsyscall_windows.go

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)