Mercurial > crates > nonstick
comparison pam/src/conv.rs @ 29:c16564971c05
conv: fix segfault when decoding response of PAM_TEXT_INFO et al.
| author | holycleugh <holycleugh> |
|---|---|
| date | Sun, 30 Dec 2018 03:40:41 -0500 |
| parents | 81a9f0479e50 |
| children | 1f4ef4c7e555 |
comparison
equal
deleted
inserted
replaced
| 28:81a9f0479e50 | 29:c16564971c05 |
|---|---|
| 62 }; | 62 }; |
| 63 | 63 |
| 64 let ret = (self.conv)(1, &&msg, &mut resp_ptr, self.appdata_ptr); | 64 let ret = (self.conv)(1, &&msg, &mut resp_ptr, self.appdata_ptr); |
| 65 | 65 |
| 66 if PamResultCode::PAM_SUCCESS == ret { | 66 if PamResultCode::PAM_SUCCESS == ret { |
| 67 if resp_ptr.is_null() { | 67 // PamResponse.resp is null for styles that don't return user input like PAM_TEXT_INFO |
| 68 let response = unsafe { (*resp_ptr).resp }; | |
| 69 if response.is_null() { | |
| 68 Ok(None) | 70 Ok(None) |
| 69 } else { | 71 } else { |
| 70 let bytes = unsafe { CStr::from_ptr((*resp_ptr).resp).to_bytes() }; | 72 let bytes = unsafe { CStr::from_ptr(response).to_bytes() }; |
| 71 Ok(String::from_utf8(bytes.to_vec()).ok()) | 73 Ok(String::from_utf8(bytes.to_vec()).ok()) |
| 72 } | 74 } |
| 73 } else { | 75 } else { |
| 74 Err(ret) | 76 Err(ret) |
| 75 } | 77 } |
