From 8c0f5228e75aa949963aa8d27dcfa2648db2e197 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Wed, 29 Jan 2014 12:54:25 -0800 Subject: move is_numeric to Xtranssock.c and only define for TCPCONN or TRANS_REOPEN Don't define this function unless it is actually going to be used. Signed-off-by: Keith Packard --- Xtransint.h | 5 ----- Xtranssock.c | 14 ++++++++++++++ Xtransutil.c | 14 -------------- 3 files changed, 14 insertions(+), 19 deletions(-) diff --git a/Xtransint.h b/Xtransint.h index fe1f117..44d8b6d 100644 --- a/Xtransint.h +++ b/Xtransint.h @@ -351,11 +351,6 @@ static int TRANS(WriteV)( #endif /* WIN32 */ - -static int is_numeric ( - const char * /* str */ -); - #ifdef TRANS_SERVER static int trans_mkdir ( const char *, /* path */ diff --git a/Xtranssock.c b/Xtranssock.c index 0177186..84159e8 100644 --- a/Xtranssock.c +++ b/Xtranssock.c @@ -196,6 +196,20 @@ static Sockettrans2dev Sockettrans2devtab[] = { static int TRANS(SocketINETClose) (XtransConnInfo ciptr); #endif +#if defined(TCPCONN) || defined(TRANS_REOPEN) +static int +is_numeric (const char *str) +{ + int i; + + for (i = 0; i < (int) strlen (str); i++) + if (!isdigit (str[i])) + return (0); + + return (1); +} +#endif + #ifdef UNIXCONN diff --git a/Xtransutil.c b/Xtransutil.c index 1bce2d2..884cfdf 100644 --- a/Xtransutil.c +++ b/Xtransutil.c @@ -425,20 +425,6 @@ TRANS(WSAStartup) (void) } #endif -#include - -static int -is_numeric (const char *str) -{ - int i; - - for (i = 0; i < (int) strlen (str); i++) - if (!isdigit (str[i])) - return (0); - - return (1); -} - #ifdef TRANS_SERVER #include #include -- cgit v1.2.3 From c761c6505d49e8381a3eae94f2e5e118cbdf6487 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Wed, 29 Jan 2014 12:54:26 -0800 Subject: Use font server ErrorF/VErrorF instead of private versions XTrans creates custom ErrorF/VErrorF functions when the including project doesn't provide them, however the test for that is weak and xtrans ends up using the private versions for the font server as well. This means that all xtrans error messages will not be included in the font server log. It also causes redefinition warnings when building the font server (which is how this problem was identified). However, the font server doesn't currently provide a VErrorF function, so instead of just always relying on the font server to provide these functions, this patch uses a new TRANS_HAS_ERRORF define to select whether the project-provided or internal versions will be used. A patch to the font server that adds VErrorF and defines TRANS_HAS_ERRORF will be required to fix this bug. Signed-off-by: Keith Packard --- Xtransint.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Xtransint.h b/Xtransint.h index 44d8b6d..b8f3b76 100644 --- a/Xtransint.h +++ b/Xtransint.h @@ -370,10 +370,11 @@ static int trans_mkdir ( #include /* - * The X server provides ErrorF() & VErrorF(), for other software that uses - * xtrans, we provide our own simple versions. + * The X server and the font server both provide ErrorF() & VErrorF(). For + * other software that uses xtrans, we provide our own simple + * versions. */ -# if defined(XSERV_t) && defined(TRANS_SERVER) +# if (defined(XSERV_t) || defined(TRANS_HAS_ERRORF)) && defined(TRANS_SERVER) # include "os.h" # else static inline void _X_ATTRIBUTE_PRINTF(1, 0) -- cgit v1.2.3 From 9ae32feef793082a302e65d31514a958604c761d Mon Sep 17 00:00:00 2001 From: Olivier Fourdan Date: Tue, 25 Jun 2019 14:59:59 +0200 Subject: Allow partial connection to succeed Xwayland can optionally be socket-activated by the Wayland compositor, in which case it would use only the sockets provided by the compositor. However, that prevents other transport protocols from working, because when it's given a socket from the Wayland compositor, it would disable all other connections and rely solely on the given socket. Change `MakeAllCOTSServerListeners` to allow for partial connections so that if `partial` is set to a non-zero value by the caller, we do not bail out in the address is already in use. That allows to continue trying with other protocols even if the local connection fails (as this is already handled by the socket from the Wayland compositor). Related: https://gitlab.freedesktop.org/xorg/xserver/issues/817 Signed-off-by: Olivier Fourdan --- Xtrans.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Xtrans.c b/Xtrans.c index ce76120..e88b597 100644 --- a/Xtrans.c +++ b/Xtrans.c @@ -1170,6 +1170,9 @@ TRANS(MakeAllCOTSServerListeners) (const char *port, int *partial, if ((status = TRANS(CreateListener (ciptr, port, flags))) < 0) { + if (*partial != 0) + continue; + if (status == TRANS_ADDR_IN_USE) { /* -- cgit v1.2.3 From 9d77996f9f972da63c06099fd8c0f0529159b98f Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Sat, 25 Feb 2023 09:33:29 -0800 Subject: Remove "All rights reserved" from Oracle copyright notices Oracle no longer includes this term in our copyright & license notices. Signed-off-by: Alan Coopersmith --- COPYING | 2 +- Xtranssock.c | 2 +- xtrans.m4 | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/COPYING b/COPYING index d2dbc2c..c76b034 100644 --- a/COPYING +++ b/COPYING @@ -48,7 +48,7 @@ CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ______________________________________________________________________________ -Copyright (c) 2002, 2005, Oracle and/or its affiliates. All rights reserved. +Copyright (c) 2002, 2005, Oracle and/or its affiliates. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), diff --git a/Xtranssock.c b/Xtranssock.c index 84159e8..99c0f1f 100644 --- a/Xtranssock.c +++ b/Xtranssock.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, Oracle and/or its affiliates. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), diff --git a/xtrans.m4 b/xtrans.m4 index 0a5c5c1..55e186b 100644 --- a/xtrans.m4 +++ b/xtrans.m4 @@ -1,5 +1,5 @@ dnl -dnl Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved. +dnl Copyright (c) 2005, Oracle and/or its affiliates. dnl dnl Permission is hereby granted, free of charge, to any person obtaining a dnl copy of this software and associated documentation files (the "Software"), -- cgit v1.2.3 From e24adec1203cd25423ab2835a5be4f6b828b72a5 Mon Sep 17 00:00:00 2001 From: Demi Marie Obenour Date: Thu, 17 Dec 2020 03:28:45 +0000 Subject: Remove client-side abstract socket support CVE-2020-25697 and the Flatpak documentation show that clients using abstract sockets without mutual authentication is unsafe. TRANS_ABSTRACT remains supported, but it is now a no-op on the client side. Abstract sockets are still supported for servers, as the X server authenticates the client via other methods. Signed-off-by: Demi Marie Obenour --- Xtransint.h | 4 +++- Xtranssock.c | 33 +++------------------------------ 2 files changed, 6 insertions(+), 31 deletions(-) diff --git a/Xtransint.h b/Xtransint.h index b8f3b76..a43f7f8 100644 --- a/Xtransint.h +++ b/Xtransint.h @@ -297,7 +297,9 @@ typedef struct _Xtransport_table { #define TRANS_DISABLED (1<<2) /* Don't open this one */ #define TRANS_NOLISTEN (1<<3) /* Don't listen on this one */ #define TRANS_NOUNLINK (1<<4) /* Don't unlink transport endpoints */ -#define TRANS_ABSTRACT (1<<5) /* Use abstract sockets if available */ +#define TRANS_ABSTRACT (1<<5) /* This previously meant that abstract sockets should be used available. For security + * reasons, this is now a no-op on the client side, but it is still supported for servers. + */ #define TRANS_NOXAUTH (1<<6) /* Don't verify authentication (because it's secure some other way at the OS layer) */ #define TRANS_RECEIVED (1<<7) /* The fd for this has already been opened by someone else. */ diff --git a/Xtranssock.c b/Xtranssock.c index 99c0f1f..9482ecf 100644 --- a/Xtranssock.c +++ b/Xtranssock.c @@ -141,7 +141,7 @@ from the copyright holders. /* others don't need this */ #define SocketInitOnce() /**/ -#ifdef linux +#ifdef __linux__ #define HAVE_ABSTRACT_SOCKETS #endif @@ -1839,12 +1839,6 @@ TRANS(SocketUNIXConnect) (XtransConnInfo ciptr, struct sockaddr_un sockname; SOCKLEN_T namelen; - - int abstract = 0; -#ifdef HAVE_ABSTRACT_SOCKETS - abstract = ciptr->transptr->flags & TRANS_ABSTRACT; -#endif - prmsg (2,"SocketUNIXConnect(%d,%s,%s)\n", ciptr->fd, host, port); /* @@ -1880,7 +1874,7 @@ TRANS(SocketUNIXConnect) (XtransConnInfo ciptr, sockname.sun_family = AF_UNIX; - if (set_sun_path(port, UNIX_PATH, sockname.sun_path, abstract) != 0) { + if (set_sun_path(port, UNIX_PATH, sockname.sun_path, 0) != 0) { prmsg (1, "SocketUNIXConnect: path too long\n"); return TRANS_CONNECT_FAILED; } @@ -1896,16 +1890,6 @@ TRANS(SocketUNIXConnect) (XtransConnInfo ciptr, #endif - - /* - * Adjust the socket path if using abstract sockets. - * Done here because otherwise all the strlen() calls above would fail. - */ - - if (abstract) { - sockname.sun_path[0] = '\0'; - } - /* * Do the connect() */ @@ -1939,15 +1923,7 @@ TRANS(SocketUNIXConnect) (XtransConnInfo ciptr, return TRANS_IN_PROGRESS; else if (olderrno == EINTR) return TRANS_TRY_CONNECT_AGAIN; - else if (olderrno == ENOENT || olderrno == ECONNREFUSED) { - /* If opening as abstract socket failed, try again normally */ - if (abstract) { - ciptr->transptr->flags &= ~(TRANS_ABSTRACT); - return TRANS_TRY_CONNECT_AGAIN; - } else { - return TRANS_CONNECT_FAILED; - } - } else { + else { prmsg (2,"SocketUNIXConnect: Can't connect: errno = %d\n", EGET()); @@ -1969,9 +1945,6 @@ TRANS(SocketUNIXConnect) (XtransConnInfo ciptr, return TRANS_CONNECT_FAILED; } - if (abstract) - sockname.sun_path[0] = '@'; - ciptr->family = AF_UNIX; ciptr->addrlen = namelen; ciptr->peeraddrlen = namelen; -- cgit v1.2.3 From b898f415e7c31de5b4beb06b22a5498049852e53 Mon Sep 17 00:00:00 2001 From: Demi Marie Obenour Date: Thu, 15 Dec 2022 14:43:37 -0500 Subject: Allow full paths to sockets on non-macOS This adds explicit checks for addresses that start with / or unix: and uses full paths in this case. Signed-off-by: Demi Marie Obenour --- Xtrans.c | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/Xtrans.c b/Xtrans.c index e88b597..b2b98a2 100644 --- a/Xtrans.c +++ b/Xtrans.c @@ -331,14 +331,26 @@ TRANS(ParseAddress) (const char *address, */ #endif + if (address != NULL) { + if (address[0] == '/') { + _protocol = "local"; + _host = ""; + _port = address; + } else #ifdef HAVE_LAUNCHD - /* launchd sockets will look like 'local//tmp/launch-XgkNns/:0' */ - if(address != NULL && strlen(address)>8 && (!strncmp(address,"local//",7))) { - _protocol="local"; - _host=""; - _port=address+6; - } + /* launchd sockets will look like 'local//tmp/launch-XgkNns/:0' */ + if(!strncmp(address,"local//",7)) { + _protocol="local"; + _host=""; + _port=address+6; + } else #endif + if (!strncmp(address, "unix:", 5)) { + _protocol = "local"; + _host = ""; + _port = address + 5; + } + } /* * Now that we have all of the components, allocate new -- cgit v1.2.3 From 232a11a947564762689e63c3a6603d3f956f696d Mon Sep 17 00:00:00 2001 From: Demi Marie Obenour Date: Thu, 15 Dec 2022 14:48:13 -0500 Subject: DISPLAY starting with unix: or / is always a socket path Do not consider anything else in this case. Signed-off-by: Demi Marie Obenour --- Xtrans.c | 48 +++++++++++++++++++++++++----------------------- 1 file changed, 25 insertions(+), 23 deletions(-) diff --git a/Xtrans.c b/Xtrans.c index b2b98a2..12eefe8 100644 --- a/Xtrans.c +++ b/Xtrans.c @@ -202,14 +202,36 @@ TRANS(ParseAddress) (const char *address, * If a "::" is found then assume DNET. */ - char *mybuf, *tmpptr; - const char *_protocol; + char *mybuf, *tmpptr = NULL; + const char *_protocol = NULL; char *_host, *_port; char hostnamebuf[256]; int _host_len; prmsg (3,"ParseAddress(%s)\n", address); + /* First, check for AF_UNIX socket paths */ + if (address[0] == '/') { + _protocol = "local"; + _host = ""; + _port = address; + } else +#ifdef HAVE_LAUNCHD + /* launchd sockets will look like 'local//tmp/launch-XgkNns/:0' */ + if(!strncmp(address,"local//",7)) { + _protocol="local"; + _host=""; + _port=address+6; + } else +#endif + if (!strncmp(address, "unix:", 5)) { + _protocol = "local"; + _host = ""; + _port = address + 5; + } + if (_protocol) + goto done_parsing; + /* Copy the string so it can be changed */ tmpptr = mybuf = strdup (address); @@ -331,27 +353,7 @@ TRANS(ParseAddress) (const char *address, */ #endif - if (address != NULL) { - if (address[0] == '/') { - _protocol = "local"; - _host = ""; - _port = address; - } else -#ifdef HAVE_LAUNCHD - /* launchd sockets will look like 'local//tmp/launch-XgkNns/:0' */ - if(!strncmp(address,"local//",7)) { - _protocol="local"; - _host=""; - _port=address+6; - } else -#endif - if (!strncmp(address, "unix:", 5)) { - _protocol = "local"; - _host = ""; - _port = address + 5; - } - } - +done_parsing: /* * Now that we have all of the components, allocate new * string space for them. -- cgit v1.2.3 From 3b3a3bd75d86aec78f6ef893b198c3efc378bc64 Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Fri, 2 Jun 2023 17:29:41 -0700 Subject: xtrans 1.5.0 Signed-off-by: Alan Coopersmith --- configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 5786af9..f9b0e0b 100644 --- a/configure.ac +++ b/configure.ac @@ -21,7 +21,7 @@ # Initialize Autoconf AC_PREREQ([2.60]) -AC_INIT([xtrans], [1.4.0], +AC_INIT([xtrans], [1.5.0], [https://gitlab.freedesktop.org/xorg/lib/libxtrans/issues], [xtrans]) AC_CONFIG_SRCDIR([Makefile.am]) -- cgit v1.2.3