RE: [Quickfix-developers] Field with embedded null character
Brought to you by:
orenmnero
From: Yihu F. <Yih...@re...> - 2004-10-28 20:55:05
|
Hi, Actually I am thinking what if a FIX engine sends a FIX message which has embedded null character. After the message read off the socket (which is a character array), the rest of the code is using STL string to represent the message. A null character will basically truncate the string. For example, this message with an extra null in 55=3DIBM<null><soh> =20 8=3DFIX.4.0<soh>9=3D71<soh>35=3DD<soh>49=3DFIRM0<soh>56=3DFIRM1<soh>11=3D12= 3<soh>21=3D 1<soh>38=3D456<soh>40=3D2<soh>44=3D789<soh>54=3D1<soh>55=3DIBM<null><soh>59= =3D0<soh> 10=3D157<soh> In Parser::readFixMessage, extractLength will extract the length of the message which is larger than m_buffer.size() because m_buffer is a string and the null character terminate the string in the middle of the message. This will in turn drop the whole character buffer in ThreadedSocketConnection::readQueue() even if the buffer could have a multiple FIX message in it. There is no exception or error log in such a scenario. How should QF handle this case? Thanks. -Yihu -----Original Message----- From: Caleb Epstein [mailto:cal...@gm...]=20 Sent: Thursday, October 28, 2004 9:06 AM To: Yihu Fang Cc: qui...@li...; Oren Miller Subject: Re: [Quickfix-developers] Field with embedded null character On Wed, 27 Oct 2004 21:23:04 -0400, Yihu Fang <yih...@re...> wrote: > However, in QuickFIX message constructor, it takes string as the parameter. > It will throw an invalid message exception because it thinks the string is > truncated at the null character and cannot find the Tag 10.=20 Make sure you construct the string you pass to the Message constructor properly. The std::string constructor can take a const char* with or without a length. If you don't pass the length, it'll stop at the first embedded \0 and you'll end up with a truncated message. That said, it does seem that QuickFIX has a bug in the message serialization code when dealing with fields having embedded \0 bytes: #include <quickfix/Message.h> #include <iostream> using namespace FIX; using namespace std; int main () { Message m; m.setField (1000, string ("one\0", 4)); cout << m.toString () << endl; cout << m.getField (1000) << endl; } Gives the output (where ^A =3D ASCII SOH and \0 is an ASCII NULL) 9=3D10^A1000=3D one^A10=3D057^A one\0 Note extra space and lack of \0 for serialized message form. --=20 Caleb Epstein cal...@gm... ----------------------------------------------------------------- Visit our Internet site at http://www.reuters.com Get closer to the financial markets with Reuters Messaging - for more information and to register, visit http://www.reuters.com/messaging Any views expressed in this message are those of the individual sender, except where the sender specifically states them to be the views of Reuters Ltd. |