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
f9985708
Commit
f9985708
authored
Aug 17, 2017
by
sigiesec
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Problem: unreachable code in zap_client_t
Solution: replaced unreachable code by assertions and adapted uses
parent
7f15e6c8
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
46 additions
and
75 deletions
+46
-75
curve_server.cpp
src/curve_server.cpp
+3
-6
curve_server.hpp
src/curve_server.hpp
+1
-1
gssapi_server.cpp
src/gssapi_server.cpp
+4
-8
gssapi_server.hpp
src/gssapi_server.hpp
+1
-1
null_mechanism.cpp
src/null_mechanism.cpp
+4
-6
null_mechanism.hpp
src/null_mechanism.hpp
+1
-1
plain_server.cpp
src/plain_server.cpp
+5
-7
plain_server.hpp
src/plain_server.hpp
+2
-2
zap_client.cpp
src/zap_client.cpp
+15
-33
zap_client.hpp
src/zap_client.hpp
+10
-10
No files found.
src/curve_server.cpp
View file @
f9985708
...
...
@@ -488,9 +488,7 @@ int zmq::curve_server_t::process_initiate (msg_t *msg_)
// not work properly the program will abort.
rc
=
session
->
zap_connect
();
if
(
rc
==
0
)
{
rc
=
send_zap_request
(
client_key
);
if
(
rc
!=
0
)
return
-
1
;
send_zap_request
(
client_key
);
rc
=
receive_and_process_zap_reply
();
if
(
rc
==
-
1
)
return
-
1
;
...
...
@@ -561,10 +559,9 @@ int zmq::curve_server_t::produce_error (msg_t *msg_) const
return
0
;
}
int
zmq
::
curve_server_t
::
send_zap_request
(
const
uint8_t
*
key
)
void
zmq
::
curve_server_t
::
send_zap_request
(
const
uint8_t
*
key
)
{
return
zap_client_t
::
send_zap_request
(
"CURVE"
,
5
,
key
,
crypto_box_PUBLICKEYBYTES
);
zap_client_t
::
send_zap_request
(
"CURVE"
,
5
,
key
,
crypto_box_PUBLICKEYBYTES
);
}
#endif
src/curve_server.hpp
View file @
f9985708
...
...
@@ -103,7 +103,7 @@ namespace zmq
int
produce_ready
(
msg_t
*
msg_
);
int
produce_error
(
msg_t
*
msg_
)
const
;
int
send_zap_request
(
const
uint8_t
*
key
);
void
send_zap_request
(
const
uint8_t
*
key
);
};
}
...
...
src/gssapi_server.cpp
View file @
f9985708
...
...
@@ -125,9 +125,7 @@ int zmq::gssapi_server_t::process_handshake_command (msg_t *msg_)
bool
expecting_zap_reply
=
false
;
int
rc
=
session
->
zap_connect
();
if
(
rc
==
0
)
{
rc
=
send_zap_request
();
if
(
rc
!=
0
)
return
-
1
;
send_zap_request
();
rc
=
receive_and_process_zap_reply
();
if
(
rc
!=
0
)
{
if
(
rc
==
-
1
)
...
...
@@ -151,16 +149,14 @@ int zmq::gssapi_server_t::process_handshake_command (msg_t *msg_)
return
0
;
}
int
zmq
::
gssapi_server_t
::
send_zap_request
()
void
zmq
::
gssapi_server_t
::
send_zap_request
()
{
gss_buffer_desc
principal
;
gss_display_name
(
&
min_stat
,
target_name
,
&
principal
,
NULL
);
int
rc
=
zap_client_t
::
send_zap_request
(
"GSSAPI"
,
6
,
principal
.
value
,
principal
.
length
);
zap_client_t
::
send_zap_request
(
"GSSAPI"
,
6
,
principal
.
value
,
principal
.
length
);
gss_release_buffer
(
&
min_stat
,
&
principal
);
return
rc
;
}
int
zmq
::
gssapi_server_t
::
encode
(
msg_t
*
msg_
)
...
...
src/gssapi_server.hpp
View file @
f9985708
...
...
@@ -88,7 +88,7 @@ namespace zmq
void
accept_context
();
int
produce_next_token
(
msg_t
*
msg_
);
int
process_next_token
(
msg_t
*
msg_
);
int
send_zap_request
();
void
send_zap_request
();
};
}
...
...
src/null_mechanism.cpp
View file @
f9985708
...
...
@@ -74,11 +74,9 @@ int zmq::null_mechanism_t::next_handshake_command (msg_t *msg_)
errno
=
EAGAIN
;
return
-
1
;
}
int
rc
=
send_zap_request
();
if
(
rc
!=
0
)
return
-
1
;
send_zap_request
();
zap_request_sent
=
true
;
rc
=
receive_and_process_zap_reply
();
int
rc
=
receive_and_process_zap_reply
();
if
(
rc
==
-
1
||
rc
==
1
)
return
-
1
;
zap_reply_received
=
true
;
...
...
@@ -189,8 +187,8 @@ zmq::mechanism_t::status_t zmq::null_mechanism_t::status () const
return
handshaking
;
}
int
zmq
::
null_mechanism_t
::
send_zap_request
()
void
zmq
::
null_mechanism_t
::
send_zap_request
()
{
return
zap_client_t
::
send_zap_request
(
"NULL"
,
4
,
NULL
,
NULL
,
0
);
zap_client_t
::
send_zap_request
(
"NULL"
,
4
,
NULL
,
NULL
,
0
);
}
src/null_mechanism.hpp
View file @
f9985708
...
...
@@ -70,7 +70,7 @@ namespace zmq
int
process_error_command
(
const
unsigned
char
*
cmd_data
,
size_t
data_size
);
int
send_zap_request
();
void
send_zap_request
();
};
}
...
...
src/plain_server.cpp
View file @
f9985708
...
...
@@ -169,9 +169,7 @@ int zmq::plain_server_t::process_hello (msg_t *msg_)
int
rc
=
session
->
zap_connect
();
if
(
rc
!=
0
)
return
-
1
;
rc
=
send_zap_request
(
username
,
password
);
if
(
rc
!=
0
)
return
-
1
;
send_zap_request
(
username
,
password
);
return
receive_and_process_zap_reply
()
==
-
1
?
-
1
:
0
;
}
...
...
@@ -219,13 +217,13 @@ int zmq::plain_server_t::produce_error (msg_t *msg_) const
return
0
;
}
int
zmq
::
plain_server_t
::
send_zap_request
(
const
std
::
string
&
username
,
const
std
::
string
&
password
)
void
zmq
::
plain_server_t
::
send_zap_request
(
const
std
::
string
&
username
,
const
std
::
string
&
password
)
{
const
uint8_t
*
credentials
[]
=
{
reinterpret_cast
<
const
uint8_t
*>
(
username
.
c_str
()),
reinterpret_cast
<
const
uint8_t
*>
(
password
.
c_str
())};
size_t
credentials_sizes
[]
=
{
username
.
size
(),
password
.
size
()};
return
zap_client_t
::
send_zap_request
(
"PLAIN"
,
5
,
credential
s
,
credentials_sizes
,
2
);
zap_client_t
::
send_zap_request
(
"PLAIN"
,
5
,
credentials
,
credentials_size
s
,
2
);
}
src/plain_server.hpp
View file @
f9985708
...
...
@@ -62,8 +62,8 @@ namespace zmq
int
process_hello
(
msg_t
*
msg_
);
int
process_initiate
(
msg_t
*
msg_
);
int
send_zap_request
(
const
std
::
string
&
username
,
const
std
::
string
&
password
);
void
send_zap_request
(
const
std
::
string
&
username
,
const
std
::
string
&
password
);
};
}
...
...
src/zap_client.cpp
View file @
f9985708
...
...
@@ -45,25 +45,23 @@ zap_client_t::zap_client_t (session_base_t *const session_,
{
}
int
zap_client_t
::
send_zap_request
(
const
char
*
mechanism
,
void
zap_client_t
::
send_zap_request
(
const
char
*
mechanism
,
size_t
mechanism_length
,
const
uint8_t
*
credentials
,
size_t
credentials_size
)
{
return
send_zap_request
(
mechanism
,
mechanism_length
,
&
credentials
,
&
credentials_size
,
1
);
send_zap_request
(
mechanism
,
mechanism_length
,
&
credentials
,
&
credentials_size
,
1
);
}
int
zap_client_t
::
send_zap_request
(
const
char
*
mechanism
,
void
zap_client_t
::
send_zap_request
(
const
char
*
mechanism
,
size_t
mechanism_length
,
const
uint8_t
**
credentials
,
size_t
*
credentials_sizes
,
size_t
credentials_count
)
{
// TODO I don't think the rc can be -1 anywhere below.
// It might only be -1 if the HWM was exceeded, but on the ZAP socket,
// the HWM is disabled. They should be changed to zmq_assert (rc == 0);
// The method's return type can be changed to void then.
// write_zap_msg cannot fail. It could only fail if the HWM was exceeded,
// but on the ZAP socket, the HWM is disabled.
int
rc
;
msg_t
msg
;
...
...
@@ -73,8 +71,7 @@ int zap_client_t::send_zap_request (const char *mechanism,
errno_assert
(
rc
==
0
);
msg
.
set_flags
(
msg_t
::
more
);
rc
=
session
->
write_zap_msg
(
&
msg
);
if
(
rc
!=
0
)
return
close_and_return
(
&
msg
,
-
1
);
errno_assert
(
rc
==
0
);
// Version frame
rc
=
msg
.
init_size
(
3
);
...
...
@@ -82,8 +79,7 @@ int zap_client_t::send_zap_request (const char *mechanism,
memcpy
(
msg
.
data
(),
"1.0"
,
3
);
msg
.
set_flags
(
msg_t
::
more
);
rc
=
session
->
write_zap_msg
(
&
msg
);
if
(
rc
!=
0
)
return
close_and_return
(
&
msg
,
-
1
);
errno_assert
(
rc
==
0
);
// Request ID frame
rc
=
msg
.
init_size
(
1
);
...
...
@@ -91,8 +87,7 @@ int zap_client_t::send_zap_request (const char *mechanism,
memcpy
(
msg
.
data
(),
"1"
,
1
);
msg
.
set_flags
(
msg_t
::
more
);
rc
=
session
->
write_zap_msg
(
&
msg
);
if
(
rc
!=
0
)
return
close_and_return
(
&
msg
,
-
1
);
errno_assert
(
rc
==
0
);
// Domain frame
rc
=
msg
.
init_size
(
options
.
zap_domain
.
length
());
...
...
@@ -101,8 +96,7 @@ int zap_client_t::send_zap_request (const char *mechanism,
options
.
zap_domain
.
length
());
msg
.
set_flags
(
msg_t
::
more
);
rc
=
session
->
write_zap_msg
(
&
msg
);
if
(
rc
!=
0
)
return
close_and_return
(
&
msg
,
-
1
);
errno_assert
(
rc
==
0
);
// Address frame
rc
=
msg
.
init_size
(
peer_address
.
length
());
...
...
@@ -110,8 +104,7 @@ int zap_client_t::send_zap_request (const char *mechanism,
memcpy
(
msg
.
data
(),
peer_address
.
c_str
(),
peer_address
.
length
());
msg
.
set_flags
(
msg_t
::
more
);
rc
=
session
->
write_zap_msg
(
&
msg
);
if
(
rc
!=
0
)
return
close_and_return
(
&
msg
,
-
1
);
errno_assert
(
rc
==
0
);
// Identity frame
rc
=
msg
.
init_size
(
options
.
identity_size
);
...
...
@@ -119,8 +112,7 @@ int zap_client_t::send_zap_request (const char *mechanism,
memcpy
(
msg
.
data
(),
options
.
identity
,
options
.
identity_size
);
msg
.
set_flags
(
msg_t
::
more
);
rc
=
session
->
write_zap_msg
(
&
msg
);
if
(
rc
!=
0
)
return
close_and_return
(
&
msg
,
-
1
);
errno_assert
(
rc
==
0
);
// Mechanism frame
rc
=
msg
.
init_size
(
mechanism_length
);
...
...
@@ -129,8 +121,7 @@ int zap_client_t::send_zap_request (const char *mechanism,
if
(
credentials_count
)
msg
.
set_flags
(
msg_t
::
more
);
rc
=
session
->
write_zap_msg
(
&
msg
);
if
(
rc
!=
0
)
return
close_and_return
(
&
msg
,
-
1
);
errno_assert
(
rc
==
0
);
// Credentials frames
for
(
size_t
i
=
0
;
i
<
credentials_count
;
++
i
)
{
...
...
@@ -140,11 +131,8 @@ int zap_client_t::send_zap_request (const char *mechanism,
msg
.
set_flags
(
msg_t
::
more
);
memcpy
(
msg
.
data
(),
credentials
[
i
],
credentials_sizes
[
i
]);
rc
=
session
->
write_zap_msg
(
&
msg
);
if
(
rc
!=
0
)
return
close_and_return
(
&
msg
,
-
1
);
errno_assert
(
rc
==
0
);
}
return
0
;
}
int
zap_client_t
::
receive_and_process_zap_reply
()
...
...
@@ -288,13 +276,7 @@ zmq::mechanism_t::status_t zap_client_common_handshake_t::status () const
int
zap_client_common_handshake_t
::
zap_msg_available
()
{
// TODO I don't think that it is possible that this is called in any
// state other than expect_zap_reply. It should be changed to
// zmq_assert (state == expect_zap_reply);
if
(
state
!=
waiting_for_zap_reply
)
{
errno
=
EFSM
;
return
-
1
;
}
zmq_assert
(
state
==
waiting_for_zap_reply
);
return
receive_and_process_zap_reply
()
==
-
1
?
-
1
:
0
;
}
...
...
src/zap_client.hpp
View file @
f9985708
...
...
@@ -43,16 +43,16 @@ class zap_client_t : public virtual mechanism_t
const
std
::
string
&
peer_address_
,
const
options_t
&
options_
);
int
send_zap_request
(
const
char
*
mechanism
,
size_t
mechanism_length
,
const
uint8_t
*
credentials
,
size_t
credentials_size
);
int
send_zap_request
(
const
char
*
mechanism
,
size_t
mechanism_length
,
const
uint8_t
**
credentials
,
size_t
*
credentials_sizes
,
size_t
credentials_count
);
void
send_zap_request
(
const
char
*
mechanism
,
size_t
mechanism_length
,
const
uint8_t
*
credentials
,
size_t
credentials_size
);
void
send_zap_request
(
const
char
*
mechanism
,
size_t
mechanism_length
,
const
uint8_t
**
credentials
,
size_t
*
credentials_sizes
,
size_t
credentials_count
);
virtual
int
receive_and_process_zap_reply
();
virtual
void
handle_zap_status_code
();
...
...
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