@@ -463,11 +463,13 @@ pub unsafe extern "system" fn AcquireCredentialsHandleW(
463463 check_null!( p_auth_data) ;
464464 check_null!( ph_credential) ;
465465
466- // SAFETY:
467- // - `psz_package` is guaranteed to be non-null due to the prior check.
468- // - The memory region `psz_package` contains a valid null-terminator at the end of string.
469- // - The memory region `psz_package` points to is valid for reads of bytes up to and including null-terminator.
470- let security_package_name = unsafe { c_w_str_to_string( psz_package) } ;
466+ let security_package_name = try_execute!(
467+ // SAFETY:
468+ // - `psz_package` is guaranteed to be non-null due to the prior check.
469+ // - The memory region `psz_package` contains a valid null-terminator at the end of string.
470+ // - The memory region `psz_package` points to is valid for reads of bytes up to and including null-terminator.
471+ unsafe { c_w_str_to_string( psz_package) } . map_err( Error :: from)
472+ ) ;
471473 try_execute!( verify_security_package( & security_package_name) ) ;
472474
473475 debug!( ?security_package_name) ;
@@ -737,11 +739,13 @@ pub unsafe extern "system" fn InitializeSecurityContextW(
737739 let service_principal = if p_target_name. is_null( ) {
738740 String :: new( )
739741 } else {
740- // SAFETY:
741- // - `p_target_name` is guaranteed to be non-null due to the prior check.
742- // - The memory region `p_target_name` contains a valid null-terminator at the end of string.
743- // - The memory region `p_target_name` points to is valid for reads of bytes up to and including null-terminator.
744- unsafe { c_w_str_to_string( p_target_name) }
742+ try_execute!(
743+ // SAFETY:
744+ // - `p_target_name` is guaranteed to be non-null due to the prior check.
745+ // - The memory region `p_target_name` contains a valid null-terminator at the end of string.
746+ // - The memory region `p_target_name` points to is valid for reads of bytes up to and including null-terminator.
747+ unsafe { c_w_str_to_string( p_target_name) } . map_err( Error :: from)
748+ )
745749 } ;
746750 debug!( ?service_principal, "Target name (SPN)" ) ;
747751
@@ -1334,11 +1338,13 @@ pub unsafe extern "system" fn SetCredentialsAttributesW(
13341338 } ;
13351339
13361340 if ul_attribute == SECPKG_CRED_ATTR_NAMES {
1337- // SAFETY:
1338- // - `p_buffer` is guaranteed to be non-null due to the prior check.
1339- // - The memory region `p_buffer` contains a valid null-terminator at the end of string.
1340- // - The memory region `p_buffer` points to is valid for reads of bytes up to and including null-terminator.
1341- let workstation = unsafe { c_w_str_to_string( p_buffer as * const _) } ;
1341+ let workstation = try_execute!(
1342+ // SAFETY:
1343+ // - `p_buffer` is guaranteed to be non-null due to the prior check.
1344+ // - The memory region `p_buffer` contains a valid null-terminator at the end of string.
1345+ // - The memory region `p_buffer` points to is valid for reads of bytes up to and including null-terminator.
1346+ unsafe { c_w_str_to_string( p_buffer as * const _) } . map_err( Error :: from)
1347+ ) ;
13421348
13431349 credentials_handle. attributes. workstation = Some ( workstation) ;
13441350
@@ -1355,11 +1361,13 @@ pub unsafe extern "system" fn SetCredentialsAttributesW(
13551361 0
13561362 } else if ul_attribute == SECPKG_CRED_ATTR_KDC_URL {
13571363 let cred_attr = p_buffer. cast:: <SecPkgCredentialsKdcUrlW >( ) ;
1358- // SAFETY:
1359- // - `p_buffer` is guaranteed to be non-null due to the prior check.
1360- // - The memory region `p_buffer` contains a valid null-terminator at the end of string.
1361- // - The memory region `p_buffer` points to is valid for reads of bytes up to and including null-terminator.
1362- let kdc_url = unsafe { c_w_str_to_string( ( * cred_attr) . kdc_url. cast_const( ) ) } ;
1364+ let kdc_url = try_execute!(
1365+ // SAFETY:
1366+ // - `p_buffer` is guaranteed to be non-null due to the prior check.
1367+ // - The memory region `p_buffer` contains a valid null-terminator at the end of string.
1368+ // - The memory region `p_buffer` points to is valid for reads of bytes up to and including null-terminator.
1369+ unsafe { c_w_str_to_string( ( * cred_attr) . kdc_url. cast_const( ) ) } . map_err( Error :: from)
1370+ ) ;
13631371 credentials_handle. attributes. kdc_url = Some ( kdc_url) ;
13641372
13651373 0
@@ -1545,32 +1553,42 @@ pub unsafe extern "system" fn ChangeAccountPasswordW(
15451553 check_null!( psz_new_password) ;
15461554 check_null!( p_output) ;
15471555
1548- // SAFETY:
1549- // - `psz_package_name` is guaranteed to be non-null due to the prior check.
1550- // - The memory region `psz_package_name` contains a valid null-terminator at the end of string.
1551- // - The memory region `psz_package_name` points to is valid for reads of bytes up to and including null-terminator.
1552- let mut security_package_name = unsafe { c_w_str_to_string( psz_package_name) } ;
1556+ let mut security_package_name = try_execute!(
1557+ // SAFETY:
1558+ // - `psz_package_name` is guaranteed to be non-null due to the prior check.
1559+ // - The memory region `psz_package_name` contains a valid null-terminator at the end of string.
1560+ // - The memory region `psz_package_name` points to is valid for reads of bytes up to and including null-terminator.
1561+ unsafe { c_w_str_to_string( psz_package_name) } . map_err( Error :: from)
1562+ ) ;
15531563
1554- // SAFETY:
1555- // - `psz_domain_name` is guaranteed to be non-null due to the prior check.
1556- // - The memory region `psz_domain_name` contains a valid null-terminator at the end of string.
1557- // - The memory region `psz_domain_name` points to is valid for reads of bytes up to and including null-terminator.
1558- let mut domain = unsafe { c_w_str_to_string( psz_domain_name) } ;
1559- // SAFETY:
1560- // - `psz_account_name` is guaranteed to be non-null due to the prior check.
1561- // - The memory region `psz_account_name` contains a valid null-terminator at the end of string.
1562- // - The memory region `psz_account_name` points to is valid for reads of bytes up to and including null-terminator.
1563- let mut username = unsafe { c_w_str_to_string( psz_account_name) } ;
1564- // SAFETY:
1565- // - `psz_old_password` is guaranteed to be non-null due to the prior check.
1566- // - The memory region `psz_old_password` contains a valid null-terminator at the end of string.
1567- // - The memory region `psz_old_password` points to is valid for reads of bytes up to and including null-terminator.
1568- let mut password = Secret :: new( unsafe { c_w_str_to_string( psz_old_password) } ) ;
1569- // SAFETY:
1570- // - `psz_new_password` is guaranteed to be non-null due to the prior check.
1571- // - The memory region `psz_new_password` contains a valid null-terminator at the end of string.
1572- // - The memory region `psz_new_password` points to is valid for reads of bytes up to and including null-terminator.
1573- let mut new_password = Secret :: new( unsafe { c_w_str_to_string( psz_new_password) } ) ;
1564+ let mut domain = try_execute!(
1565+ // SAFETY:
1566+ // - `psz_domain_name` is guaranteed to be non-null due to the prior check.
1567+ // - The memory region `psz_domain_name` contains a valid null-terminator at the end of string.
1568+ // - The memory region `psz_domain_name` points to is valid for reads of bytes up to and including null-terminator.
1569+ unsafe { c_w_str_to_string( psz_domain_name) } . map_err( Error :: from)
1570+ ) ;
1571+ let mut username = try_execute!(
1572+ // SAFETY:
1573+ // - `psz_account_name` is guaranteed to be non-null due to the prior check.
1574+ // - The memory region `psz_account_name` contains a valid null-terminator at the end of string.
1575+ // - The memory region `psz_account_name` points to is valid for reads of bytes up to and including null-terminator.
1576+ unsafe { c_w_str_to_string( psz_account_name) } . map_err( Error :: from)
1577+ ) ;
1578+ let mut password = Secret :: new( try_execute!(
1579+ // SAFETY:
1580+ // - `psz_old_password` is guaranteed to be non-null due to the prior check.
1581+ // - The memory region `psz_old_password` contains a valid null-terminator at the end of string.
1582+ // - The memory region `psz_old_password` points to is valid for reads of bytes up to and including null-terminator.
1583+ unsafe { c_w_str_to_string( psz_old_password) } . map_err( Error :: from)
1584+ ) ) ;
1585+ let mut new_password = Secret :: new( try_execute!(
1586+ // SAFETY:
1587+ // - `psz_new_password` is guaranteed to be non-null due to the prior check.
1588+ // - The memory region `psz_new_password` contains a valid null-terminator at the end of string.
1589+ // - The memory region `psz_new_password` points to is valid for reads of bytes up to and including null-terminator.
1590+ unsafe { c_w_str_to_string( psz_new_password) } . map_err( Error :: from)
1591+ ) ) ;
15741592
15751593 // SAFETY:
15761594 // * `security_package_name' is a `String`.
0 commit comments