NetBSD Problem Report #55700

From  Wed Oct  7 16:00:23 2020
Return-Path: <>
Received: from ( [])
	(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
	(Client CN "", Issuer " CA" (not verified))
	by (Postfix) with ESMTPS id DB4901A923A
	for <>; Wed,  7 Oct 2020 16:00:23 +0000 (UTC)
Message-Id: <>
Date: Wed, 7 Oct 2020 18:00:19 +0200 (CEST)
From: Michael Scholz <>
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
System: NetBSD 9.99.73 NetBSD 9.99.73 (PUMPKIN) #0: Mon Oct 5 18:14:49 CEST 2020 amd64
Architecture: x86_64
Machine: amd64

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* etc should be escaped to prevent regcomp(3) from using it as
a repetition operator, I think.


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

	postinstall -s /usr/src/ -d check


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}

From: Valery Ushakov <>
Subject: Re: install/55700: postinstall doesn't work correctly with BSD
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.


From: Valery Ushakov <>
Subject: Re: install/55700: postinstall doesn't work correctly with BSD
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

 exclude_libs() then abused exlcude() without realizing it's doing it
 wrong.  It passes "" for exclusion, but the input it gets
 is "/lib/" 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
 	    set -- --fixed-strings --line-regexp --invert-match
         set -- "$@" "-e" "${pattern}"
     "${cmd}" "$@"

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


NetBSD Home
NetBSD PR Database Search

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