Skip to content

Fix NullReferenceException in DbConnectionOptions.ConvertValueToBoolean - #131650

Open
pumpkin-bit wants to merge 1 commit into
dotnet:mainfrom
pumpkin-bit:fix/dbconnectionoptions-null-ref
Open

Fix NullReferenceException in DbConnectionOptions.ConvertValueToBoolean#131650
pumpkin-bit wants to merge 1 commit into
dotnet:mainfrom
pumpkin-bit:fix/dbconnectionoptions-null-ref

Conversation

@pumpkin-bit

Copy link
Copy Markdown
Contributor

Problem/bug

In the System.Data.Common component, the DbConnectionOptions class is responsible for parsing connection strings. If a connection string specifies a key without a value, the parser stores that key in the internal _parsetable dictionary with a null value. Inside the ConvertValueToBooleanInternal method, stringValue.Trim() was called; since stringValue was null, the program crashed with an unhandled NullReferenceException instead of throwing the appropriate exception.

The code originally contained a comment: // TODO: Is it possible for _parsetable to contain a null value here? If so there's a bug here, investigate..


Solution

A check was added to ConvertValueToBooleanInternal if stringValue is null, the standard ADP.InvalidConnectionOptionValue(keyName) (ArgumentException) is used immediately. The method signature was changed to accept string? stringValue to explicitly support nullable strings, and an obsolete TODO comment was removed.
A unit test was added to DbConnectionStringBuilderTest.cs to verify handling of empty key values. All tests passed.

@github-actions github-actions Bot added the area-VM-reflection-mono Reflection issues specific to MonoVM label Jul 31, 2026
@dotnet-policy-service dotnet-policy-service Bot added the community-contribution Indicates that the PR has been added by a community member label Jul 31, 2026
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).
13 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@jkotas jkotas added area-System.Data and removed area-VM-reflection-mono Reflection issues specific to MonoVM labels Jul 31, 2026
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-System.Data community-contribution Indicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants