The analysis focused on the vulnerability description and the provided commit diffs. The primary vulnerability, as described in the CVE summary (GHSA-x9vc-6hfv-hg8c), is an integer overflow in the WriteBind method within Npgsql.Internal.NpgsqlConnector.FrontendMessages.cs. This occurs when summing parameter lengths into an int variable, leading to an incorrect message size being written, which enables SQL injection. The commit patches clearly show modifications in WriteBind to mitigate this, primarily by introducing a call to WriteBuffer.StartMessage() which adds message length validation. This function is identified with high confidence.
Additionally, the patches for Npgsql.Internal.NpgsqlWriteBuffer.cs revealed changes in the DirectWrite method. Specifically, length calculations like buffer.Length + 4 were wrapped in checked() blocks, and StartMessage() calls were added. This indicates that DirectWrite also had a potential integer overflow vulnerability when calculating message lengths for direct byte writes, which was fixed concurrently. This function is identified with medium confidence as it's not the primary focus of the CVE description but is evident from the patch code.
Other Write* methods in NpgsqlConnector.FrontendMessages.cs were also modified to include WriteBuffer.StartMessage(). While this indicates a broad application of the mitigation strategy, the vulnerability description specifically attributes the exploitable overflow to the parameter length summation logic within WriteBind.
| Package Name | Ecosystem | Vulnerable Versions | First Patched Version |
|---|---|---|---|
| Npgsql | nuget | >= 8.0.0, < 8.0.3 | 8.0.3 |
| Npgsql | nuget | <= 4.0.13 | 4.0.14 |
| Npgsql | nuget | >= 4.1.0, < 4.1.13 | 4.1.13 |
| Npgsql | nuget | >= 5.0.0, < 5.0.18 | 5.0.18 |
| Npgsql | nuget | >= 6.0.0, < 6.0.11 | 6.0.11 |
| Npgsql | nuget | >= 7.0.0, < 7.0.7 | 7.0.7 |