X-Git-Url: http://git.demorecorder.com/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fxcb_util.c;h=cc4e24af2c4d881f69f69121283f2dfd14115c1a;hb=a546d00091de0ab16374dec55e8e2fa87d6bbebf;hp=287f12fd93781933a33887298c769dd16f089e47;hpb=d06857217328c2283a8956788d72646fc67216fb;p=free-sw%2Fxcb%2Flibxcb diff --git a/src/xcb_util.c b/src/xcb_util.c index 287f12f..cc4e24a 100644 --- a/src/xcb_util.c +++ b/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)