aboutsummaryrefslogtreecommitdiff
path: root/libxcb/src/xcb_util.c
diff options
context:
space:
mode:
Diffstat (limited to 'libxcb/src/xcb_util.c')
-rw-r--r--libxcb/src/xcb_util.c29
1 files changed, 22 insertions, 7 deletions
diff --git a/libxcb/src/xcb_util.c b/libxcb/src/xcb_util.c
index 287f12fd9..cc4e24af2 100644
--- a/libxcb/src/xcb_util.c
+++ b/libxcb/src/xcb_util.c
@@ -145,8 +145,9 @@ static int _xcb_open(char *host, char *protocol, const int display)
#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)
{
@@ -181,24 +182,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;
}
static int _xcb_socket(int family, int type, int proto)