NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

bin/50896: sloppy usage checking in shell builtin 'shift'



>Number:         50896
>Category:       bin
>Synopsis:       sloppy usage checking in shell builtin 'shift'
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    bin-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sat Mar 05 13:20:00 +0000 2016
>Originator:     Robert Elz
>Release:        NetBSD 7.99.26 (all versions up to today (at least))
>Organization:
>Environment:
System: NetBSD andromeda.noi.kre.to 7.99.26 NetBSD 7.99.26 (VBOX64-1.1-20160128) #43: Thu Jan 28 16:09:08 ICT 2016 kre%onyx.coe.psu.ac.th@localhost:/usr/obj/current/kernels/amd64/VBOX64 amd64
Architecture: x86_64
Machine: amd64
>Description:

	The shell builtin "shift" takes an optional single numeric
	argument.  Our shell correctly tests whether that arg (if
	given) is in fact numeric, and errors (as it should) if not.
	It also checks it is in range, and errors (as it is allowed
	to do - optional behavior is for shift to return a non-zero
	status) if not.  (It also sub-optimally handles the weird
	case of "shift 0" but that's so rare it isn't worth putting
	in special code to optimize it.)

	What it doesn't do (and no do most other shells it seems,
	though bash does) is object if there is more than 1 arg.

>How-To-Repeat:

	sh -c "set -- a b c; shift 1 foo; echo this output should not appear"

	Since shift is a special builtin, in a non-interactive shell
	the erroneous shift should cause the shell to exit (with an
	error message).

>Fix:
	I have a fix for this (it is trivial), it will be in one of
	the next set of patches that get applied to sh.  This PR is
	really just a placeholder to the cvs commit log can refer to it.

	It is also supremely unimportant, so there will be no great rush
	to get the patch applied... it can wait until there are more to
	happen at the same time.



Home | Main Index | Thread Index | Old Index