bug-bash
[Top][All Lists]
Advanced

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

Re: [PATCH] printf: more error handling


From: Chet Ramey
Subject: Re: [PATCH] printf: more error handling
Date: Sat, 3 Feb 2024 13:05:23 -0500
User-agent: Mozilla Thunderbird

On 2/2/24 6:33 PM, Grisha Levit wrote:
On Thu, Feb 1, 2024 at 7:41 PM Chet Ramey <chet.ramey@case.edu> wrote:

On 1/22/24 9:44 PM, Grisha Levit wrote:
The size of the buffer used for printf -v is tracked in an int but this
can overflow since the buffer can be built up by multiple vsnprintf(3)
calls, each of which can append up to INT_MAX bytes to the buffer:

Thanks for the report and patch.

Thanks, a small question -- in your commit[1] you added an ferror check here:

No, I just left it in.


    177       nw = vflag ? vbprintf (f, func) : printf (f, func); \
    178     if (nw < 0 || ferror (stdout)) \
    179       { \

Is it necessary to check the error indicator if printf(3) just had a non-
negative return?

I think printf is allowed to set the error flag that ferror checks even if
it returns 0, but I could be convinced otherwise.


And, if so, can this check be, as elsewhere:
`(vflag == 0 && ferror (stdout))'?  I think `printf -v' should work no
matter what the state of stdout is, no?

Sure.

--
``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/

Attachment: OpenPGP_signature.asc
Description: OpenPGP digital signature


reply via email to

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