aboutsummaryrefslogtreecommitdiff
path: root/libxcb/src/xcb_util.c
diff options
context:
space:
mode:
authormarha <marha@users.sourceforge.net>2010-04-30 14:50:34 +0000
committermarha <marha@users.sourceforge.net>2010-04-30 14:50:34 +0000
commitd059ebdcb012228102f0b64f8cddf9464d5b625a (patch)
treeefb17b86cee9db4f82871f4f02e32d013a2bb837 /libxcb/src/xcb_util.c
parentf96df66d1a8e5d93a5ac597cf1ed7890d7773286 (diff)
downloadvcxsrv-d059ebdcb012228102f0b64f8cddf9464d5b625a.tar.gz
vcxsrv-d059ebdcb012228102f0b64f8cddf9464d5b625a.tar.bz2
vcxsrv-d059ebdcb012228102f0b64f8cddf9464d5b625a.zip
svn merge -r558:HEAD "^/branches/released" .
Diffstat (limited to 'libxcb/src/xcb_util.c')
-rw-r--r--libxcb/src/xcb_util.c31
1 files changed, 22 insertions, 9 deletions
diff --git a/libxcb/src/xcb_util.c b/libxcb/src/xcb_util.c
index 78bab5c5d..101532be3 100644
--- a/libxcb/src/xcb_util.c
+++ b/libxcb/src/xcb_util.c
@@ -143,13 +143,12 @@ static int _xcb_open_abstract(char *protocol, const char *file, size_t filelen);
static int _xcb_open(char *host, char *protocol, const int display)
{
-#ifdef HAVE_ABSTRACT_SOCKETS
int fd;
-#endif
static const char unix_base[] = "/tmp/.X11-unix/X";
const char *base = unix_base;
- char file[PATH_MAX + 1];
- int filelen;
+ size_t filelen;
+ char *file = NULL;
+ int actual_filelen;
if(*host)
{
@@ -184,24 +183,38 @@ static int _xcb_open(char *host, char *protocol, const int display)
#endif
}
+ filelen = strlen(base) + 1 + sizeof(display) * 3 + 1;
+ file = malloc(filelen);
+ if(file == NULL)
+ return -1;
+
/* display specifies Unix socket */
#ifdef HAVE_LAUNCHD
if(base == host)
- filelen = snprintf(file, sizeof(file), "%s:%d", base, display);
+ actual_filelen = snprintf(file, filelen, "%s:%d", base, display);
else
#endif
- filelen = snprintf(file, sizeof(file), "%s%d", base, display);
- if(filelen < 0)
+ actual_filelen = snprintf(file, filelen, "%s%d", base, display);
+ if(actual_filelen < 0)
+ {
+ free(file);
return -1;
+ }
/* snprintf may truncate the file */
- filelen = MIN(filelen, sizeof(file) - 1);
+ filelen = MIN(actual_filelen, filelen - 1);
#ifdef HAVE_ABSTRACT_SOCKETS
fd = _xcb_open_abstract(protocol, file, filelen);
if (fd >= 0 || (errno != ENOENT && errno != ECONNREFUSED))
+ {
+ free(file);
return fd;
+ }
#endif
- return _xcb_open_unix(protocol, file);
+ fd = _xcb_open_unix(protocol, file);
+ free(file);
+
+ return fd;
}
#ifdef DNETCONN