Skip to content

fix: initialize Message sections in ParseMessageWithDataDictionary#759

Open
SAY-5 wants to merge 1 commit into
quickfixgo:mainfrom
SAY-5:fix/parse-message-zero-value-panic
Open

fix: initialize Message sections in ParseMessageWithDataDictionary#759
SAY-5 wants to merge 1 commit into
quickfixgo:mainfrom
SAY-5:fix/parse-message-zero-value-panic

Conversation

@SAY-5
Copy link
Copy Markdown

@SAY-5 SAY-5 commented May 25, 2026

Fixes #390.

Bug

ParseMessage and ParseMessageWithDataDictionary accept a *Message
pointer but do not call Init() on the provided message. FieldMap
stores its mutex as *sync.RWMutex (a pointer), which is nil for a
zero-value struct. When doParsing immediately tries to lock that
mutex it panics:

panic: runtime error: invalid memory address or nil pointer dereference
        sync.(*RWMutex).Lock(0x0)
        github.com/quickfixgo/quickfix.doParsing [...]

This affects any caller that takes the natural approach of declaring a
local variable and passing its address:

var msg quickfix.Message
err := quickfix.ParseMessage(&msg, rawMsg) // panics

Fix

In ParseMessageWithDataDictionary, check each section's rwLock
before entering doParsing. If it is nil, call the section's
Init(). This matches what NewMessage() already does and is
idempotent for callers that pass an already-initialised message.

Verification

TestParseMessageZeroValue (added in parse_nil_test.go) panics
without the fix and passes with it. All existing tests continue to pass
with -race:

ok  github.com/quickfixgo/quickfix  14.172s

A zero-value Message has nil rwLock pointers in its Header, Body, and
Trailer FieldMap fields because those pointers are only set by Init().
Calling ParseMessage with a stack-allocated Message panics immediately
when doParsing tries to lock those nil mutexes.

Guard each section in ParseMessageWithDataDictionary: if rwLock is nil
call the section's Init() before entering doParsing. This matches the
pattern already used by NewMessage() and keeps re-initialisation cheap
for callers that reuse an already-initialised Message.

Closes quickfixgo#390

Signed-off-by: Sai Asish Y <say.apm35@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ParseMessage panic: assignment to entry in nil map quickfix v0.6.0

1 participant