fix: CountNameList undercounts leading-comma name-lists#1123
Open
MarkAtwood wants to merge 1 commit into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes an off-by-one allocation sizing bug in CountNameList() that could reject valid (but odd) SSH name-lists with a leading comma (empty first token), which in turn could cause DoExtInfoServerSigAlgs() to fail when parsing server-sig-algs.
Changes:
- Stop discounting a leading comma in
CountNameList()so its computed capacity matches whatGetNameListRaw()can emit. - Preserve the existing behavior of discounting a trailing comma, consistent with
GetNameListRaw()stripping only trailing commas.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
Bug
CountNameList()(src/internal.c) sizes the allocation thatGetNameListRaw()then fills. It discounts both a leading and a trailing comma, but
GetNameListRaw()only strips a trailing comma — it still emits the emptyleading token (the
idListIdx == 0first-token case). For a name-list with aleading comma such as
,ssh-rsa,CountNameList()returns 1 whileGetNameListRaw()needs 2 slots, so the fill hits the capacity guard andreturns
WS_BUFFER_E.The visible effect is in
DoExtInfoServerSigAlgs(), which sizes theserver-sig-algsbuffer fromCountNameList(): a peer advertising aleading-comma / empty-first-element name-list is spuriously rejected and the
connection fails. No memory-safety impact — the capacity guard fails closed.
Fix
Drop the leading-comma discount in
CountNameList().GetNameListRaw()keepsthat first token, so the count must include it. Over-counting an empty leading
element is harmless:
GetNameListRaw()caps writes at the capacity and rewritesthe caller's size to the actual filled count.
Verification
Built
--enable-allagainst wolfSSL master; compiles clean. Traced,ssh-rsa,ssh-rsa,ssh-dss(normal, unaffected), and,,ssh-rsa(harmless over-alloc)by hand against
GetNameListRaw.Reported by static analysis (Fenrir finding F-6817). Distinct from the
trailing-comma name-list issue tracked separately.