Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
L
libzmq
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
libzmq
Commits
71bef330
Commit
71bef330
authored
Oct 23, 2010
by
Dhammika Pathirana
Committed by
Martin Sustrik
Oct 23, 2010
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
handle decoding malformed messages
Signed-off-by:
Dhammika Pathirana
<
dhammika@gmail.com
>
parent
8d697992
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
53 additions
and
22 deletions
+53
-22
decoder.cpp
src/decoder.cpp
+18
-8
decoder.hpp
src/decoder.hpp
+19
-4
zmq_engine.cpp
src/zmq_engine.cpp
+16
-10
No files found.
src/decoder.cpp
View file @
71bef330
...
@@ -54,16 +54,22 @@ bool zmq::decoder_t::one_byte_size_ready ()
...
@@ -54,16 +54,22 @@ bool zmq::decoder_t::one_byte_size_ready ()
next_step
(
tmpbuf
,
8
,
&
decoder_t
::
eight_byte_size_ready
);
next_step
(
tmpbuf
,
8
,
&
decoder_t
::
eight_byte_size_ready
);
else
{
else
{
// TODO: Handle over-sized message decently.
// There has to be at least one byte (the flags) in the message).
// There has to be at least one byte (the flags) in the message).
zmq_assert
(
*
tmpbuf
>
0
);
if
(
!*
tmpbuf
)
{
decoding_error
();
return
false
;
}
// in_progress is initialised at this point so in theory we should
// in_progress is initialised at this point so in theory we should
// close it before calling zmq_msg_init_size, however, it's a 0-byte
// close it before calling zmq_msg_init_size, however, it's a 0-byte
// message and thus we can treat it as uninitialised...
// message and thus we can treat it as uninitialised...
int
rc
=
zmq_msg_init_size
(
&
in_progress
,
*
tmpbuf
-
1
);
int
rc
=
zmq_msg_init_size
(
&
in_progress
,
*
tmpbuf
-
1
);
if
(
rc
!=
0
&&
errno
==
ENOMEM
)
{
decoding_error
();
return
false
;
}
errno_assert
(
rc
==
0
);
errno_assert
(
rc
==
0
);
next_step
(
tmpbuf
,
1
,
&
decoder_t
::
flags_ready
);
next_step
(
tmpbuf
,
1
,
&
decoder_t
::
flags_ready
);
}
}
return
true
;
return
true
;
...
@@ -75,19 +81,23 @@ bool zmq::decoder_t::eight_byte_size_ready ()
...
@@ -75,19 +81,23 @@ bool zmq::decoder_t::eight_byte_size_ready ()
// read the message data into it.
// read the message data into it.
size_t
size
=
(
size_t
)
get_uint64
(
tmpbuf
);
size_t
size
=
(
size_t
)
get_uint64
(
tmpbuf
);
// TODO: Handle over-sized message decently.
// There has to be at least one byte (the flags) in the message).
// There has to be at least one byte (the flags) in the message).
zmq_assert
(
size
>
0
);
if
(
!
size
)
{
decoding_error
();
return
false
;
}
// in_progress is initialised at this point so in theory we should
// in_progress is initialised at this point so in theory we should
// close it before calling zmq_msg_init_size, however, it's a 0-byte
// close it before calling zmq_msg_init_size, however, it's a 0-byte
// message and thus we can treat it as uninitialised...
// message and thus we can treat it as uninitialised...
int
rc
=
zmq_msg_init_size
(
&
in_progress
,
size
-
1
);
int
rc
=
zmq_msg_init_size
(
&
in_progress
,
size
-
1
);
if
(
rc
!=
0
&&
errno
==
ENOMEM
)
{
decoding_error
();
return
false
;
}
errno_assert
(
rc
==
0
);
errno_assert
(
rc
==
0
);
next_step
(
tmpbuf
,
1
,
&
decoder_t
::
flags_ready
);
next_step
(
tmpbuf
,
1
,
&
decoder_t
::
flags_ready
);
return
true
;
return
true
;
}
}
...
...
src/decoder.hpp
View file @
71bef330
...
@@ -98,9 +98,13 @@ namespace zmq
...
@@ -98,9 +98,13 @@ namespace zmq
read_pos
+=
size_
;
read_pos
+=
size_
;
to_read
-=
size_
;
to_read
-=
size_
;
while
(
!
to_read
)
while
(
!
to_read
)
{
if
(
!
(
static_cast
<
T
*>
(
this
)
->*
next
)
())
if
(
!
(
static_cast
<
T
*>
(
this
)
->*
next
)
())
{
if
(
unlikely
(
!
(
static_cast
<
T
*>
(
this
)
->
next
)))
return
(
size_t
)
-
1
;
return
size_
;
return
size_
;
}
}
return
size_
;
return
size_
;
}
}
...
@@ -109,9 +113,13 @@ namespace zmq
...
@@ -109,9 +113,13 @@ namespace zmq
// Try to get more space in the message to fill in.
// Try to get more space in the message to fill in.
// If none is available, return.
// If none is available, return.
while
(
!
to_read
)
while
(
!
to_read
)
{
if
(
!
(
static_cast
<
T
*>
(
this
)
->*
next
)
())
if
(
!
(
static_cast
<
T
*>
(
this
)
->*
next
)
())
{
if
(
unlikely
(
!
(
static_cast
<
T
*>
(
this
)
->
next
)))
return
(
size_t
)
-
1
;
return
pos
;
return
pos
;
}
}
// If there are no more data in the buffer, return.
// If there are no more data in the buffer, return.
if
(
pos
==
size_
)
if
(
pos
==
size_
)
...
@@ -142,6 +150,13 @@ namespace zmq
...
@@ -142,6 +150,13 @@ namespace zmq
next
=
next_
;
next
=
next_
;
}
}
// This function should be called from the derived class to
// abort decoder state machine.
inline
void
decoding_error
()
{
next
=
NULL
;
}
private
:
private
:
unsigned
char
*
read_pos
;
unsigned
char
*
read_pos
;
...
...
src/zmq_engine.cpp
View file @
71bef330
...
@@ -119,18 +119,24 @@ void zmq::zmq_engine_t::in_event ()
...
@@ -119,18 +119,24 @@ void zmq::zmq_engine_t::in_event ()
// Push the data to the decoder.
// Push the data to the decoder.
size_t
processed
=
decoder
.
process_buffer
(
inpos
,
insize
);
size_t
processed
=
decoder
.
process_buffer
(
inpos
,
insize
);
// Stop polling for input if we got stuck.
if
(
unlikely
(
processed
==
(
size_t
)
-
1
))
{
if
(
processed
<
insize
)
{
disconnection
=
true
;
// This may happen if queue limits are in effect or when
// init object reads all required information from the socket
// and rejects to read more data.
reset_pollin
(
handle
);
}
}
else
{
// Stop polling for input if we got stuck.
if
(
processed
<
insize
)
{
// Adjust the buffer.
// This may happen if queue limits are in effect or when
inpos
+=
processed
;
// init object reads all required information from the socket
insize
-=
processed
;
// and rejects to read more data.
reset_pollin
(
handle
);
}
// Adjust the buffer.
inpos
+=
processed
;
insize
-=
processed
;
}
// Flush all messages the decoder may have produced.
// Flush all messages the decoder may have produced.
inout
->
flush
();
inout
->
flush
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment