public inbox for linux-man@vger.kernel.org
 help / color / mirror / Atom feed
From: Alejandro Colomar <alx.manpages@gmail.com>
To: Eric Biggers <ebiggers@kernel.org>
Cc: Ian Abbott <abbotti@mev.co.uk>, Zack Weinberg <zack@owlfolio.org>,
	linux-man@vger.kernel.org,
	Michael Kerrisk <mtk.manpages@gmail.com>,
	Alejandro Colomar <alx@kernel.org>
Subject: Re: [PATCH] scanf.3: Do not mention the ERANGE error
Date: Fri, 20 Jan 2023 14:12:07 +0100	[thread overview]
Message-ID: <b929eaed-0e8f-bb6c-87cb-8a36573c2769@gmail.com> (raw)
In-Reply-To: <Y8oT53gEtkAOX0Zb@sol.localdomain>


[-- Attachment #1.1: Type: text/plain, Size: 3285 bytes --]



On 1/20/23 05:09, Eric Biggers wrote:
> Hi Alejandro,
> 

[...]

>>
>> <https://git.kernel.org/pub/scm/docs/man-pages/man-pages.git/commit/?id=a15d34326c581eab107bf05782cc60d8ebdcad69>
>>
>> Cheers,
>>
> 
> This is commonly used functionality with no replacement suggested.

Maybe we should suggest using strtol(3) in BUGS.

>  Should it
> really be deprecated?

While the interface of sscanf(3) numeric conversions is not mis-designed and 
could be fixed, it is not correctly implemented, nor even standardized.

I think it's correct to deprecate unless there's a clear effort to fix it.

This is similar but different to bzero(3).  bzero(3) was broken or slow in some 
implementations.  That's probably why it was never added to ISO C, and why POSIX 
later removed it.  The API wasn't bad, and in fact it's great, I prefer it over 
memset(3).  The difference between bzero(3) and sscanf(3) is that bzero(3) has 
now been fixed, and is _the best_ API, while sscanf(3) is still broken.

>  Is the undefined behavior here a real world issue
> anywhere, or is this just a theoretical issue based on interpretation of the C
> standard?

All implementations of sscanf(3) produce Undefined Behavior (UB), AFAIK.  How 
much you consider UB to be a real-world issue differs for each programmer, but I 
tend to consider all UB to be as bad as nasal demons.  I'm not saying UB 
shouldn't exist, just that you shouldn't invoke it.  And a function that is used 
for scanning user input is one of those places where you really want to avoid 
invoking UB.

>  Perhaps instead of a deprecation, this just deserves a mention in the
> BUGS section of the man page, and a request to the C standard committee to fix
> the text in the standard to make the behavior defined?

I could change the "deprecated" statements by "see bugs", but I don't think it's 
a reasonable difference.  However, yes, I should still add something to BUGS.

While I'm doing some effort to fix implementations and standards in other APIs 
that matter to me, such as sockaddr_storage, or bzero(3), I don't use sscanf(3), 
so I'm sorry that I won't do the same for it.

However, if somebody really wants to use that function, and would like to fix 
it, I encourage that effort.  If the function is fixed, which shouldn't be that 
hard, I'm fine removing the messages against its usage in the manual.

While that doesn't happen, I prefer strongly recommending against their usage in 
the manual.  And dict(1) seems to say that the verb for that is "to deprecate" :)

> 
> I'll note that memcpy() is not deprecated, even though the C standard has a bug
> where 'memcpy(dst, src, 0)' is undefined if either pointer is NULL.  That's a
> very similar sort of issue.  The fix, of course, is for implementations to
> ignore the defective standard and make the behavior defined...

Right.  memcpy(3) has a bug in the standard.  However, implementations do the 
Right Thing (tm).  If implementations did the right thing for sscanf(3), that 
would be enough to remove the recommendation against it.  But my understanding 
is that the sscanf(3) implementation is not free of that problem.

> 
> - Eric

Cheers,

Alex

-- 
<http://www.alejandro-colomar.es/>

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

  reply	other threads:[~2023-01-20 13:12 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-08 12:34 [PATCH] scanf.3: Do not mention the ERANGE error Ian Abbott
2022-12-09 18:59 ` Alejandro Colomar
2022-12-09 19:28   ` Ian Abbott
2022-12-09 19:33     ` Alejandro Colomar
2022-12-09 21:41       ` Zack Weinberg
2022-12-11 15:58         ` Alejandro Colomar
2022-12-11 16:03           ` Alejandro Colomar
2022-12-12  2:11           ` Zack Weinberg
2022-12-12 10:21             ` Alejandro Colomar
2022-12-14  2:13               ` Zack Weinberg
2022-12-14 10:47                 ` Alejandro Colomar
2022-12-14 11:03                   ` Ian Abbott
2022-12-29  6:42                     ` Zack Weinberg
2022-12-29  6:39                   ` Zack Weinberg
2022-12-29 10:47                     ` Alejandro Colomar
2022-12-29 16:35                       ` Zack Weinberg
2022-12-29 16:39                         ` Alejandro Colomar
2022-12-12 15:22             ` Ian Abbott
2022-12-14  2:18               ` Zack Weinberg
2022-12-14 10:22                 ` Ian Abbott
2022-12-14 10:39                   ` Alejandro Colomar
2022-12-14 10:52                     ` Ian Abbott
2022-12-14 11:23                       ` Alejandro Colomar
2022-12-14 14:10                         ` Ian Abbott
2022-12-14 16:38                         ` Joseph Myers
2022-12-12 10:07       ` Ian Abbott
2022-12-12 11:33 ` Alejandro Colomar
2023-01-20  4:09   ` Eric Biggers
2023-01-20 13:12     ` Alejandro Colomar [this message]
2023-01-20 17:55       ` G. Branden Robinson
2023-01-20 22:02         ` Alejandro Colomar
2023-01-20 19:41       ` Eric Biggers

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=b929eaed-0e8f-bb6c-87cb-8a36573c2769@gmail.com \
    --to=alx.manpages@gmail.com \
    --cc=abbotti@mev.co.uk \
    --cc=alx@kernel.org \
    --cc=ebiggers@kernel.org \
    --cc=linux-man@vger.kernel.org \
    --cc=mtk.manpages@gmail.com \
    --cc=zack@owlfolio.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox