fix: stop AttributesFromDSN panicking on unix-socket DSNs#625
Open
fix: stop AttributesFromDSN panicking on unix-socket DSNs#625
Conversation
AttributesFromDSN first split the DSN on the first '/' to drop the
database/params suffix, and then unwrapped any protocol(addr) form by
taking dsn[openParen+1 : len(dsn)-1]. That ordering is safe for most
addresses but breaks as soon as the address itself contains a slash:
unix(/tmp/mysql.sock)/mysql?parseTime=true
The '/' split happens inside the parentheses, truncating dsn to
`unix(`. The protocol unwrap then computes [openParen+1 : len(dsn)-1]
= [5:4], which panics with slice bounds out of range (XSAM#624).
Extract the protocol(addr) address first by reading between the
matching parens, and only fall back to the first-'/' trim on bare
addresses. This makes the unix-socket case round-trip to
semconv.ServerAddress("/tmp/mysql.sock") and leaves every
existing test case unchanged.
Fixes XSAM#624
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #625 +/- ##
=====================================
Coverage 86.4% 86.4%
=====================================
Files 16 16
Lines 752 752
=====================================
Hits 650 650
Misses 75 75
Partials 27 27 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #624.
AttributesFromDSNfirst split the DSN on the first/to drop the database/params suffix, and then unwrapped anyprotocol(addr)form by takingdsn[openParen+1 : len(dsn)-1]. That ordering is safe for most addresses but breaks as soon as the address itself contains a slash:The
/split happens inside the parentheses, truncatingdsntounix(. The protocol unwrap then computes[openParen+1 : len(dsn)-1]=[5:4], which panics withslice bounds out of range.This PR extracts the
protocol(addr)address first by reading between the matching parens, and only falls back to the first-/trim on bare addresses. That makes the unix-socket case round-trip tosemconv.ServerAddress("/tmp/mysql.sock")and leaves every existing test case unchanged. A regression test is added for the unix-socket DSN.