Skip to content

Conversation

liss-h
Copy link
Collaborator

@liss-h liss-h commented Mar 31, 2025

Fixes a SEGFAULT caused by invalid va_list usage.

Bug Description

Serd's API is written in terms of vprintf compatibility (i.e. you need to generate the message via v*printf* and char const *fmt, va_list args)

Since we want to put the message in a buffer instead of printing it directly, we are using vsnprintf. This involves two calls to vsnprintf, one to figure out how big the buffer should be and another one to actually fill the buffer with the message. As it turns out the first call to vsnprintf consumed the va_list, therefore the second call to vsnprintf would overread into garbage. Sometimes this overread would just produce garbage messages, sometimes it would trigger a SEGFAULT.

Fix

We just need to va_copy the list for the first call. Additionally, I added some more stuff to make the code more robust.

@bigerl bigerl self-requested a review March 31, 2025 09:05
Copy link
Collaborator

@bigerl bigerl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thx for the PR. Changes look good. This was a sneaky one!

@liss-h liss-h merged commit 47e9781 into develop Apr 1, 2025
20 checks passed
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.

2 participants