bug-bash
[Top][All Lists]
Advanced

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

Re: %q with truncating size loses safeness of %q


From: Chet Ramey
Subject: Re: %q with truncating size loses safeness of %q
Date: Fri, 17 Apr 2020 16:12:20 -0400
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:68.0) Gecko/20100101 Thunderbird/68.7.0

On 4/17/20 10:22 AM, Sam Liddicott wrote:

> Bash Version: 4.4
> Patch Level: 20
> Release Status: release
> 
> Also occurs on 5.0.7(1)-release
> 
> Description:
> printf %q with a truncating size will emit partially escaped
> sequence thus losing the safety and composability that %q
> is intended to provide.
> 
> Repeat-By:
> $ printf 'echo %.2q%q\n' "a'b" ';ls'
> echo a\\;ls
> The semi-colon is no longer escaped, the expectation of
> the %q formatter is lost

I would say this is a programmer error.  The way precisions work with
string arguments is that the argument is fetched or generated (this
includes generating the quoted string for %q or the expanded string for
%b) and then printf writes number of bytes (!) from that generated string
specified by the precision.

Chet

-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU    chet@case.edu    http://tiswww.cwru.edu/~chet/



reply via email to

[Prev in Thread] Current Thread [Next in Thread]