(Fix): fixed unsafe.Slice using &r (pointer-to-pointer) as the backing array instead of r (the calloc'd response array), which wrote password bytes into random stack memory.

This commit is contained in:
2026-07-18 21:29:20 +05:30
parent e51720da14
commit c37b3629ca

View File

@@ -80,13 +80,22 @@ func latchd_pam_conv(numMsg C.int, msg **C.struct_pam_message, resp **C.struct_p
} }
*resp = r *resp = r
s := unsafe.Slice((**C.struct_pam_response)(unsafe.Pointer(&r)), int(numMsg)) msgSlice := unsafe.Slice(msg, int(numMsg))
respSlice := unsafe.Slice(r, int(numMsg))
for i := 0; i < int(numMsg); i++ { for i := 0; i < int(numMsg); i++ {
switch msgSlice[i].msg_style {
case C.PAM_PROMPT_ECHO_OFF, C.PAM_PROMPT_ECHO_ON:
c := C.CString(pw) c := C.CString(pw)
if c == nil { if c == nil {
return C.PAM_BUF_ERR return C.PAM_BUF_ERR
} }
s[i] = &C.struct_pam_response{resp: c, resp_retcode: 0} respSlice[i].resp = c
respSlice[i].resp_retcode = 0
default:
respSlice[i].resp = nil
respSlice[i].resp_retcode = 0
}
} }
return C.PAM_SUCCESS return C.PAM_SUCCESS
} }