[zeromq-dev] ZMQ appends weird characters to message

Dávid Kaya mail at davidkaya.sk
Mon Sep 15 19:44:42 CEST 2014


Oh thanks a lot, didn't know this. So the correct way would be to have 
one pointer to message_t as a member of my class and before every send() 
I should rebuild it and delete it manually when I am done with the 
socket, right? Or should I have (message_t*) for every message I use?

On 15.09.2014 19:30, Thomas Rodgers wrote:
> Message goes out of scope, destructor called, receiving side is
> getting a pointer to a free'd heap block.
>
> On Mon, Sep 15, 2014 at 10:27 AM, Dávid Kaya  wrote:
>
>> Here is that function: http://pastebin.com/AgUuDqqK [1] .
>>
>> On 15.09.2014 19:19, gonzalo diethelm wrote:
>> > Without seeing any actual code, it is impossible to say.
>> >
>> > --
>> > Gonzalo Diethelm
>> > DCV Chile
>> >
>> >> -----Original Message-----
>> >> From: zeromq-dev-bounces at lists.zeromq.org [2]
>> [mailto:zeromq-dev- [3]
>> >> bounces at lists.zeromq.org [4]] On Behalf Of Dávid Kaya
>> >> Sent: Monday, September 15, 2014 2:18 PM
>> >> To: ZeroMQ development list
>> >> Subject: Re: [zeromq-dev] ZMQ appends weird characters to
>> message
>> >>
>> >> If it would be because of memory, the std::string.replace()
>> would
>> >> not fix,
>> >> would it? Everything is done in one function, I don't think this
>> is
>> >> the problem.
>> >>
>> >>
>> >> On 15.09.2014 19:11, gonzalo diethelm wrote:
>> >> > That usually happens... Try to focus on the differences
>> between
>> >> your
>> >> > short example and your real code.
>> >> >
>> >> > One point to focus on could be memory management: are you sure
>> the
>> >> > messages you are sending are actually surviving until they get
>> >> sent?
>> >> > A
>> >> > simple wrong way to manage this would be putting your messages
>> in
>> >> an
>> >> > automatic variable that gets overwritten when you leave the
>> >> function
>> >> > that sends the message. Another wrong way would be using a
>> static
>> >> > buffer for your messages, that gets overwritten with each
>> message.
>> >> >
>> >> > HTH.
>> >> >
>> >> > --
>> >> > Gonzalo Diethelm
>> >> > DCV Chile
>> >> >
>> >> >> -----Original Message-----
>> >> >> From: zeromq-dev-bounces at lists.zeromq.org [5]
>> [mailto:zeromq-dev- [6]
>> >> >> bounces at lists.zeromq.org [7]] On Behalf Of Dávid Kaya
>> >> >> Sent: Monday, September 15, 2014 2:02 PM
>> >> >> To: ZeroMQ development list
>> >> >> Subject: Re: [zeromq-dev] ZMQ appends weird characters to
>> message
>> >> >>
>> >> >> Well I tried to recreate the problem but it works as intended
>> in
>> >> my
>> >> >> short example. I really don't know where could be the problem
>> >> since I
>> >> >> am doing it exactly the same way in my example as in my
>> >> application.
>> >> >> Maybe the problem is in the std::string, because when I use
>> >> >> std::string.replace() to replace some characters in the URL
>> then
>> >> it
>> >> >> works fine.
>> >> >> But when I dont use it and append the URL to "success:"
>> >> >> message right away, then it does not work. So maybe
>> >> >> std::string.replace() somehow fixes the string when it
>> rearranges
>> >> it.
>> >> >> The first problem with "login" was because I wasn't using
>> size()
>> >> in
>> >> >> string constructor.
>> >> >>
>> >> >> David
>> >> >>
>> >> >> On 15.09.2014 17:56, gonzalo diethelm wrote:
>> >> >> > Please create a short (as short as possible) example that
>> shows
>> >> >> this
>> >> >> > symptom, and post it to the list.
>> >> >> >
>> >> >> > --
>> >> >> > Gonzalo Diethelm
>> >> >> > DCV Chile
>> >> >> >
>> >> >> >> -----Original Message-----
>> >> >> >> From: zeromq-dev-bounces at lists.zeromq.org [8]
>> [mailto:zeromq-dev- [9]
>> >> >> >> bounces at lists.zeromq.org [10]] On Behalf Of Dávid Kaya
>> >> >> >> Sent: Monday, September 15, 2014 12:39 PM
>> >> >> >> To: ZeroMQ development list
>> >> >> >> Subject: Re: [zeromq-dev] ZMQ appends weird characters to
>> >> message
>> >> >> >>
>> >> >> >> Yes, I've printed that message. There can't be any NULL
>> byte
>> >> >> there.
>> >> >> >> It is string
>> >> >> >> "success:" appended with url. It is normal url like
>> >> >> >> "http://example.org/path/to/jsp?lang=en_US?session=
>> [11]"session id
>> >> >> here".
>> >> >> >> That session ID contains numbers, characters and dashes.
>> >> >> >>
>> >> >> >>
>> >> >> >> On 15.09.2014 17:30, gonzalo diethelm wrote:
>> >> >> >> > No, this is not a (known) limitation. Did you print
>> exactly
>> >> >> what
>> >> >> >> you
>> >> >> >> > are sending and what you are receiving? My guess is you
>> are
>> >> >> >> putting a
>> >> >> >> > null byte in the middle of what you are sending.
>> >> >> >> >
>> >> >> >> > --
>> >> >> >> > Gonzalo Diethelm
>> >> >> >> > DCV Chile
>> >> >> >> >
>> >> >> >> >> -----Original Message-----
>> >> >> >> >> From: zeromq-dev-bounces at lists.zeromq.org [12]
>> >> [mailto:zeromq-dev- [13]
>> >> >> >> >> bounces at lists.zeromq.org [14]] On Behalf Of Dávid Kaya
>> >> >> >> >> Sent: Monday, September 15, 2014 12:21 PM
>> >> >> >> >> To: zeromq-dev at lists.zeromq.org [15]
>> >> >> >> >> Subject: Re: [zeromq-dev] ZMQ appends weird characters
>> to
>> >> >> message
>> >> >> >> >>
>> >> >> >> >> Well, I've printed out size and it is correct. I've
>> also
>> >> >> >> shortened
>> >> >> >> >> the message by 5 characters and it stopped cutting off
>> the
>> >> >> last
>> >> >> >> >> characters (atleast I think it stopped, tried 15 times
>> and
>> >> it
>> >> >> >> came
>> >> >> >> >> correct every time). So I think the problem was in the
>> >> length
>> >> >> of
>> >> >> >> the
>> >> >> >> >> message. I don't know if it is a bug in ZMQ or system
>> >> >> limitation
>> >> >> >> of
>> >> >> >> >> socket files?
>> >> >> >> >>
>> >> >> >> >> David
>> >> >> >> >>
>> >> >> >> >>
>> >> >> >> >> On 15.09.2014 16:47, gonzalo diethelm wrote:
>> >> >> >> >> > Good point. Forgot about the specific details for
>> that
>> >> C++
>> >> >> >> >> > constructor. The null byte should not be required.
>> >> >> >> >> >
>> >> >> >> >> > As Tom points out, you should print out what you are
>> >> sending
>> >> >> >> and
>> >> >> >> >> > receiving (contents and length) and make sure it
>> makes
>> >> >> sense.
>> >> >> >> >> >
>> >> >> >> >> > HTH.
>> >> >> >> >> >
>> >> >> >> >> > --
>> >> >> >> >> > Gonzalo Diethelm
>> >> >> >> >> > DCV Chile
>> >> >> >> >> >
>> >> >> >> >> >> -----Original Message-----
>> >> >> >> >> >> From: zeromq-dev-bounces at lists.zeromq.org [16]
>> >> >> [mailto:zeromq-dev- [17]
>> >> >> >> >> >> bounces at lists.zeromq.org [18]] On Behalf Of Tom
>> Quarendon
>> >> >> >> >> >> Sent: Monday, September 15, 2014 11:42 AM
>> >> >> >> >> >> To: ZeroMQ development list
>> >> >> >> >> >> Subject: Re: [zeromq-dev] ZMQ appends weird
>> characters
>> >> to
>> >> >> >> message
>> >> >> >> >> >>
>> >> >> >> >> >> > You have two choices:
>> >> >> >> >> >> > 1. Send the '' as part of the message (and set
>> >> length
>> >> >> to
>> >> >> >> one
>> >> >> >> >> >> more byte).
>> >> >> >> >> >> > 2. Append a '' after receiving the message.
>> >> >> >> >> >>
>> >> >> >> >> >> Uh, why?
>> >> >> >> >> >> string(static_cast(reply.data()),reply.size());
>> >> >> >> >> >> doesn't assume the string is null terminated. It
>> >> constructs
>> >> >> >> >> string
>> >> >> >> >> >> from pointer and length. Isn't adding a in a null
>> just
>> >> >> going
>> >> >> >> mask
>> >> >> >> >> the
>> >> >> >> >> >> real issue and make it look like the std::string
>> only
>> >> >> >> contained
>> >> >> >> >> >> "login" when really it still contained the extra
>> stuff
>> >> as
>> >> >> >> well.
>> >> >> >> >> >> David, Do you know what reply.size() actually
>> contains?
>> >> >> Have
>> >> >> >> you
>> >> >> >> >> >> tried printing that out and comparing it to what you
>> >> >> expect?
>> >> >> >> >> >>
>> >> >> >> >> >> _______________________________________________
>> >> >> >> >> >> zeromq-dev mailing list
>> >> >> >> >> >> zeromq-dev at lists.zeromq.org [19]
>> >> >> >> >> >> http://lists.zeromq.org/mailman/listinfo/zeromq-dev
>> [20]
>> >> >> >> >> >
>> >> >> >> >> >
>> >> >> >> >> > -----------------------------------------
>> >> >> >> >> > Declaración de confidencialidad: Este Mensaje esta
>> >> destinado
>> >> >> >> para
>> >> >> >> >> el
>> >> >> >> >> > uso de la o las personas o entidades a quien ha sido
>> >> >> dirigido y
>> >> >> >> >> puede
>> >> >> >> >> > contener información reservada y confidencial que no
>> >> puede
>> >> >> ser
>> >> >> >> >> > divulgada, difundida, ni aprovechada en forma alguna.
>> El
>> >> uso
>> >> >> no
>> >> >> >> >> > autorizado de la información contenida en este
>> correo
>> >> podrá
>> >> >> ser
>> >> >> >> >> > sancionado de conformidad con la ley chilena.
>> >> >> >> >> > Si usted ha recibido este correo electrónico por
>> error,
>> >> le
>> >> >> >> pedimos
>> >> >> >> >> > eliminarlo junto con los archivos adjuntos y avisar
>> >> >> >> inmediatamente
>> >> >> >> >> al
>> >> >> >> >> > remitente, respondiendo este mensaje.
>> >> >> >> >> >
>> >> >> >> >> > "Before printing this e-mail think if is really
>> >> necesary".
>> >> >> >> >> > Disclosure: This Message is to be used by the
>> individual,
>> >> >> >> >> individuals
>> >> >> >> >> > or entities that it is addressed to and may include
>> >> private
>> >> >> and
>> >> >> >> >> > confidential information that may not be disclosed,
>> made
>> >> >> public
>> >> >> >> >> nor
>> >> >> >> >> > used in any way at all. Unauthorized use of the
>> >> information
>> >> >> in
>> >> >> >> >> this
>> >> >> >> >> > electronic mail message may be subject to the
>> penalties
>> >> set
>> >> >> >> forth
>> >> >> >> >> by
>> >> >> >> >> > Chilean law.
>> >> >> >> >> > If you have received this electronic mail message in
>> >> error,
>> >> >> we
>> >> >> >> ask
>> >> >> >> >> you
>> >> >> >> >> > to destroy the message and its attached file(s) and
>> to
>> >> >> >> immediately
>> >> >> >> >> > notify the sender by answering this message.
>> >> >> >> >> > _______________________________________________
>> >> >> >> >> > zeromq-dev mailing list
>> >> >> >> >> > zeromq-dev at lists.zeromq.org [21]
>> >> >> >> >> > http://lists.zeromq.org/mailman/listinfo/zeromq-dev
>> [22]
>> >> >> >> >>
>> >> >> >> >> _______________________________________________
>> >> >> >> >> zeromq-dev mailing list
>> >> >> >> >> zeromq-dev at lists.zeromq.org [23]
>> >> >> >> >> http://lists.zeromq.org/mailman/listinfo/zeromq-dev
>> [24]
>> >> >> >> >
>> >> >> >> > -----------------------------------------
>> >> >> >> > Declaración de confidencialidad: Este Mensaje esta
>> destinado
>> >> >> para
>> >> >> >> el
>> >> >> >> > uso de la o las personas o entidades a quien ha sido
>> >> dirigido y
>> >> >> >> puede
>> >> >> >> > contener información reservada y confidencial que no
>> puede
>> >> ser
>> >> >> >> > divulgada, difundida, ni aprovechada en forma alguna. El
>> uso
>> >> no
>> >> >> >> > autorizado de la información contenida en este correo
>> podrá
>> >> ser
>> >> >> >> > sancionado de conformidad con la ley chilena.
>> >> >> >> > Si usted ha recibido este correo electrónico por error,
>> le
>> >> >> pedimos
>> >> >> >> > eliminarlo junto con los archivos adjuntos y avisar
>> >> >> inmediatamente
>> >> >> >> al
>> >> >> >> > remitente, respondiendo este mensaje.
>> >> >> >> >
>> >> >> >> > "Before printing this e-mail think if is really
>> necesary".
>> >> >> >> > Disclosure: This Message is to be used by the
>> individual,
>> >> >> >> individuals
>> >> >> >> > or entities that it is addressed to and may include
>> private
>> >> and
>> >> >> >> > confidential information that may not be disclosed, made
>> >> public
>> >> >> >> nor
>> >> >> >> > used in any way at all. Unauthorized use of the
>> information
>> >> in
>> >> >> >> this
>> >> >> >> > electronic mail message may be subject to the penalties
>> set
>> >> >> forth
>> >> >> >> by
>> >> >> >> > Chilean law.
>> >> >> >> > If you have received this electronic mail message in
>> error,
>> >> we
>> >> >> ask
>> >> >> >> you
>> >> >> >> > to destroy the message and its attached file(s) and to
>> >> >> immediately
>> >> >> >> > notify the sender by answering this message.
>> >> >> >> > _______________________________________________
>> >> >> >> > zeromq-dev mailing list
>> >> >> >> > zeromq-dev at lists.zeromq.org [25]
>> >> >> >> > http://lists.zeromq.org/mailman/listinfo/zeromq-dev [26]
>> >> >> >>
>> >> >> >> _______________________________________________
>> >> >> >> zeromq-dev mailing list
>> >> >> >> zeromq-dev at lists.zeromq.org [27]
>> >> >> >> http://lists.zeromq.org/mailman/listinfo/zeromq-dev [28]
>> >> >> > _______________________________________________
>> >> >> > zeromq-dev mailing list
>> >> >> > zeromq-dev at lists.zeromq.org [29]
>> >> >> > http://lists.zeromq.org/mailman/listinfo/zeromq-dev [30]
>> >> >>
>> >> >> _______________________________________________
>> >> >> zeromq-dev mailing list
>> >> >> zeromq-dev at lists.zeromq.org [31]
>> >> >> http://lists.zeromq.org/mailman/listinfo/zeromq-dev [32]
>> >> >
>> >> > -----------------------------------------
>> >> > Declaración de confidencialidad: Este Mensaje esta destinado
>> para
>> >> el
>> >> > uso de la o las personas o entidades a quien ha sido dirigido
>> y
>> >> puede
>> >> > contener información reservada y confidencial que no puede
>> ser
>> >> > divulgada, difundida, ni aprovechada en forma alguna. El uso
>> no
>> >> > autorizado de la información contenida en este correo podrá
>> ser
>> >> > sancionado de conformidad con la ley chilena.
>> >> > Si usted ha recibido este correo electrónico por error, le
>> pedimos
>> >> > eliminarlo junto con los archivos adjuntos y avisar
>> inmediatamente
>> >> al
>> >> > remitente, respondiendo este mensaje.
>> >> >
>> >> > "Before printing this e-mail think if is really necesary".
>> >> > Disclosure: This Message is to be used by the individual,
>> >> individuals
>> >> > or entities that it is addressed to and may include private
>> and
>> >> > confidential information that may not be disclosed, made
>> public
>> >> nor
>> >> > used in any way at all. Unauthorized use of the information in
>> >> this
>> >> > electronic mail message may be subject to the penalties set
>> forth
>> >> by
>> >> > Chilean law.
>> >> > If you have received this electronic mail message in error, we
>> ask
>> >> you
>> >> > to destroy the message and its attached file(s) and to
>> immediately
>> >> > notify the sender by answering this message.
>> >> > _______________________________________________
>> >> > zeromq-dev mailing list
>> >> > zeromq-dev at lists.zeromq.org [33]
>> >> > http://lists.zeromq.org/mailman/listinfo/zeromq-dev [34]
>> >>
>> >> _______________________________________________
>> >> zeromq-dev mailing list
>> >> zeromq-dev at lists.zeromq.org [35]
>> >> http://lists.zeromq.org/mailman/listinfo/zeromq-dev [36]
>> >
>> > -----------------------------------------
>> > Declaración de confidencialidad: Este Mensaje esta destinado
>> para
>> > el uso de la o las personas o entidades a quien ha sido dirigido
>> y
>> > puede contener información reservada y confidencial que no puede
>> > ser divulgada, difundida, ni aprovechada en forma alguna. El uso
>> no
>> > autorizado de la información contenida en este correo podrá ser
>> > sancionado de conformidad con la ley chilena.
>> > Si usted ha recibido este correo electrónico por error, le
>> pedimos
>> > eliminarlo junto con los archivos adjuntos y avisar
>> inmediatamente
>> > al remitente, respondiendo este mensaje.
>> >
>> > "Before printing this e-mail think if is really necesary".
>> > Disclosure: This Message is to be used by the individual,
>> > individuals or entities that it is addressed to and may include
>> > private and confidential information that may not be disclosed,
>> > made public nor used in any way at all. Unauthorized use of the
>> > information in this electronic mail message may be subject to the
>> > penalties set forth by Chilean law.
>> > If you have received this electronic mail message in error, we
>> ask
>> > you to destroy the message and its attached file(s) and to
>> > immediately notify the sender by answering this message.
>> > _______________________________________________
>> > zeromq-dev mailing list
>> > zeromq-dev at lists.zeromq.org [37]
>> > http://lists.zeromq.org/mailman/listinfo/zeromq-dev [38]
>>
>> _______________________________________________
>> zeromq-dev mailing list
>> zeromq-dev at lists.zeromq.org [39]
>> http://lists.zeromq.org/mailman/listinfo/zeromq-dev [40]
>
>
>
> Links:
> ------
> [1] http://pastebin.com/AgUuDqqK
> [2] mailto:zeromq-dev-bounces at lists.zeromq.org
> [3] mailto:zeromq-dev-
> [4] mailto:bounces at lists.zeromq.org
> [5] mailto:zeromq-dev-bounces at lists.zeromq.org
> [6] mailto:zeromq-dev-
> [7] mailto:bounces at lists.zeromq.org
> [8] mailto:zeromq-dev-bounces at lists.zeromq.org
> [9] mailto:zeromq-dev-
> [10] mailto:bounces at lists.zeromq.org
> [11] http://example.org/path/to/jsp?lang=en_US?session=
> [12] mailto:zeromq-dev-bounces at lists.zeromq.org
> [13] mailto:zeromq-dev-
> [14] mailto:bounces at lists.zeromq.org
> [15] mailto:zeromq-dev at lists.zeromq.org
> [16] mailto:zeromq-dev-bounces at lists.zeromq.org
> [17] mailto:zeromq-dev-
> [18] mailto:bounces at lists.zeromq.org
> [19] mailto:zeromq-dev at lists.zeromq.org
> [20] http://lists.zeromq.org/mailman/listinfo/zeromq-dev
> [21] mailto:zeromq-dev at lists.zeromq.org
> [22] http://lists.zeromq.org/mailman/listinfo/zeromq-dev
> [23] mailto:zeromq-dev at lists.zeromq.org
> [24] http://lists.zeromq.org/mailman/listinfo/zeromq-dev
> [25] mailto:zeromq-dev at lists.zeromq.org
> [26] http://lists.zeromq.org/mailman/listinfo/zeromq-dev
> [27] mailto:zeromq-dev at lists.zeromq.org
> [28] http://lists.zeromq.org/mailman/listinfo/zeromq-dev
> [29] mailto:zeromq-dev at lists.zeromq.org
> [30] http://lists.zeromq.org/mailman/listinfo/zeromq-dev
> [31] mailto:zeromq-dev at lists.zeromq.org
> [32] http://lists.zeromq.org/mailman/listinfo/zeromq-dev
> [33] mailto:zeromq-dev at lists.zeromq.org
> [34] http://lists.zeromq.org/mailman/listinfo/zeromq-dev
> [35] mailto:zeromq-dev at lists.zeromq.org
> [36] http://lists.zeromq.org/mailman/listinfo/zeromq-dev
> [37] mailto:zeromq-dev at lists.zeromq.org
> [38] http://lists.zeromq.org/mailman/listinfo/zeromq-dev
> [39] mailto:zeromq-dev at lists.zeromq.org
> [40] http://lists.zeromq.org/mailman/listinfo/zeromq-dev
> [41] mailto:mail at davidkaya.sk




More information about the zeromq-dev mailing list