Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sanitize Reg Entries in SerialPort.GetPortNames (Issue 93240) #93242

Closed
wants to merge 1 commit into from

Conversation

ctacke
Copy link

@ctacke ctacke commented Oct 9, 2023

Fixes: #93240

Edit (@krwq): Using correct syntax so that issue linking works

@ghost ghost added the community-contribution Indicates that the PR has been added by a community member label Oct 9, 2023
@ghost
Copy link

ghost commented Oct 9, 2023

Tagging subscribers to this area: @dotnet/area-system-io
See info in area-owners.md if you want to be subscribed.

Issue Details

Fix for Issue 93240

#93240

Author: ctacke
Assignees: -
Labels:

area-System.IO, community-contribution

Milestone: -

@ghost
Copy link

ghost commented Oct 10, 2023

Tagging subscribers to this area: @dotnet/area-system-io-ports
See info in area-owners.md if you want to be subscribed.

Issue Details

Fix for Issue 93240

#93240

Author: ctacke
Assignees: -
Labels:

community-contribution, area-System.IO.Ports

Milestone: -

Copy link
Member

@adamsitnik adamsitnik left a comment

Choose a reason for hiding this comment

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

@ctacke thank you for your contribution!

The main owner of System.IO.Ports is currently offline, in the meantime I've tagged the owners of Microsoft.Win32.Registry to verify whether it should be fixed here or in the API that IO Ports is simply calling.

result[i] = (string)serialKey.GetValue(result[i]);
// Replace the name in the array with its value, trimming at the first null character if it exists
var temp = (string)serialKey.GetValue(result[i]);
var end = temp.IndexOf('\0');
Copy link
Member

Choose a reason for hiding this comment

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

I am not sure whether we should try to workaround the null characters here. Ideally RegistryKey.GetValueNames should do it out of the box.

@dotnet/area-microsoft-win32 thoughts?

Copy link
Member

Choose a reason for hiding this comment

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

GetValueNames looks like better choice to me. can you please give it try @ctacke ?

Copy link
Author

Choose a reason for hiding this comment

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

I'm not sure what the suggestion is. The Value Name is not the issue, the Value itself is. I can't "try GetValueNames" as a resolution, because it doesn't give the data I need.

You could certainly argue that Registry.GetValue should be stopping at the first null, but I don't know if there are other instances where a null-containing string might be valid data. If null-containing strings are generally considered invalid data for registry entries, then yes, the bug would be in Registry.GetValue

Copy link
Member

Choose a reason for hiding this comment

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

I may be wrong but it seems like this is what the method does e.g. terminates on null (while the GetValue does not)
https://learn.microsoft.com/en-us/dotnet/api/microsoft.win32.registrykey.getvaluenames?view=net-8.0#microsoft-win32-registrykey-getvaluenames

Perhaps @adamsitnik can explain more.

@krwq
Copy link
Member

krwq commented Jan 22, 2024

@ctacke could you please investigate if the recommended API is suitable for usage? I don't have any hardware where I could try this out

@krwq krwq added the needs-author-action An issue or pull request that requires more info or actions from the author. label Jan 22, 2024
@ghost ghost added the no-recent-activity label Feb 5, 2024
@ghost
Copy link

ghost commented Feb 5, 2024

This pull request has been automatically marked no-recent-activity because it has not had any activity for 14 days. It will be closed if no further activity occurs within 14 more days. Any new comment (by anyone, not necessarily the author) will remove no-recent-activity.

@ghost
Copy link

ghost commented Feb 19, 2024

This pull request will now be closed since it had been marked no-recent-activity but received no further activity in the past 14 days. It is still possible to reopen or comment on the pull request, but please note that it will be locked if it remains inactive for another 30 days.

@ghost ghost closed this Feb 19, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Mar 21, 2024
This pull request was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-System.IO.Ports community-contribution Indicates that the PR has been added by a community member needs-author-action An issue or pull request that requires more info or actions from the author. no-recent-activity
Projects
None yet
Development

Successfully merging this pull request may close these issues.

SerialPort.GetPortNames not handling poor registry data
5 participants