git: 1b4b3e9ce1e7 - main - x11-wm/fvwm3: Avoid crash in FvwmIconMan

From: Cy Schubert <cy_at_FreeBSD.org>
Date: Thu, 28 Jul 2022 12:57:20 UTC
The branch main has been updated by cy:

URL: https://cgit.FreeBSD.org/ports/commit/?id=1b4b3e9ce1e7255519f84324f3a7a4c1d7cd3f33

commit 1b4b3e9ce1e7255519f84324f3a7a4c1d7cd3f33
Author:     Felix Palmen <felix@palmen-it.de>
AuthorDate: 2022-07-18 23:20:36 +0000
Commit:     Cy Schubert <cy@FreeBSD.org>
CommitDate: 2022-07-28 12:56:00 +0000

    x11-wm/fvwm3: Avoid crash in FvwmIconMan
    
    Add a patch working around the crash by initializing some struct member
    to NULL that's otherwise used uninitialized and backporting some code
    from upstream's main branch to correctly handle that case.
    
    PR:             265291
    MFH:            2022Q3
---
 x11-wm/fvwm3/Makefile             |  2 +-
 x11-wm/fvwm3/files/patch-pr265291 | 51 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 52 insertions(+), 1 deletion(-)

diff --git a/x11-wm/fvwm3/Makefile b/x11-wm/fvwm3/Makefile
index ed384f122d7b..3d1424cb679b 100644
--- a/x11-wm/fvwm3/Makefile
+++ b/x11-wm/fvwm3/Makefile
@@ -1,6 +1,6 @@
 PORTNAME=	fvwm3
 PORTVERSION=	1.0.4
-PORTREVISION=	5
+PORTREVISION=	6
 CATEGORIES=	x11-wm
 MASTER_SITES=	https://github.com/fvwmorg/fvwm3/releases/download/${PORTVERSION}/ \
 		http://fvwm.sourceforge.net/generated/icon_download/:icons
diff --git a/x11-wm/fvwm3/files/patch-pr265291 b/x11-wm/fvwm3/files/patch-pr265291
new file mode 100644
index 000000000000..59fa97e71389
--- /dev/null
+++ b/x11-wm/fvwm3/files/patch-pr265291
@@ -0,0 +1,51 @@
+Avoid a crash caused by UB (use of uninitialized value).
+
+Initialize a value to NULL and backport code handling this case from main.
+This won't hurt and avoids the crash, although it's probably not the correct
+fix.
+
+Upstream issue: https://github.com/fvwmorg/fvwm3/issues/659
+
+--- modules/FvwmIconMan/x.c.orig	2022-07-18 23:18:50 UTC
++++ modules/FvwmIconMan/x.c
+@@ -742,6 +742,7 @@ void X_init_manager (int man_id)
+     char *scr;
+     fscreen_scr_arg arg;
+     arg.mouse_ev = NULL;
++    arg.name = NULL;
+ 
+     geometry_mask = FScreenParseGeometryWithScreen(
+       man->geometry_str, &man->geometry.x, &man->geometry.y,
+--- libs/FScreen.c.orig	2022-07-21 10:39:30 UTC
++++ libs/FScreen.c
+@@ -186,6 +186,11 @@ monitor_resolve_name(const char *scr)
+ {
+ 	struct monitor	*m = NULL;
+ 
++	if (scr == NULL)
++	{
++		return NULL;
++	}
++
+ 	/* Assume the monitor name is a literal RandR name (such as HDMI2) and
+ 	 * look it up regardless.
+ 	 */
+@@ -698,11 +703,14 @@ FindScreen(fscreen_scr_arg *arg, fscreen_scr_t screen)
+ 		m = FindScreenOfXY(arg->xypos.x, arg->xypos.y);
+ 		break;
+ 	case FSCREEN_BY_NAME:
+-		if (arg == NULL || arg->name == NULL) {
+-			/* XXX: Work out what to do. */
+-			break;
++		if (arg == NULL || arg->name == NULL)
++		{
++			m = monitor_by_primary();
+ 		}
+-		m = monitor_resolve_name(arg->name);
++		else
++		{
++			m = monitor_resolve_name(arg->name);
++		}
+ 		break;
+ 	default:
+ 		/* XXX: Possible error condition here? */