Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nx-libs
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
1
Issues
1
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
dimbor
nx-libs
Commits
6198e037
Commit
6198e037
authored
Dec 27, 2017
by
Ulrich Sibiller
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
nxcomp: implement correct length handling for unix socket structs
(partially) fixes ArcticaProject/nx-libs#612
parent
2367fc71
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
57 additions
and
28 deletions
+57
-28
Loop.cpp
nxcomp/src/Loop.cpp
+51
-16
Proxy.cpp
nxcomp/src/Proxy.cpp
+6
-12
No files found.
nxcomp/src/Loop.cpp
View file @
6198e037
...
@@ -55,6 +55,8 @@
...
@@ -55,6 +55,8 @@
#include "Misc.h"
#include "Misc.h"
#include <cstddef>
#ifdef __sun
#ifdef __sun
#include <strings.h>
#include <strings.h>
#endif
#endif
...
@@ -3590,19 +3592,14 @@ int SetupAuthInstance()
...
@@ -3590,19 +3592,14 @@ int SetupAuthInstance()
launchdAddrUnix
.
sun_family
=
AF_UNIX
;
launchdAddrUnix
.
sun_family
=
AF_UNIX
;
#ifdef __linux__
// determine the maximum number of characters that fit into struct
const
int
launchdAddrNameLength
=
108
;
// sockaddr_un's sun_path member
#else
std
::
size_t
launchdAddrNameLength
=
/* POSIX/SUS does not specify a length.
sizeof
(
struct
sockaddr_un
)
-
offsetof
(
struct
sockaddr_un
,
sun_path
);
* BSD derivatives generally support 104 bytes, other systems may be more constrained.
* If you happen to run into such systems, extend this section with the appropriate limit.
*/
const
int
launchdAddrNameLength
=
104
;
#endif
int
success
=
-
1
;
int
success
=
-
1
;
s
trncpy
(
launchdAddrUnix
.
sun_path
,
displayHost
,
launchdAddrNameLength
);
s
nprintf
(
launchdAddrUnix
.
sun_path
,
launchdAddrNameLength
,
"%s"
,
displayHost
);
*
(
launchdAddrUnix
.
sun_path
+
launchdAddrNameLength
-
1
)
=
'\0'
;
*
(
launchdAddrUnix
.
sun_path
+
launchdAddrNameLength
-
1
)
=
'\0'
;
...
@@ -3909,6 +3906,11 @@ void SetupDisplaySocket(int &addr_family, sockaddr *&addr,
...
@@ -3909,6 +3906,11 @@ void SetupDisplaySocket(int &addr_family, sockaddr *&addr,
// UNIX domain port.
// UNIX domain port.
//
//
// determine the maximum number of characters that fit into struct
// sockaddr_un's sun_path member
std
::
size_t
maxlen_un
=
sizeof
(
struct
sockaddr_un
)
-
offsetof
(
struct
sockaddr_un
,
sun_path
);
nxinfo
<<
"Loop: Using real X server on UNIX domain socket.
\n
"
nxinfo
<<
"Loop: Using real X server on UNIX domain socket.
\n
"
<<
std
::
flush
;
<<
std
::
flush
;
...
@@ -3943,10 +3945,28 @@ void SetupDisplaySocket(int &addr_family, sockaddr *&addr,
...
@@ -3943,10 +3945,28 @@ void SetupDisplaySocket(int &addr_family, sockaddr *&addr,
sockaddr_un
*
xServerAddrABSTRACT
=
new
sockaddr_un
;
sockaddr_un
*
xServerAddrABSTRACT
=
new
sockaddr_un
;
memset
(
xServerAddrABSTRACT
,
0
,
sizeof
(
struct
sockaddr_un
));
memset
(
xServerAddrABSTRACT
,
0
,
sizeof
(
struct
sockaddr_un
));
xServerAddrABSTRACT
->
sun_family
=
AF_UNIX
;
xServerAddrABSTRACT
->
sun_family
=
AF_UNIX
;
// FIXME: ensure sun_path can hold len+1 bytes!
memcpy
(
xServerAddrABSTRACT
->
sun_path
,
unixSocketName
,
len
+
1
);
if
(
maxlen_un
<
(
unsigned
int
)
len
+
1
)
// FIXME: comment why + 3?
{
addr_length
=
len
+
3
;
nxfatal
<<
"Loop: PANIC! Abstract socket name '"
<<
unixSocketName
+
1
<<
"' is too long!"
<<
std
::
flush
;
delete
[]
display
;
delete
xServerAddrABSTRACT
;
HandleCleanup
();
}
// copy including the leading '\0'
memcpy
(
xServerAddrABSTRACT
->
sun_path
,
unixSocketName
,
len
+
1
);
// man 7 unix:
// "an abstract socket address is distinguished (from a
// pathname socket) by the fact that sun_path[0] is a null byte
// ('\0'). The socket's address in this namespace is given by the
// additional bytes in sun_path that are covered by the specified
// length of the address structure."
addr_length
=
offsetof
(
struct
sockaddr_un
,
sun_path
)
+
len
+
1
;
int
ret
=
connect
(
testSocketFD
,
int
ret
=
connect
(
testSocketFD
,
(
struct
sockaddr
*
)
xServerAddrABSTRACT
,
(
struct
sockaddr
*
)
xServerAddrABSTRACT
,
...
@@ -4032,8 +4052,17 @@ void SetupDisplaySocket(int &addr_family, sockaddr *&addr,
...
@@ -4032,8 +4052,17 @@ void SetupDisplaySocket(int &addr_family, sockaddr *&addr,
nxinfo
<<
"Loop: Assuming X socket name '"
<<
unixSocketName
nxinfo
<<
"Loop: Assuming X socket name '"
<<
unixSocketName
<<
"'.
\n
"
<<
std
::
flush
;
<<
"'.
\n
"
<<
std
::
flush
;
sockaddr_un
*
xServerAddrUNIX
=
new
sockaddr_un
;
if
(
maxlen_un
<
strlen
(
unixSocketName
)
+
1
)
{
nxfatal
<<
"Loop: PANIC! Socket name '"
<<
unixSocketName
<<
"' is too long!"
<<
std
::
flush
;
delete
[]
display
;
HandleCleanup
();
}
sockaddr_un
*
xServerAddrUNIX
=
new
sockaddr_un
;
xServerAddrUNIX
->
sun_family
=
AF_UNIX
;
xServerAddrUNIX
->
sun_family
=
AF_UNIX
;
strcpy
(
xServerAddrUNIX
->
sun_path
,
unixSocketName
);
strcpy
(
xServerAddrUNIX
->
sun_path
,
unixSocketName
);
...
@@ -6539,12 +6568,18 @@ int PrepareProxyConnectionUnix(char** path, int* timeout, int* proxyFileDescript
...
@@ -6539,12 +6568,18 @@ int PrepareProxyConnectionUnix(char** path, int* timeout, int* proxyFileDescript
/* FIXME: Add socket file existence and permission checks */
/* FIXME: Add socket file existence and permission checks */
*
proxyFileDescriptor
=
-
1
;
*
proxyFileDescriptor
=
-
1
;
*
reason
=
-
1
;
*
reason
=
-
1
;
// determine the maximum number of characters that fit into struct
// sockaddr_un's sun_path member
const
std
::
size_t
sockpathlen
=
sizeof
(
struct
sockaddr_un
)
-
offsetof
(
struct
sockaddr_un
,
sun_path
);
sockaddr_un
addr
;
sockaddr_un
addr
;
addr
.
sun_family
=
AF_UNIX
;
addr
.
sun_family
=
AF_UNIX
;
s
trncpy
(
addr
.
sun_path
,
*
path
,
108
-
1
);
s
nprintf
(
addr
.
sun_path
,
sockpathlen
,
"%s"
,
*
path
);
*
proxyFileDescriptor
=
socket
(
AF_UNIX
,
SOCK_STREAM
,
PF_UNSPEC
);
*
proxyFileDescriptor
=
socket
(
AF_UNIX
,
SOCK_STREAM
,
PF_UNSPEC
);
*
reason
=
EGET
();
*
reason
=
EGET
();
...
...
nxcomp/src/Proxy.cpp
View file @
6198e037
...
@@ -30,6 +30,7 @@
...
@@ -30,6 +30,7 @@
#include <cstdio>
#include <cstdio>
#include <unistd.h>
#include <unistd.h>
#include <cstdlib>
#include <cstdlib>
#include <cstddef>
#include <string.h>
#include <string.h>
#include <sys/types.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/stat.h>
...
@@ -6294,19 +6295,12 @@ int Proxy::handleNewGenericConnectionFromProxyUnix(int channelId, T_channel_type
...
@@ -6294,19 +6295,12 @@ int Proxy::handleNewGenericConnectionFromProxyUnix(int channelId, T_channel_type
serverAddrUnix
.
sun_family
=
AF_UNIX
;
serverAddrUnix
.
sun_family
=
AF_UNIX
;
#ifdef __linux__
// determine the maximum number of characters that fit into struct
const
int
serverAddrNameLength
=
108
;
// sockaddr_un's sun_path member
#else
std
::
size_t
serverAddrNameLength
=
/* POSIX/SUS does not specify a length.
sizeof
(
struct
sockaddr_un
)
-
offsetof
(
struct
sockaddr_un
,
sun_path
);
* BSD derivatives generally support 104 bytes, other systems may be more constrained.
* If you happen to run into such systems, extend this section with the appropriate limit.
*/
const
int
serverAddrNameLength
=
104
;
#endif
strncpy
(
serverAddrUnix
.
sun_path
,
path
,
serverAddrNameLength
);
*
(
serverAddrUnix
.
sun_path
+
serverAddrNameLength
-
1
)
=
'\0'
;
snprintf
(
serverAddrUnix
.
sun_path
,
serverAddrNameLength
,
"%s"
,
path
)
;
#ifdef TEST
#ifdef TEST
*
logofs
<<
"Proxy: Connecting to "
<<
label
<<
" server "
*
logofs
<<
"Proxy: Connecting to "
<<
label
<<
" server "
...
...
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