assignProcessToJob assigns a process to a Job Object. Returns the process handle which should be closed by the caller.
(job windows.Handle, pid int)
| 43 | // assignProcessToJob assigns a process to a Job Object. |
| 44 | // Returns the process handle which should be closed by the caller. |
| 45 | func assignProcessToJob(job windows.Handle, pid int) (windows.Handle, error) { |
| 46 | // Validate PID range to prevent overflow |
| 47 | if pid < 0 || pid > 0x7FFFFFFF { |
| 48 | return 0, fmt.Errorf("invalid process ID: %d", pid) |
| 49 | } |
| 50 | |
| 51 | // Get child process handle (requires PROCESS_ALL_ACCESS) |
| 52 | // #nosec G115 -- PID validated above to prevent overflow |
| 53 | hProc, err := windows.OpenProcess(windows.PROCESS_ALL_ACCESS, false, uint32(pid)) |
| 54 | if err != nil { |
| 55 | return 0, err |
| 56 | } |
| 57 | // Assign to Job |
| 58 | if err = windows.AssignProcessToJobObject(job, hProc); err != nil { |
| 59 | _ = windows.CloseHandle(hProc) |
| 60 | return 0, err |
| 61 | } |
| 62 | return hProc, nil |
| 63 | } |
| 64 | |
| 65 | // GetAPIKeyFromHelper executes a shell command to dynamically generate an API key. |
| 66 | // The command is executed in cmd.exe with a timeout controlled by the provided context. |
no outgoing calls