Skip to content

replace stringstream zmq parsing with string construction so we don't rely on null terminated messages#56

Open
marc1uk wants to merge 1 commit into
ToolDAQ:mainfrom
marc1uk:zmqfixes
Open

replace stringstream zmq parsing with string construction so we don't rely on null terminated messages#56
marc1uk wants to merge 1 commit into
ToolDAQ:mainfrom
marc1uk:zmqfixes

Conversation

@marc1uk
Copy link
Copy Markdown
Contributor

@marc1uk marc1uk commented May 12, 2026

std::stringstream expects its input to be null terminated.
Unless we guarantee that all zmq messages received are null terminated, this could lead to the stringstream reading past the end of the message and into arbitrary data, risking segfaulting.
This replaces all instances i could find of std::stringstream for zmq message parsing with a std::string construction that takes the message size. A stringstream is subsequently constructed from this string in the couple of instances where the streamer extraction operator is used.

@marc1uk
Copy link
Copy Markdown
Contributor Author

marc1uk commented May 12, 2026

Just commenting here so as not to forget: this breaks RemoteControl (and potentially other things).
The issue is constructing strings with a length means they may include null characters as part of their data. Subsequently string comparisons if(mystring=="All") fail, because "All\0" != "All".
I think likely what we want is something that constructs a string from either the number of bytes specified by the zmq message, or the number of bytes until there's a null, whichever is less.
This is easily done with two steps:

std::string val(static_cast<char*>(msg.data()),msg.size());
val = val.c_str();  // or val = val.substr(0,val.find('\0'));

but it would be good to do this in one step if possible.

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