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
2e4fc4fa
Commit
2e4fc4fa
authored
Aug 22, 2017
by
sigiesec
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Problem: zmq_poller_*_fd functions do not check for invalid fd
Solution: add checks, added test cases
parent
f9af5503
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
38 additions
and
5 deletions
+38
-5
zmq.cpp
src/zmq.cpp
+12
-0
test_poller.cpp
tests/test_poller.cpp
+26
-5
No files found.
src/zmq.cpp
View file @
2e4fc4fa
...
...
@@ -1269,6 +1269,10 @@ int zmq_poller_add_fd (void *poller_, int fd_, void *user_data_, short events_)
errno
=
EFAULT
;
return
-
1
;
}
if
(
fd_
==
zmq
::
retired_fd
)
{
errno
=
ENOTSOCK
;
return
-
1
;
}
return
((
zmq
::
socket_poller_t
*
)
poller_
)
->
add_fd
(
fd_
,
user_data_
,
events_
);
}
...
...
@@ -1301,6 +1305,10 @@ int zmq_poller_modify_fd (void *poller_, int fd_, short events_)
errno
=
EFAULT
;
return
-
1
;
}
if
(
fd_
==
zmq
::
retired_fd
)
{
errno
=
ENOTSOCK
;
return
-
1
;
}
return
((
zmq
::
socket_poller_t
*
)
poller_
)
->
modify_fd
(
fd_
,
events_
);
}
...
...
@@ -1332,6 +1340,10 @@ int zmq_poller_remove_fd (void *poller_, int fd_)
errno
=
EFAULT
;
return
-
1
;
}
if
(
fd_
==
zmq
::
retired_fd
)
{
errno
=
ENOTSOCK
;
return
-
1
;
}
return
((
zmq
::
socket_poller_t
*
)
poller_
)
->
remove_fd
(
fd_
);
}
...
...
tests/test_poller.cpp
View file @
2e4fc4fa
...
...
@@ -29,6 +29,20 @@
#include "testutil.hpp"
// duplicated from fd.hpp
#ifdef ZMQ_HAVE_WINDOWS
#if defined _MSC_VER &&_MSC_VER <= 1400
typedef
UINT_PTR
fd_t
;
enum
{
retired_fd
=
(
fd_t
)(
~
0
)};
#else
typedef
SOCKET
fd_t
;
enum
{
retired_fd
=
(
fd_t
)
INVALID_SOCKET
};
#endif
#else
typedef
int
fd_t
;
enum
{
retired_fd
=
-
1
};
#endif
void
test_null_poller_pointers
(
void
*
ctx
)
{
int
rc
=
zmq_poller_destroy
(
NULL
);
...
...
@@ -55,11 +69,7 @@ void test_null_poller_pointers (void *ctx)
rc
=
zmq_poller_remove
(
&
null_poller
,
socket
);
assert
(
rc
==
-
1
&&
errno
==
EFAULT
);
#ifdef _WIN32
SOCKET
fd
;
#else
int
fd
;
#endif
fd_t
fd
;
size_t
fd_size
=
sizeof
fd
;
rc
=
zmq_getsockopt
(
socket
,
ZMQ_FD
,
&
fd
,
&
fd_size
);
assert
(
rc
==
0
);
...
...
@@ -97,6 +107,17 @@ void test_null_socket_pointers ()
rc
=
zmq_poller_remove
(
poller
,
NULL
);
assert
(
rc
==
-
1
&&
errno
==
ENOTSOCK
);
fd_t
null_socket_fd
=
retired_fd
;
rc
=
zmq_poller_add_fd
(
poller
,
null_socket_fd
,
NULL
,
ZMQ_POLLIN
);
assert
(
rc
==
-
1
&&
errno
==
ENOTSOCK
);
rc
=
zmq_poller_modify_fd
(
poller
,
null_socket_fd
,
ZMQ_POLLIN
);
assert
(
rc
==
-
1
&&
errno
==
ENOTSOCK
);
rc
=
zmq_poller_remove_fd
(
poller
,
null_socket_fd
);
assert
(
rc
==
-
1
&&
errno
==
ENOTSOCK
);
rc
=
zmq_poller_destroy
(
&
poller
);
assert
(
rc
==
0
);
}
...
...
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