pseudo: Add patch to workaround insane path lengths

Message ID 20220318100354.1057607-1-richard.purdie@linuxfoundation.org
State New
Headers show
Series pseudo: Add patch to workaround insane path lengths | expand

Commit Message

Richard Purdie March 18, 2022, 10:03 a.m. UTC
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
---
 .../pseudo/files/pathlength.patch             | 38 +++++++++++++++++++
 meta/recipes-devtools/pseudo/pseudo_git.bb    |  1 +
 2 files changed, 39 insertions(+)
 create mode 100644 meta/recipes-devtools/pseudo/files/pathlength.patch

Patch

diff --git a/meta/recipes-devtools/pseudo/files/pathlength.patch b/meta/recipes-devtools/pseudo/files/pathlength.patch
new file mode 100644
index 00000000000..8507b0144cd
--- /dev/null
+++ b/meta/recipes-devtools/pseudo/files/pathlength.patch
@@ -0,0 +1,38 @@ 
+Crazy shell code (e.g. libtool) can pass in a command pipeline as a path which exceeds the max path
+length the system can support (6000+ chars). This will fail in libc or the syscall but if we don't
+do something here, we'd segfault before it can do that. Leave path unchanged and let libc deal 
+with it.
+
+This was observed with segfaults in libfm:do_install after the libtool upgrade. It does depend on
+the length of the local build path too.
+
+Upstream-Status: Pending
+Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
+
+Index: git/pseudo_util.c
+===================================================================
+--- git.orig/pseudo_util.c
++++ git/pseudo_util.c
+@@ -810,12 +810,21 @@ pseudo_fix_path(const char *base, const
+ 		return 0;
+ 	}
+ 	newpathlen = pseudo_path_max();
++	pathlen = strlen(path);
++	/* Crazy shell code (e.g. libtool) can pass in a command pipeline as a path which exceeds the max path
++	 * length the system can support (6000+ chars). This will fail in libc or the syscall but if we don't
++	 * do something here, we'd segfault before it can do that. Leave path unchanged and let libc deal 
++	 * with it. 
++	 */
++	if ((pathlen + baselen) >= newpathlen) {
++		return path;
++	}
+ 	if (!pathbufs[pathbuf]) {
+ 		pathbufs[pathbuf] = malloc(newpathlen);
+ 	}
+ 	newpath = pathbufs[pathbuf];
+ 	pathbuf = (pathbuf + 1) % PATHBUFS;
+-	pathlen = strlen(path);
++
+ 	/* a trailing slash has special meaning, but processing
+ 	 * trailing slashes is expensive.
+ 	 */
diff --git a/meta/recipes-devtools/pseudo/pseudo_git.bb b/meta/recipes-devtools/pseudo/pseudo_git.bb
index f9e3b469104..f6fa9010c26 100644
--- a/meta/recipes-devtools/pseudo/pseudo_git.bb
+++ b/meta/recipes-devtools/pseudo/pseudo_git.bb
@@ -2,6 +2,7 @@  require pseudo.inc
 
 SRC_URI = "git://git.yoctoproject.org/pseudo;branch=oe-core \
            file://0001-configure-Prune-PIE-flags.patch \
+           file://pathlength.patch \
            file://fallback-passwd \
            file://fallback-group \
            "