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
b54b55d8
Commit
b54b55d8
authored
Feb 06, 2019
by
Simon Giesecke
Committed by
Simon Giesecke
Feb 06, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Problem: sun_path in an AF_UNIX address might not be null-terminated
Solution: use addrlen to determine the length
parent
31015fdc
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
13 additions
and
12 deletions
+13
-12
ipc_address.cpp
src/ipc_address.cpp
+12
-12
ipc_address.hpp
src/ipc_address.hpp
+1
-0
No files found.
src/ipc_address.cpp
View file @
b54b55d8
...
...
@@ -42,7 +42,8 @@ zmq::ipc_address_t::ipc_address_t ()
memset
(
&
_address
,
0
,
sizeof
_address
);
}
zmq
::
ipc_address_t
::
ipc_address_t
(
const
sockaddr
*
sa_
,
socklen_t
sa_len_
)
zmq
::
ipc_address_t
::
ipc_address_t
(
const
sockaddr
*
sa_
,
socklen_t
sa_len_
)
:
_addrlen
(
sa_len_
)
{
zmq_assert
(
sa_
&&
sa_len_
>
0
);
...
...
@@ -72,6 +73,8 @@ int zmq::ipc_address_t::resolve (const char *path_)
/* Abstract sockets start with '\0' */
if
(
path_
[
0
]
==
'@'
)
*
_address
.
sun_path
=
'\0'
;
_addrlen
=
offsetof
(
sockaddr_un
,
sun_path
)
+
path_len
;
return
0
;
}
...
...
@@ -92,14 +95,14 @@ int zmq::ipc_address_t::to_string (std::string &addr_) const
*
pos
++
=
'@'
;
src_pos
++
;
}
// TODO
// according to http://man7.org/linux/man-pages/man7/unix.7.html, NOTES
// section, address.sun_path might not always be null-terminated; instead,
// we must store the sa_len_ passed in the ctor to calculate the actual
// length
const
size_t
src_len
=
strlen
(
src_pos
);
memcpy
(
pos
,
src_pos
,
src_len
+
1
);
addr_
.
assign
(
pos
,
buf
,
pos
-
buf
+
src_len
);
// section, address.sun_path might not always be null-terminated; therefore,
// we calculate the length based of addrlen
const
size_t
src_len
=
strnlen
(
src_pos
,
_addrlen
-
offsetof
(
sockaddr_un
,
sun_path
)
-
(
src_pos
-
_address
.
sun_path
));
memcpy
(
pos
,
src_pos
,
src_len
);
addr_
.
assign
(
buf
,
pos
-
buf
+
src_len
);
return
0
;
}
...
...
@@ -110,10 +113,7 @@ const sockaddr *zmq::ipc_address_t::addr () const
socklen_t
zmq
::
ipc_address_t
::
addrlen
()
const
{
if
(
!
_address
.
sun_path
[
0
]
&&
_address
.
sun_path
[
1
])
return
static_cast
<
socklen_t
>
(
strlen
(
_address
.
sun_path
+
1
))
+
sizeof
(
sa_family_t
)
+
1
;
return
static_cast
<
socklen_t
>
(
sizeof
_address
);
return
_addrlen
;
}
#endif
src/ipc_address.hpp
View file @
b54b55d8
...
...
@@ -58,6 +58,7 @@ class ipc_address_t
private
:
struct
sockaddr_un
_address
;
size_t
_addrlen
;
ipc_address_t
(
const
ipc_address_t
&
);
const
ipc_address_t
&
operator
=
(
const
ipc_address_t
&
);
...
...
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