#1123923 libxcb should not use PATH_MAX

Package:
src:libxcb
Source:
src:libxcb
Submitter:
Petter Reinholdtsen
Date:
2026-07-02 17:45:06 UTC
Severity:
normal
Tags:
#1123923#5
Date:
2025-12-24 01:54:20 UTC
From:
To:
After getting rid of PATH_MAX and MAXPATHLEN in release 1.7 dated
2010-08-13, it seem to have been reintroduced in the current code base,
making it fail to build on Hurd.  I propose the following patch to avoid
the use of an arbitrary and for at least some file systems wrong
hardcoded limit to some paths checked.

diff --git a/src/xcb_util.c b/src/xcb_util.c
index 5124d14..def2264 100644
--- a/src/xcb_util.c
+++ b/src/xcb_util.c
@@ -104,35 +104,46 @@ static int _xcb_parse_display_path_to_socket(const char *name, char **host, char
                                              int *displayp, int *screenp)
 {
     struct stat sbuf;
-    char path[PATH_MAX];
-    size_t len;
+    char *path = NULL;
     int _screen = 0, res;

-    len = strlen(name);
-    if (len >= sizeof(path))
-        return 0;
-    memcpy(path, name, len + 1);
-    res = stat(path, &sbuf);
+    res = stat(name, &sbuf);
     if (0 != res) {
         unsigned long lscreen;
        char *dot, *endptr;
         if (res != -1 || (errno != ENOENT && errno != ENOTDIR))
             return 0;
+        path = strdup(name);
         dot = strrchr(path, '.');
-        if (!dot || dot[1] < '1' || dot[1] > '9')
+        if (!dot || dot[1] < '1' || dot[1] > '9') {
+            free(path);
+            path = NULL;
             return 0;
+        }
         *dot = '\0';
         errno = 0;
         lscreen = strtoul(dot + 1, &endptr, 10);
-        if (lscreen > INT_MAX || !endptr || *endptr || errno)
+        if (lscreen > INT_MAX || !endptr || *endptr || errno) {
+            free(path);
+            path = NULL;
             return 0;
-        if (0 != stat(path, &sbuf))
+        }
+        if (0 != stat(path, &sbuf)) {
+            free(path);
+            path = NULL;
             return 0;
+        }
         _screen = (int)lscreen;
     }

     if (host) {
-        *host = strdup(path);
+        if (path) {
+            *host = strdup(path);
+            free(path);
+            path = NULL;
+        } else {
+            *host = strdup(name);
+        }
         if (!*host)
             return 0;
     }
@@ -285,15 +296,19 @@ static int _xcb_open(const char *host, char *protocol, const int display)
         if (is_system_labeled())
         {
             const char *tsol_base = "/var/tsol/doors/.X11-unix/X";
-            char tsol_socket[PATH_MAX];
+            char *tsol_socket;
             struct stat sbuf;
-
+            size_t needed = snprintf(NULL, 0, "%s%d", tsol_base, display) + 1;
+            tsol_socket = malloc(needed);
             snprintf(tsol_socket, sizeof(tsol_socket), "%s%d", tsol_base, display);

-            if (stat(tsol_socket, &sbuf) == 0)
+            if (stat(tsol_socket, &sbuf) == 0) {
                 base = tsol_base;
-            else if (errno != ENOENT)
+                free(tsol_socket);
+            } else if (errno != ENOENT) {
+                free(tsol_socket);
                 return 0;
+           }
         }
 #endif

#1123923#10
Date:
2025-12-24 10:25:36 UTC
From:
To:
A different approach solving the same issue is already in upstream in
commit 6a7661f60a70ff42c64b32a725edcbee790d1c0d from
<URL: https://gitlab.freedesktop.org/xorg/lib/libxcb/-/merge_requests/65 >.

The remaining patch is passed on to
<URL: https://gitlab.freedesktop.org/xorg/lib/libxcb/-/merge_requests/81 >.