commit:     77c6aa5ac90ebe5ef18bf7f6afe44833b383c974
Author:     Sam James <sam <AT> gentoo <DOT> org>
AuthorDate: Fri Jan 28 02:30:08 2022 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Fri Jan 28 02:30:42 2022 +0000
URL:        https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=77c6aa5a

sys-libs/gpm: fix build with musl, misc upstream backports

- Backport musl patches
- Backport include path fix
- Backport signedness fix

Closes: https://bugs.gentoo.org/829581
Signed-off-by: Sam James <sam <AT> gentoo.org>

 sys-libs/gpm/files/gpm-1.20.7-gcc-include.patch |  18 +++
 sys-libs/gpm/files/gpm-1.20.7-musl.patch        | 143 ++++++++++++++++++++++++
 sys-libs/gpm/files/gpm-1.20.7-signedness.patch  |  20 ++++
 sys-libs/gpm/gpm-1.20.7-r4.ebuild               | 112 +++++++++++++++++++
 4 files changed, 293 insertions(+)

diff --git a/sys-libs/gpm/files/gpm-1.20.7-gcc-include.patch 
b/sys-libs/gpm/files/gpm-1.20.7-gcc-include.patch
new file mode 100644
index 000000000000..51d047c465cc
--- /dev/null
+++ b/sys-libs/gpm/files/gpm-1.20.7-gcc-include.patch
@@ -0,0 +1,18 @@
+https://github.com/telmich/gpm/commit/80cac2a2bd7eed7e80626559f792f37319030729
+
+From: "Desmond O. Chang" <[email protected]>
+Date: Wed, 13 Apr 2016 21:17:48 +0800
+Subject: [PATCH] Add gcc include path
+
+Close #13
+--- a/src/Makefile.in
++++ b/src/Makefile.in
+@@ -96,7 +96,7 @@ $(DEPFILE) dep: prog/gpm-root.c
+ 
+       # create dependencies
+       for DEPS in `echo *.c */*.c`; do \
+-      $(CC) -I. -I $(srcdir) -M @CPPFLAGS@ $(CPPFLAGS) $$DEPS | \
++      $(CC) -I. -I $(srcdir) -I $(srcdir)/headers -M @CPPFLAGS@ $(CPPFLAGS) 
$$DEPS | \
+       $(SED) 's/^\(.*\)\.o\([ :]+\)/\1.o \1.lo\2/g' >> $(DEPFILE) ; done
+ 
+ ### INSTALL

diff --git a/sys-libs/gpm/files/gpm-1.20.7-musl.patch 
b/sys-libs/gpm/files/gpm-1.20.7-musl.patch
new file mode 100644
index 000000000000..37f8542a87aa
--- /dev/null
+++ b/sys-libs/gpm/files/gpm-1.20.7-musl.patch
@@ -0,0 +1,143 @@
+https://github.com/telmich/gpm/commit/d88fb1de5803c366ab62f7de9ee5d83207fb2afe
+https://github.com/telmich/gpm/commit/4a938233fbe6de7af05aabc74891b68d4bae40f8
+https://bugs.gentoo.org/829581
+
+From: Dima Krasner <[email protected]>
+Date: Wed, 12 Nov 2014 23:06:46 +0200
+Subject: [PATCH] Added musl support to libgpm and the daemon.
+
+--- a/src/daemon/open_console.c
++++ b/src/daemon/open_console.c
+@@ -21,6 +21,7 @@
+ 
+ #include <fcntl.h>                  /* open and co.      */
+ #include <sys/stat.h>               /* stat()            */
++#include <sys/types.h>              /* major()           */
+ #include <sys/ioctl.h>              /* ioctl             */
+ 
+ /* Linux specific (to be outsourced in gpm2 */
+--- a/src/prog/display-buttons.c
++++ b/src/prog/display-buttons.c
+@@ -36,6 +36,7 @@
+ #include <stdio.h>            /* printf()             */
+ #include <time.h>             /* time()               */
+ #include <errno.h>            /* errno                */
++#include <sys/select.h>       /* fd_set and FD_*      */
+ #include <gpm.h>              /* gpm information      */
+ 
+ /* display resulting data */
+--- a/src/prog/display-coords.c
++++ b/src/prog/display-coords.c
+@@ -38,6 +38,7 @@
+ #include <stdio.h>            /* printf()             */
+ #include <time.h>             /* time()               */
+ #include <errno.h>            /* errno                */
++#include <sys/select.h>       /* fd_set and FD_*      */
+ #include <gpm.h>              /* gpm information      */
+ 
+ /* display resulting data */
+--- a/src/prog/gpm-root.y
++++ b/src/prog/gpm-root.y
+@@ -1199,9 +1199,9 @@ int main(int argc, char **argv)
+ #if defined(__GLIBC__)
+    __sigemptyset(&childaction.sa_mask);
+ #else /* __GLIBC__ */
+-   childaction.sa_mask=0;
++   sigemptyset(&childaction.sa_mask);
+ #endif /* __GLIBC__ */
+-   childaction.sa_flags=SA_INTERRUPT; /* need to break the select() call */
++   childaction.sa_flags=0;
+    sigaction(SIGCHLD,&childaction,NULL);
+ 
+    /*....................................... Connect and get your buffer */
+
+From: Kurt Nalty <[email protected]>
+Date: Sat, 29 Dec 2018 23:44:24 -0600
+Subject: [PATCH 1/4] Update gpm.c
+
+--- a/src/daemon/gpm.c
++++ b/src/daemon/gpm.c
+@@ -29,7 +29,7 @@
+ #include <signal.h>        /* SIGPIPE */
+ #include <time.h>          /* time() */
+ #include <sys/param.h>
+-#include <sys/fcntl.h>     /* O_RDONLY */
++#include <fcntl.h>         /* O_RDONLY */
+ #include <sys/wait.h>      /* wait()   */
+ #include <sys/stat.h>      /* mkdir()  */
+ #include <sys/time.h>      /* timeval */
+
+From: Kurt Nalty <[email protected]>
+Date: Sat, 29 Dec 2018 23:47:17 -0600
+Subject: [PATCH 2/4] Add include <string.h>
+
+Added
+ line 28, #include <string.h>                 /* strcpy, bzero     */
+for musl compilation
+--- a/src/daemon/old_main.c
++++ b/src/daemon/old_main.c
+@@ -25,6 +25,7 @@
+ #include <signal.h>                 /* guess again       */
+ #include <errno.h>                  /* guess again       */
+ #include <unistd.h>                 /* unlink            */
++#include <string.h>                 /* strcpy, bzero     */
+ #include <sys/stat.h>               /* chmod             */
+ 
+ #include <linux/kd.h>               /* linux hd*         */
+
+From: Kurt Nalty <[email protected]>
+Date: Sat, 29 Dec 2018 23:52:58 -0600
+Subject: [PATCH 3/4] Update liblow.c for musl compatible
+
+Changed #include <sys/fcntl.h>   to    #include <fcntl.h>
+Changed SA_NOMASK to SA_NODEFER on lines 176, 367
+--- a/src/lib/liblow.c
++++ b/src/lib/liblow.c
+@@ -33,7 +33,7 @@
+ #include <sys/types.h>     /* socket() */
+ #include <sys/socket.h>    /* socket() */
+ #include <sys/un.h>        /* struct sockaddr_un */
+-#include <sys/fcntl.h>     /* O_RDONLY */
++#include <fcntl.h>     /* O_RDONLY */
+ #include <sys/stat.h>      /* stat() */
+ 
+ #ifdef  SIGTSTP         /* true if BSD system */
+@@ -173,7 +173,7 @@ static void gpm_suspend_hook (int signum)
+   /* Reincarnation. Prepare for another death early. */
+   sigemptyset(&sa.sa_mask);
+   sa.sa_handler = gpm_suspend_hook;
+-  sa.sa_flags = SA_NOMASK;
++  sa.sa_flags = SA_NODEFER;
+   sigaction (SIGTSTP, &sa, 0);
+ 
+   /* Pop the gpm stack by closing the useless connection */
+@@ -364,7 +364,7 @@ int Gpm_Open(Gpm_Connect *conn, int flag)
+ 
+          /* if signal was originally ignored, job control is not supported */
+          if (gpm_saved_suspend_hook.sa_handler != SIG_IGN) {
+-            sa.sa_flags = SA_NOMASK;
++            sa.sa_flags = SA_NODEFER;
+             sa.sa_handler = gpm_suspend_hook;
+             sigaction(SIGTSTP, &sa, 0);
+          }
+
+From: Kurt Nalty <[email protected]>
+Date: Mon, 31 Dec 2018 18:41:19 -0600
+Subject: [PATCH 4/4] Aligned comments
+
+--- a/src/lib/liblow.c
++++ b/src/lib/liblow.c
+@@ -29,11 +29,12 @@
+ #include <string.h>        /* strncmp */
+ #include <unistd.h>        /* select(); */
+ #include <errno.h>
++#include <fcntl.h>         /* O_RDONLY */
++
+ #include <sys/time.h>      /* timeval */
+ #include <sys/types.h>     /* socket() */
+ #include <sys/socket.h>    /* socket() */
+ #include <sys/un.h>        /* struct sockaddr_un */
+-#include <fcntl.h>     /* O_RDONLY */
+ #include <sys/stat.h>      /* stat() */
+ 
+ #ifdef  SIGTSTP         /* true if BSD system */

diff --git a/sys-libs/gpm/files/gpm-1.20.7-signedness.patch 
b/sys-libs/gpm/files/gpm-1.20.7-signedness.patch
new file mode 100644
index 000000000000..3904bfd6cca3
--- /dev/null
+++ b/sys-libs/gpm/files/gpm-1.20.7-signedness.patch
@@ -0,0 +1,20 @@
+https://github.com/telmich/gpm/commit/4337fd9fc2d2ea83654f2ca69245503730231ac3
+
+From: iljavs <[email protected]>
+Date: Mon, 27 Jun 2016 01:17:57 -0700
+Subject: [PATCH] fix signedness issue
+
+This commit fixes a signedness issue, where a negative vc coming from a 
malicious client could possibly cause memory corruption.
+--- a/src/daemon/processconn.c
++++ b/src/daemon/processconn.c
+@@ -67,7 +67,8 @@ int processConn(int fd)
+       return -1;
+    }
+ 
+-   if((vc = request->vc) > MAX_VC) {
++   vc = request->vc;
++   if(vc > MAX_VC || vc < 0) {
+       gpm_report(GPM_PR_DEBUG, GPM_MESS_REQUEST_ON, vc, MAX_VC);
+       free(info);
+       close(newfd);
+

diff --git a/sys-libs/gpm/gpm-1.20.7-r4.ebuild 
b/sys-libs/gpm/gpm-1.20.7-r4.ebuild
new file mode 100644
index 000000000000..d554df614508
--- /dev/null
+++ b/sys-libs/gpm/gpm-1.20.7-r4.ebuild
@@ -0,0 +1,112 @@
+# Copyright 1999-2022 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+# emacs support disabled due to #99533 #335900
+
+EAPI=7
+
+inherit autotools linux-info systemd usr-ldscript multilib-minimal
+
+DESCRIPTION="Console-based mouse driver"
+HOMEPAGE="https://www.nico.schottelius.org/software/gpm/";
+SRC_URI="
+       https://www.nico.schottelius.org/software/${PN}/archives/${P}.tar.lzma
+       mirror://gentoo/${P}-docs.patch.xz"
+
+LICENSE="GPL-2"
+SLOT="0"
+KEYWORDS="~alpha ~amd64 ~arm ~arm64 ~hppa ~ia64 ~m68k ~mips ~ppc ~ppc64 ~riscv 
~s390 ~sparc ~x86"
+IUSE="selinux"
+
+RDEPEND="
+       sys-libs/ncurses:=[${MULTILIB_USEDEP}]
+       selinux? ( sec-policy/selinux-gpm )"
+DEPEND="${RDEPEND}"
+BDEPEND="
+       app-arch/xz-utils
+       sys-apps/texinfo
+       virtual/yacc"
+
+CONFIG_CHECK="~INPUT_MOUSEDEV"
+ERROR_INPUT_MOUSEDEV="CONFIG_INPUT_MOUSEDEV:\tis not set (required to expose 
mice for GPM)"
+
+pkg_pretend() {
+       check_extra_config
+}
+
+src_prepare() {
+       eapply "${FILESDIR}"/${P}-sysmacros.patch
+
+       # Hack up the docs until we get this sorted upstream.
+       # https://github.com/telmich/gpm/issues/8
+       eapply "${WORKDIR}"/${P}-docs.patch
+       touch -r . doc/* || die
+
+       # bug #629774
+       eapply "${FILESDIR}"/${P}-glibc-2.26.patch
+       # bug #705878
+       eapply "${FILESDIR}"/${P}-gcc-10.patch
+       # bug #829581
+       eapply "${FILESDIR}"/${P}-musl.patch
+       #
+       eapply "${FILESDIR}"/${P}-gcc-include.patch
+       eapply "${FILESDIR}"/${P}-signedness.patch
+
+       eapply_user
+
+       # fix ABI values
+       sed -i \
+               -e '/^abi_lev=/s:=.*:=1:' \
+               -e '/^abi_age=/s:=.*:=20:' \
+               configure.ac.footer || die
+       # Rebuild autotools since release doesn't include them.
+       # Should be fixed with the next release though.
+       # https://github.com/telmich/gpm/pull/15
+       sed -i -e '/ACLOCAL/,$d' autogen.sh || die
+       ./autogen.sh
+       eautoreconf
+
+       # Out-of-tree builds are broken.
+       # https://github.com/telmich/gpm/issues/16
+       multilib_copy_sources
+}
+
+multilib_src_configure() {
+       econf \
+               --disable-static \
+               --sysconfdir="${EPREFIX}"/etc/gpm \
+               emacs="${BROOT}"/bin/false
+}
+
+_emake() {
+       emake \
+               EMACS=: ELISP="" \
+               $(multilib_is_native_abi || echo "PROG= ") \
+               "$@"
+}
+
+multilib_src_compile() {
+       _emake
+}
+
+multilib_src_test() {
+       _emake check
+}
+
+multilib_src_install() {
+       _emake DESTDIR="${D}" install
+
+       dosym libgpm.so.1 /usr/$(get_libdir)/libgpm.so
+       gen_usr_ldscript -a gpm
+}
+
+multilib_src_install_all() {
+       insinto /etc/gpm
+       doins conf/gpm-*.conf
+
+       dodoc README TODO doc/Announce doc/FAQ doc/README*
+
+       newinitd "${FILESDIR}"/gpm.rc6-2 gpm
+       newconfd "${FILESDIR}"/gpm.conf.d gpm
+       systemd_dounit "${FILESDIR}"/gpm.service
+}

Reply via email to