mirror of
https://github.com/zeromq/libzmq.git
synced 2025-10-16 07:23:46 +02:00
resolve #1292 ZMQ_IDENTITY_FD does not validate option_len
This commit is contained in:
@@ -142,7 +142,13 @@ int zmq::router_t::xgetsockopt (int option_, const void *optval_,
|
|||||||
*optvallen_=sizeof(fd_t);
|
*optvallen_=sizeof(fd_t);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (optval_ && optvallen_ && *optvallen_) {
|
if (optval_ && optvallen_ && *optvallen_) {
|
||||||
|
if (*optvallen_ < sizeof(fd_t)) {
|
||||||
|
*optvallen_=sizeof(fd_t);
|
||||||
|
return EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
blob_t identity= blob_t((unsigned char*)optval_,*optvallen_);
|
blob_t identity= blob_t((unsigned char*)optval_,*optvallen_);
|
||||||
outpipes_t::iterator it = outpipes.find (identity);
|
outpipes_t::iterator it = outpipes.find (identity);
|
||||||
if (it == outpipes.end() ){
|
if (it == outpipes.end() ){
|
||||||
|
@@ -61,10 +61,18 @@ int main (void)
|
|||||||
|
|
||||||
//buffer for zmq_getsockopt / ZMQ_IDENTITY_FD
|
//buffer for zmq_getsockopt / ZMQ_IDENTITY_FD
|
||||||
char idbuf[255];
|
char idbuf[255];
|
||||||
|
char failbuf[2];
|
||||||
size_t idbufsz=zmq_msg_size (&part);
|
size_t idbufsz=zmq_msg_size (&part);
|
||||||
|
size_t failsz=2;
|
||||||
|
|
||||||
assert (idbufsz<=255);
|
assert (idbufsz<=255);
|
||||||
memcpy(idbuf,zmq_msg_data(&part),idbufsz);
|
memcpy(idbuf,zmq_msg_data(&part),idbufsz);
|
||||||
|
failbuf[0] = idbuf[0];
|
||||||
|
failbuf[1] = 0;
|
||||||
|
|
||||||
|
// ensure that we validate buffer is sufficient to hold result
|
||||||
|
rc = zmq_getsockopt (server, ZMQ_IDENTITY_FD, failbuf, &failsz);
|
||||||
|
assert (rc == EINVAL);
|
||||||
|
|
||||||
rc = zmq_getsockopt (server, ZMQ_IDENTITY_FD, idbuf, &idbufsz);
|
rc = zmq_getsockopt (server, ZMQ_IDENTITY_FD, idbuf, &idbufsz);
|
||||||
assert (rc == 0);
|
assert (rc == 0);
|
||||||
|
Reference in New Issue
Block a user