Path: csiph.com!xmission!news.snarked.org!news.linkpendium.com!news.linkpendium.com!panix!usenet.stanford.edu!not-for-mail From: Eric Blake Newsgroups: gnu.bash.bug Subject: Re: Incorrect option processing in builtin printf(1) Date: Mon, 22 Jul 2019 14:49:53 -0500 Organization: Red Hat, Inc. Lines: 123 Approved: bug-bash@gnu.org Message-ID: References: <201907221756.x6MHuxaR019063@jinx.noi.kre.to> <274806f3-f166-0fa8-0aff-9730a7f9b680@redhat.com> NNTP-Posting-Host: lists.gnu.org Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="Uzj7VqM0iMxo1SQjzioOIbAgirMXJKzvb" X-Trace: usenet.stanford.edu 1563825001 9418 209.51.188.17 (22 Jul 2019 19:50:01 GMT) X-Complaints-To: action@cs.stanford.edu To: kre@munnari.OZ.AU, bug-bash@gnu.org Envelope-to: bug-bash@gnu.org Openpgp: preference=signencrypt Autocrypt: addr=eblake@redhat.com; keydata= xsBNBEvHyWwBCACw7DwsQIh0kAbUXyqhfiKAKOTVu6OiMGffw2w90Ggrp4bdVKmCaEXlrVLU xphBM8mb+wsFkU+pq9YR621WXo9REYVIl0FxKeQo9dyQBZ/XvmUMka4NOmHtFg74nvkpJFCD TUNzmqfcjdKhfFV0d7P/ixKQeZr2WP1xMcjmAQY5YvQ2lUoHP43m8TtpB1LkjyYBCodd+LkV GmCx2Bop1LSblbvbrOm2bKpZdBPjncRNob73eTpIXEutvEaHH72LzpzksfcKM+M18cyRH+nP sAd98xIbVjm3Jm4k4d5oQyE2HwOur+trk2EcxTgdp17QapuWPwMfhaNq3runaX7x34zhABEB AAHNHkVyaWMgQmxha2UgPGVibGFrZUByZWRoYXQuY29tPsLAegQTAQgAJAIbAwULCQgHAwUV CgkICwUWAgMBAAIeAQIXgAUCS8fL9QIZAQAKCRCnoWtKJSdDahBHCACbl/5FGkUqJ89GAjeX RjpAeJtdKhujir0iS4CMSIng7fCiGZ0fNJCpL5RpViSo03Q7l37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ko/20100101 Thunderbird/60.7.0 In-Reply-To: <201907221756.x6MHuxaR019063@jinx.noi.kre.to> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Mon, 22 Jul 2019 19:49:54 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 X-BeenThere: bug-bash@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Bug reports for the GNU Bourne Again SHell List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Mailman-Original-Message-ID: <274806f3-f166-0fa8-0aff-9730a7f9b680@redhat.com> X-Mailman-Original-References: <201907221756.x6MHuxaR019063@jinx.noi.kre.to> Xref: csiph.com gnu.bash.bug:15201 This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --Uzj7VqM0iMxo1SQjzioOIbAgirMXJKzvb Content-Type: multipart/mixed; boundary="5QnLdrMnE2JNOFoQ2opHP6HPKzjc53bBK"; protected-headers="v1" From: Eric Blake To: kre@munnari.OZ.AU, bug-bash@gnu.org Message-ID: <274806f3-f166-0fa8-0aff-9730a7f9b680@redhat.com> Subject: Re: Incorrect option processing in builtin printf(1) References: <201907221756.x6MHuxaR019063@jinx.noi.kre.to> In-Reply-To: <201907221756.x6MHuxaR019063@jinx.noi.kre.to> --5QnLdrMnE2JNOFoQ2opHP6HPKzjc53bBK Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: quoted-printable On 7/22/19 12:56 PM, kre@munnari.OZ.AU wrote: > Configuration Information [Automatically generated, do not change]: > Machine: x86_64 > OS: netbsd > Compiler: gcc > Compilation CFLAGS: -O2 -D_FORTIFY_SOURCE=3D2 -I/usr/include -Wno-paren= theses -Wno-format-security > uname output: NetBSD jinx.noi.kre.to 8.99.30 NetBSD 8.99.30 (1.1-201901= 14) #9: Mon Jan 14 13:29:08 ICT 2019 kre@onyx.coe.psu.ac.th:/usr/obj/tes= ting/kernels/amd64/JINX amd64 > Machine Type: x86_64--netbsd >=20 > Bash Version: 5.0 > Patch Level: 7 > Release Status: release >=20 > Description: > POSIX specifies that printf(1) has no options, and by not Correct that there are no POSIX-mandated options,... > specifying that it is intended to comply with XBD 12.2 effectivly > says that it is not. That is, in printf, the first arg is > always the format string, whatever it contains. =2E..but wrong that it is not allowed to have options as extensions. XBD= 12.2 states "Some of the standard utilities do not conform to all of these guidelines; in those cases, the OPTIONS sections describe the deviations." and "The utilities in the Shell and Utilities volume of POSIX.1-2017 that claim conformance to these guidelines shall conform completely to these guidelines as if these guidelines contained the term "shall" instead of "should"." Then further in XSH, POSIX states in XSH 1.4 (https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap01.htm= l) that "Default Behavior: When this section is listed as "None.", it means that the implementation need not support any options. Standard utilities that do not accept options, but that do accept operands, shall recognize "--" as a first argument to be discarded." and again for 'printf' (https://pubs.opengroup.org/onlinepubs/9699919799/utilities/printf.html) "OPTIONS None." You are correct that for some utilities, POSIX does not require compliance with the Utility Syntax Guidelines (XSH 2.14 states that the special shell builtins do not comply by default without explicit mention, which is the opposite of other utilities that DO comply by default without explicit mention). But since printf is not one of the special builtins, and does not document an exemption, it must comply with the relevant Utility Syntax Guidelines. >=20 > So > printf --- should print three - chars to stdout Not so. The utility syntax guidelines state that you have invoked unspecified behavior, because you started an argument with '-' but which is not intended to be parsed as an option. The implementation may treat it as a literal string, but may equally treat it as an attempt to parse it as the first '-' requesting an option, the second '-' being the option character being requested, but treating it as an error since no option named '-' exists. If you want to output a literal string containing three dashes, you MUST write 'printf -- ---'. > printf -%d 3 should print -3 to stdout Not so. POSIX doesn't require extension options, but also does not forbid them. Bash happens to have extension options, so your command line is not portable, and it is not a bug in bash. > Please, let's try to avoid losing control of printf like what > happened to echo, stick to the requirements of POSIX where they > apply and actually speficy the output required. POSIX already specifies the bash behavior as permitted. There is nothing to change here but your broken command lines. --=20 Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org --5QnLdrMnE2JNOFoQ2opHP6HPKzjc53bBK-- --Uzj7VqM0iMxo1SQjzioOIbAgirMXJKzvb Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- iQEzBAEBCAAdFiEEccLMIrHEYCkn0vOqp6FrSiUnQ2oFAl02E2EACgkQp6FrSiUn Q2pQNAf/TJv1+q4S89gfXJiTh7xTj/ZGN9iV+bVogCCaX60/iHGVUXuTQrPFkjnS M/YmjaCLhkCbJC+fJ2i8TjaOempi4AdulQMipM6sMX60KTT/J8386qFg0l6xRXc5 f0VxULRZBWf2q3q7ps47D0hrnYMjRmP6igCa3GkvFuh7DPQ4Fi9WE1RuLJKEaCKv pu0r9IF4iRhsCaZVtWG1FsrCLcZpd4s0AkLvCYC3TyKUHI4MfBpGsppbyxA2XAec hfTlz8tqAg8arBDzdu3Z+x+rQcxPjkSvtoj6Y72dnWx2OrUuzNA30Pvb2jDRCrL1 94PhqJPxPiiIz6HhVtiiAs90P1lL5Q== =4V4I -----END PGP SIGNATURE----- --Uzj7VqM0iMxo1SQjzioOIbAgirMXJKzvb--