Skip to content

Conversation

@TheBestTvarynka
Copy link
Collaborator

From String::from_utf16_lossy documentation:

Decode a native endian UTF-16–encoded slice v into a String, replacing invalid data with the replacement character (U+FFFD).

String::from_utf16_lossy changes the credentials when the input data is not a UTF-8 valid buffer. We should not do this because it could result in invalid credentials being sent to the target server.

It's either to use String or OsString, but not String::from_utf16_lossy.

@TheBestTvarynka TheBestTvarynka self-assigned this Dec 10, 2025
Comment on lines +113 to +114
})
.map_err(Error::from)?;
Copy link
Member

@CBenoit CBenoit Dec 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: ? should already insert the glue code for the From conversion.

Suggested change
})
.map_err(Error::from)?;
})?;

note: I highly recommend we don’t use some::Result or use some::Error because the naming is confusing at usage sites. I.e.: for clarity, I think it’s better to use explicit sspi::Result and sspi::Error so we have minimal context when reading the code. (This is the suggested style in IronRDP.)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔

Yes, you are right. I do not know why I added it. There may have been a type inference issue at some point, and I forgot to clean up the code afterward.

Comment on lines +481 to -487
*package_list = Some(
String::from_utf16(
// SAFETY: `package_list` is not null due to a prior check.
unsafe {
from_raw_parts(
auth_data.package_list,
usize::try_from(auth_data.package_list_length).unwrap(),
)
},
)
}));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: Thats’ a lot of nested items. We could consider breaking down things a little bit.

use uuid::Uuid;
use winscard::winscard::{CurrentState, ReaderState, WinScardContext};
use winscard::{ErrorKind, ScardContext as PivCardContext, SmartCardInfo, WinScardResult};
use winscard::{Error, ErrorKind, ScardContext as PivCardContext, SmartCardInfo, WinScardResult};
Copy link
Member

@CBenoit CBenoit Dec 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: My preferred style would be to not import Error nor ErrorKind, and avoid as renamings because it’s then not obvious what we are talking about locally.

Copy link
Member

@CBenoit CBenoit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@CBenoit CBenoit merged commit a4889f5 into master Dec 11, 2025
63 checks passed
@CBenoit CBenoit deleted the refactor/remove-from_utf16_lossy-usage branch December 11, 2025 08:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

4 participants