From owner-freebsd-arch Fri Jan 10 15:39:24 2003 Delivered-To: freebsd-arch@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 82A1B37B401; Fri, 10 Jan 2003 15:39:22 -0800 (PST) Received: from ns1.xcllnt.net (209-128-86-226.BAYAREA.NET [209.128.86.226]) by mx1.FreeBSD.org (Postfix) with ESMTP id DA15C43EB2; Fri, 10 Jan 2003 15:39:21 -0800 (PST) (envelope-from marcel@xcllnt.net) Received: from athlon.pn.xcllnt.net (athlon.pn.xcllnt.net [192.168.4.3]) by ns1.xcllnt.net (8.12.6/8.12.6) with ESMTP id h0ANdL2G024366; Fri, 10 Jan 2003 15:39:21 -0800 (PST) (envelope-from marcel@piii.pn.xcllnt.net) Received: from athlon.pn.xcllnt.net (localhost [127.0.0.1]) by athlon.pn.xcllnt.net (8.12.6/8.12.6) with ESMTP id h0ANdLBR001425; Fri, 10 Jan 2003 15:39:21 -0800 (PST) (envelope-from marcel@athlon.pn.xcllnt.net) Received: (from marcel@localhost) by athlon.pn.xcllnt.net (8.12.6/8.12.6/Submit) id h0ANdLJ5001424; Fri, 10 Jan 2003 15:39:21 -0800 (PST) (envelope-from marcel) Date: Fri, 10 Jan 2003 15:39:21 -0800 From: Marcel Moolenaar To: arch@FreeBSD.org Cc: ru@FreeBSD.org Subject: Infinite loop in make(1) Message-ID: <20030110233921.GA1381@athlon.pn.xcllnt.net> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.1i Sender: owner-freebsd-arch@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG Gang, During release building we hit upon an infinite loop in make(1). This was cause by a substitution of which the LHS and RHS were both empty and the substitution was to be applied globally. For example (from ports/devel/m6811-gcc/Makefile): CFLAGS := ${CFLAGS:S/${_CPUCFLAGS}//g} If ${_CPUCFLAGS} is empty, the expansion obviously yields S///g. This causes make(1) to enter an infinite loop. Below a patch to prevent the infinite loop by forcing non-global substitution. This still allows S/^/foo/ and S/$/bar/ and even S///, but avoids the danger zone. Is this correct? \begin{patch} Index: var.c =================================================================== RCS file: /home/ncvs/src/usr.bin/make/var.c,v retrieving revision 1.40 diff -u -r1.40 var.c --- var.c 8 Nov 2002 16:59:11 -0000 1.40 +++ var.c 10 Jan 2003 23:30:58 -0000 @@ -1349,6 +1349,17 @@ cp++; } + /* + * Replacing the empty string for something else when + * done globally causes an infinite loop. The only + * meaningful substitution of the empty string would + * be those anchored by '^' or '$'. Thus, we can + * safely turn the substitution into a non-global one + * if the LHS is the empty string. + */ + if (pattern.leftLen == 0) + pattern.flags &= ~VAR_SUB_GLOBAL; + termc = *cp; newStr = VarModify(str, VarSubstitute, (void *)&pattern); \end{patch} -- Marcel Moolenaar USPA: A-39004 marcel@xcllnt.net To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-arch" in the body of the message