NetBSD Problem Report #56663
From www@netbsd.org Mon Jan 24 07:31:26 2022
Return-Path: <www@netbsd.org>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
(using TLSv1.3 with cipher TLS_AES_256_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 675621A9239
for <gnats-bugs@gnats.NetBSD.org>; Mon, 24 Jan 2022 07:31:26 +0000 (UTC)
Message-Id: <20220124073125.262221A923A@mollari.NetBSD.org>
Date: Mon, 24 Jan 2022 07:31:25 +0000 (UTC)
From: yetoohappy@gmail.com
Reply-To: yetoohappy@gmail.com
To: gnats-bugs@NetBSD.org
Subject: Disable RANDOM variable in sh(1) POSIX mode
X-Send-Pr-Version: www-1.0
>Number: 56663
>Category: standards
>Synopsis: Disable RANDOM variable in sh(1) POSIX mode
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: standards-manager
>State: closed
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Mon Jan 24 07:35:00 +0000 2022
>Closed-Date: Wed Dec 20 06:19:01 +0000 2023
>Last-Modified: Wed Dec 20 06:19:01 +0000 2023
>Originator: yetoo
>Release: NetBSD 9.99.93 Jan 14 build
>Organization:
>Environment:
NetBSD alarm.lan 9.99.93 NetBSD 9.99.93 (GENERIC) #0: Fri Jan 14 07:40:52 UTC 2022 mkrepro@mkrepro.NetBSD.org:/usr/src/sys/arch/i386/compile/GENERIC i386
>Description:
The RANDOM environment variable is not POSIX compliant and should be disabled in posix mode.
>How-To-Repeat:
1. Enter /bin/sh
2. execute set -o posix
3. verify posix is set via set -o
4. echo $RANDOM
5. Notice the number that is generated
>Fix:
>Release-Note:
>Audit-Trail:
From: Robert Elz <kre@munnari.OZ.AU>
To: gnats-bugs@netbsd.org
Cc:
Subject: Re: standards/56663: Disable RANDOM variable in sh(1) POSIX mode
Date: Mon, 24 Jan 2022 23:02:10 +0700
Date: Mon, 24 Jan 2022 07:35:00 +0000 (UTC)
From: yetoohappy@gmail.com
Message-ID: <20220124073500.6D46D1A923D@mollari.NetBSD.org>
| The RANDOM environment variable is not POSIX compliant
This would be extraordinary were it true, as the posix shell is
based upon ksh88 (that's the canonical sh for posix) and ksh88
supports the RANDOM variable in essentially the same way that
the NetBSD shell does (as do several other shells, including
/bin/ksh on NetBSD - aka some ancient version of pdksh, with
some local fixes).
POSIX did not require all of ksh88 be implemented in the standard
shell (eg: select is not required) and RANDOM is in that set of
"not required" features, but nothing that is in ksh88 is prohibited
(as that would have made the canonical shell non-compliant) except
where it was (at the time regarded as a bug in ksh88 - there were
just a couple of those things, RANDOM is not one).
What POSIX does say is:
From the current standard (this is not changed in current drafts of
the forthcoming version) in XBD (Basic Definitions) Section 8.1:
It is unwise to conflict with certain variables that are
frequently exported by widely used command interpreters and
applications:
Then it gives a (lengthy) list of variables that applications should
void using, included in which is RANDOM. (That is, avoid using in
a conflicting manner, it is obviously OK to use these vars in the way
they are intended, though not all of them exist everywhere.)
The section of POSIX related to the shell XCU (commands and utilities)
doesn't mention RANDOM at all (that I can see anyway) - it does however
reference XBD chapter 8.
There are differences in the details of how various implementations
deal with RANDOM in various cases, but in none of them does turning on
posix mode (or its equivalent, where it exists - ksh implementations,
unsurprisingly, have no such concept) cause RANDOM to cease providing
random numbers (though in some shells there are ways to make that happen).
There is no bug here, and certainly no standards related issue.
From: Yetoo Happy <yetoohappy@gmail.com>
To: gnats-bugs@netbsd.org
Cc: standards-manager@netbsd.org, gnats-admin@netbsd.org,
netbsd-bugs@netbsd.org
Subject: Re: standards/56663: Disable RANDOM variable in sh(1) POSIX mode
Date: Mon, 24 Jan 2022 14:21:34 -0800
So RANDOM not being disabled in posix mode isn't a bug; can the class
be changed to a change-request and moved to bin if applicable? It
would be helpful if the posix mode was strict like FreeBSD's sh where
RANDOM doesn't work so it would be easier to vet a script's
portability on NetBSD.
From: Robert Elz <kre@munnari.OZ.AU>
To: Yetoo Happy <yetoohappy@gmail.com>
Cc: gnats-bugs@netbsd.org
Subject: Re: standards/56663: Disable RANDOM variable in sh(1) POSIX mode
Date: Tue, 25 Jan 2022 06:08:31 +0700
Date: Mon, 24 Jan 2022 14:21:34 -0800
From: Yetoo Happy <yetoohappy@gmail.com>
Message-ID: <CALT2f4vjTDbBjEZwLnVLcWAOahCeA0egUFV4XWNZ1BjHPOQLog@mail.gmail.com>
| can the class be changed to a change-request and moved to bin if
| applicable?
It could be.
| It would be helpful if the posix mode was strict like FreeBSD's sh where
| RANDOM doesn't work so it would be easier to vet a script's portability
| on NetBSD.
If a script is using $RANDOM other than as a source of (fairly weak)
random numbers, it definitely isn't portable - all you need to do is
search for RANDOM in the script, and if found, see how/why it is being used.
Does FreeBSD's sh support RANDOM at all (posix mode or otherwise) ?
Last time I looked it didn't (nor do some other shells). That's all OK,
they're not required to.
But RANDOM use isn't a question for the shell really, but the application,
which should really not be using that as a variable name -- unless it wants
random numbers, and then it needs to test to see if it works first, just:
if [ "$RANDOM" = "$RANDOM" ]; then fail 'No $RANDOM support in shell'; fi
(or similar) should be included (assuming a suitable fail() function exists,
otherwise send an error message and exit).
If you see something like that, then you can generally assume that any other
use of RANDOM in the script is probably OK (but not portable to all shells).
If not, and if RANDOM is used at all, it takes more careful analysis (but
either way, the script is not portable).
kre
ps: all shells (well, almost all shells) have all kinds of extensions to
POSIX, that are not disabled in posix mode (when they have such a thing),
That is allowed by POSIX. The shell's posix mode is generally to alter
behaviour where we are deliberately doing something different to what
POSIX says we should (or should not) do (or in at least one case,
"previously said"). If anything were to ever change wrt the way we have
RANDOM implemented, it would not depend upon posix mode (-o posix) - or not
unless something very odd happens, and POSIX decides to specify that RANDOM
must be implemented, but in a way that's different to the way we prefer to
have it work.
From: Yetoo <yetoohappy@gmail.com>
To: gnats-bugs@netbsd.org
Cc: standards-manager@netbsd.org, gnats-admin@netbsd.org,
netbsd-bugs@netbsd.org
Subject: Re: standards/56663: Disable RANDOM variable in sh(1) POSIX mode
Date: Mon, 24 Jan 2022 17:09:29 -0800
On Mon, Jan 24, 2022 at 3:10 PM Robert Elz <kre@munnari.oz.au> wrote:
> Does FreeBSD's sh support RANDOM at all (posix mode or otherwise) ?
> Last time I looked it didn't (nor do some other shells). That's all OK,
> they're not required to.
FreeBSD's sh doesn't support RANDOM at all and doesn't have posix mode
as it's default.
State-Changed-From-To: open->closed
State-Changed-By: kre@NetBSD.org
State-Changed-When: Wed, 20 Dec 2023 06:19:01 +0000
State-Changed-Why:
This is not a bug, certainly not a standards issue.
It is unlikely any change will be made, but if there is
a real problem, open a new PR about that specific problem.
>Unformatted:
(Contact us)
$NetBSD: query-full-pr,v 1.47 2022/09/11 19:34:41 kim Exp $
$NetBSD: gnats_config.sh,v 1.9 2014/08/02 14:16:04 spz Exp $
Copyright © 1994-2023
The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.