NetBSD Problem Report #55700

From mike@fth-devel.net  Wed Oct  7 16:00:23 2020
Return-Path: <mike@fth-devel.net>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
	(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
	(Client CN "mail.NetBSD.org", Issuer "mail.NetBSD.org CA" (not verified))
	by mollari.NetBSD.org (Postfix) with ESMTPS id DB4901A923A
	for <gnats-bugs@gnats.NetBSD.org>; Wed,  7 Oct 2020 16:00:23 +0000 (UTC)
Message-Id: <202010071600.097G0JoY022103@pumpkin.fth-devel.net>
Date: Wed, 7 Oct 2020 18:00:19 +0200 (CEST)
From: Michael Scholz <mike@fth-devel.net>
Reply-To: mike@fth-devel.net
To: gnats-bugs@NetBSD.org
Subject: postinstall doesn't work correctly with BSD grep(1)
X-Send-Pr-Version: 3.95

>Number:         55700
>Category:       install
>Synopsis:       postinstall doesn't work correctly with BSD grep(1)
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    install-manager
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Wed Oct 07 16:05:00 +0000 2020
>Last-Modified:  Wed Oct 07 23:25:01 +0000 2020
>Originator:     Michael Scholz
>Release:        NetBSD 9.99.73
>Organization:
>Environment:
System: NetBSD pumpkin.fth-devel.net 9.99.73 NetBSD 9.99.73 (PUMPKIN) #0: Mon Oct 5 18:14:49 CEST 2020 toor@pumpkin.fth-devel.net:/usr/obj/usr/src/sys/arch/amd64/compile/PUMPKIN amd64
Architecture: x86_64
Machine: amd64
>Description:

With MKBSDGREP=yes in /etc/mk.conf, after compiling and installing the
system and calling postinstall, /usr/sbin/postinstall reports at least
two times:

	grep: repetition-operator operand invalid

This happens during "obsolete check" in exclude_libs(); the '++' in
libc++.so* etc should be escaped to prevent regcomp(3) from using it as
a repetition operator, I think.

>How-To-Repeat:

Compile and install the system with MKBSDGREP=yes and call:

	postinstall -s /usr/src/ -d check

>Fix:

In function exclude_libs() add '-e s/\\++/\\\\++/g' to the sed utility
to escape '++':

--- /usr/sbin/postinstall	2020-09-04 11:52:53.000000000 +0200
+++ postinstall	2020-10-07 17:34:53.405233356 +0200
@@ -593,7 +593,7 @@
 exclude_libs() {
 	local target="$(ls -l -d lib*.so.* 2> /dev/null \
 	    | ${AWK} '{ print $11; }' \
-	    | ${SED} -e 's@.*/@@' | ${SORT} -u)"
+	    | ${SED} -e 's@.*/@@' -e s/\\++/\\\\++/g | ${SORT} -u)"
 	exclude -t ${target}
 }

>Audit-Trail:
From: Valery Ushakov <uwe@stderr.spb.ru>
To: gnats-bugs@netbsd.org
Cc: 
Subject: Re: install/55700: postinstall doesn't work correctly with BSD
 grep(1)
Date: Wed, 7 Oct 2020 22:27:09 +0300

 This actually points to a larger problem, the pathnames are used as
 regular expressions even though they are not (semantically) supposed
 to.  So other metacharacters (e.g. dot that is ubiquitous) can
 potentially cause trouble, it's just that ++ in c++ exposed this.
 It should be fixed properly.

 -uwe

From: Valery Ushakov <uwe@stderr.spb.ru>
To: gnats-bugs@netbsd.org
Cc: 
Subject: Re: install/55700: postinstall doesn't work correctly with BSD
 grep(1)
Date: Thu, 8 Oct 2020 02:21:12 +0300

 Before I forget, exclude_libs() is broken in other ways.  Sorry to
 hijack this PR, but it's related.

 Existing uses of exclude() in do_defaults() and do_rc() take care to
 strip the directory name - but it's obfuscated: the \(\) parens come
 from the call but the \1 that refer to them is hidden deep inside
 select_set_files().

 exclude_libs() then abused exlcude() without realizing it's doing it
 wrong.  It passes "libfoo.so.1.2" for exclusion, but the input it gets
 is "/lib/libfoo.so.1.2" and b/c of the ^-anchored pattern it doesn't
 work, nothing is ever excluded.

 It's not immediately obvious to me why exclude() doesn't also $-anchor
 its patterns.  If the uses in do_rc() and do_defaults() should
 $-anchor them, then I'd ditch the existing baroque version in favor of
 something like (untested):

 exclude() {
     local cmd="${CAT}"
     for pattern; do
         if [ "${cmd}" = "${CAT}" ]; then
             cmd="${GREP}"
 	    set -- --fixed-strings --line-regexp --invert-match
         fi
         set -- "$@" "-e" "${pattern}"
     done
     "${cmd}" "$@"
 }


 and then rewrite exlcude_libs() to not use exlcude(), trying to
 over-generalize the latter.

 -uwe

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.46 2020/01/03 16:35:01 leot Exp $
$NetBSD: gnats_config.sh,v 1.9 2014/08/02 14:16:04 spz Exp $
Copyright © 1994-2020 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.