(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:
@@ -80,13 +80,22 @@ func latchd_pam_conv(numMsg C.int, msg **C.struct_pam_message, resp **C.struct_p
|
||||
}
|
||||
*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++ {
|
||||
c := C.CString(pw)
|
||||
if c == nil {
|
||||
return C.PAM_BUF_ERR
|
||||
switch msgSlice[i].msg_style {
|
||||
case C.PAM_PROMPT_ECHO_OFF, C.PAM_PROMPT_ECHO_ON:
|
||||
c := C.CString(pw)
|
||||
if c == nil {
|
||||
return C.PAM_BUF_ERR
|
||||
}
|
||||
respSlice[i].resp = c
|
||||
respSlice[i].resp_retcode = 0
|
||||
default:
|
||||
respSlice[i].resp = nil
|
||||
respSlice[i].resp_retcode = 0
|
||||
}
|
||||
s[i] = &C.struct_pam_response{resp: c, resp_retcode: 0}
|
||||
}
|
||||
return C.PAM_SUCCESS
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user