From: Alejandro Colomar <alx@kernel.org>
To: "G. Branden Robinson" <g.branden.robinson@gmail.com>
Cc: Lennart Jablonka <humm@ljabl.com>,
linux-man@vger.kernel.org,
Matthew House <mattlloydhouse@gmail.com>
Subject: Re: [PATCH] string_copying.7: don't grant strl{cpy,cat} magic
Date: Sun, 30 Jul 2023 16:05:34 +0200 [thread overview]
Message-ID: <2d4237a3-7e17-bfb8-8098-535d63b56a86@kernel.org> (raw)
In-Reply-To: <20230729193912.mzn5h2hjnyxnxkeq@illithid>
[-- Attachment #1.1: Type: text/plain, Size: 2364 bytes --]
Hi Branden,
On 2023-07-29 21:39, G. Branden Robinson wrote:
> Hi Matthew,
>
> At 2023-07-29T10:38:46-0400, Matthew House wrote:
>> On Sat, Jul 29, 2023 at 8:29 AM Alejandro Colomar <alx@kernel.org> wrote:
>>> I lied. I should have said that it writes what is safe to write,
>>> and then uses a somewhat "safer" version of undefined behavior
>>> (compared to other string copying functions). The standard
>>> differentiates "bounded UB", which doesn't perform out-of-bounds
>>> stores, from "critical UB", which performs them. In usual jargon,
>>> UB is UB, and there's no mild form of UB; however, the standard
>>> prescribes a bounded form of UB. However, I'm not sure compilers
>>> --and specifically GCC-- follow such a prescription of bounded UB,
>>> so it's better to consider all UB to be critical UB, just to fall on
>>> the safe side.
>>
>> Do you have a source for this? As far as I am aware, the standards
>> have always followed the "UB is UB" philosophy, which is why
>> standards-oriented people keep trying to reiterate it. I've never
>> heard of anything like "bounded UB" vs. "critical UB".
>
> The Ada language standard distinguishes "bounded errors" from "erroneous
> execution".
>
> http://www.ada-auth.org/standards/12rm/html/RM-1-1-5.html
>
> I've been after Alex for a while to read more about Ada. Maybe he has,
> and its (usually excellent) approach to attacking problems is seeping
> into his consciousness. ;-)
It is an excellent approach.
In this case, while I read some of that, I didn't read the errors part.
I found those definition of UB by chance, while trying to explain to a
coworker of mine that some code similar to the following one is not
safe at all:
```c
end = p + size;
p += snprintf(p, size, "a very long string that is truncated");
if (p > end)
p = end;
```
I didn't succeed. He still believes that to be fine. :/
Cheers,
Alex
>
> Nevertheless I would agree that if WG14 refuses to apply such categories
> to the C language definition, it's not going to help most users to do so
> in man pages. I suppose the best route for such a distinction to get
> into the language is via the GCC and Clang compilers.
>
> Regards,
> Branden
--
<http://www.alejandro-colomar.es/>
GPG key fingerprint: A9348594CE31283A826FBDD8D57633D441E25BB5
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
prev parent reply other threads:[~2023-07-30 14:05 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-28 19:22 [PATCH] string_copying.7: don't grant strl{cpy,cat} magic Lennart Jablonka
2023-07-28 22:05 ` Alejandro Colomar
2023-07-28 23:51 ` Lennart Jablonka
2023-07-29 12:04 ` Alejandro Colomar
2023-07-29 14:38 ` Matthew House
2023-07-29 14:47 ` Lennart Jablonka
2023-07-29 21:06 ` Matthew House
2023-07-29 19:39 ` G. Branden Robinson
2023-07-30 14:05 ` Alejandro Colomar [this message]
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=2d4237a3-7e17-bfb8-8098-535d63b56a86@kernel.org \
--to=alx@kernel.org \
--cc=g.branden.robinson@gmail.com \
--cc=humm@ljabl.com \
--cc=linux-man@vger.kernel.org \
--cc=mattlloydhouse@gmail.com \
/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