Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

Whom computers would destroy, they must first drive mad.


devel / comp.lang.c / Which tools are available for catching UB?

SubjectAuthor
* Which tools are available for catching UB?Anthony Cuozzo
+* Re: Which tools are available for catching UB?David Brown
|`* Re: Which tools are available for catching UB?Anthony Cuozzo
| +* Re: Which tools are available for catching UB?Keith Thompson
| |`- Re: Which tools are available for catching UB?Tim Rentsch
| `- Re: Which tools are available for catching UB?David Brown
+- Re: Which tools are available for catching UB?Richard Kettlewell
+- Re: Which tools are available for catching UB?Malcolm McLean
+* Re: Which tools are available for catching UB?Lew Pitcher
|+* Re: Which tools are available for catching UB?James Kuyper
||`- Re: Which tools are available for catching UB?Lew Pitcher
|`* Re: Which tools are available for catching UB?Tim Rentsch
| `* Re: Which tools are available for catching UB?Kaz Kylheku
|  `- Re: Which tools are available for catching UB?Tim Rentsch
`* Re: Which tools are available for catching UB?Kaz Kylheku
 +- Re: Which tools are available for catching UB?Chris M. Thomasson
 `- Re: Which tools are available for catching UB?Kenny McCormack

1
Which tools are available for catching UB?

<YXJnN.184010$xHn7.45772@fx14.iad>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=30786&group=comp.lang.c#30786

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!news.bbs.nz!tncsrv06.tnetconsulting.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx14.iad.POSTED!not-for-mail
MIME-Version: 1.0
User-Agent: Mozilla Thunderbird
Newsgroups: comp.lang.c
Content-Language: en-US
From: anth...@cuozzo.us (Anthony Cuozzo)
Subject: Which tools are available for catching UB?
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Lines: 8
Message-ID: <YXJnN.184010$xHn7.45772@fx14.iad>
X-Complaints-To: abuse@usenetserver.com
NNTP-Posting-Date: Thu, 11 Jan 2024 04:15:52 UTC
Organization: UsenetServer - www.usenetserver.com
Date: Wed, 10 Jan 2024 23:15:52 -0500
X-Received-Bytes: 819
 by: Anthony Cuozzo - Thu, 11 Jan 2024 04:15 UTC

The only tool I use regularly for identifying instances of undefined
behavior is the semantics compiler "kcc" from RV-Match.

Are there any other tools out there besides what ships with e.g., GCC &
Clang?

Thanks,
--Anthony Cuozzo

Re: Which tools are available for catching UB?

<unonqf$307b8$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=30793&group=comp.lang.c#30793

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!usenet.network!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: david.br...@hesbynett.no (David Brown)
Newsgroups: comp.lang.c
Subject: Re: Which tools are available for catching UB?
Date: Thu, 11 Jan 2024 13:43:59 +0100
Organization: A noiseless patient Spider
Lines: 27
Message-ID: <unonqf$307b8$1@dont-email.me>
References: <YXJnN.184010$xHn7.45772@fx14.iad>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 11 Jan 2024 12:43:59 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="d91ac923daa8a1bca9098efd7779b99b";
logging-data="3153256"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX191VbqkNdzBLIJ02IvKv3Md/vqQ5AcP5wc="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.11.0
Cancel-Lock: sha1:NCw99RIwNKOYnY1Tn+BoW1P+PRc=
In-Reply-To: <YXJnN.184010$xHn7.45772@fx14.iad>
Content-Language: en-GB
 by: David Brown - Thu, 11 Jan 2024 12:43 UTC

On 11/01/2024 05:15, Anthony Cuozzo wrote:
> The only tool I use regularly for identifying instances of undefined
> behavior is the semantics compiler "kcc" from RV-Match.
>
> Are there any other tools out there besides what ships with e.g., GCC &
> Clang?
>

Both gcc and clang have "sanitizers". You compile the code with the
appropriate options, and the code is augmented with checks for different
kinds of UB, detected at run-time. gcc and clang have many of these in
common, and some that are only implemented in one of them. Some
sanitizers can have significant impact on code speed, others do not.
You will want to try things with different flags to see what works best
for you.

<https://gcc.gnu.org/onlinedocs/gcc/Instrumentation-Options.html#index-fsanitize_003dundefined>

<https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html>

Both gcc and clang can also do a great deal of static error checking
which can find some kinds of UB before running the code. And there are
other tools such as clang-tidy, and third-party linters and checkers,
that can help. (Some are quite expensive.)

Re: Which tools are available for catching UB?

<hE_nN.29642$Sf59.27167@fx48.iad>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=30809&group=comp.lang.c#30809

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!news.samoylyk.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx48.iad.POSTED!not-for-mail
MIME-Version: 1.0
User-Agent: Mozilla Thunderbird
Subject: Re: Which tools are available for catching UB?
Content-Language: en-US
Newsgroups: comp.lang.c
References: <YXJnN.184010$xHn7.45772@fx14.iad> <unonqf$307b8$1@dont-email.me>
From: anth...@cuozzo.us (Anthony Cuozzo)
In-Reply-To: <unonqf$307b8$1@dont-email.me>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Lines: 38
Message-ID: <hE_nN.29642$Sf59.27167@fx48.iad>
X-Complaints-To: abuse@usenetserver.com
NNTP-Posting-Date: Thu, 11 Jan 2024 23:15:25 UTC
Organization: UsenetServer - www.usenetserver.com
Date: Thu, 11 Jan 2024 18:15:22 -0500
X-Received-Bytes: 2292
 by: Anthony Cuozzo - Thu, 11 Jan 2024 23:15 UTC

On 1/11/24 07:43, David Brown wrote:
> On 11/01/2024 05:15, Anthony Cuozzo wrote:
>> The only tool I use regularly for identifying instances of undefined
>> behavior is the semantics compiler "kcc" from RV-Match.
>>
>> Are there any other tools out there besides what ships with e.g., GCC
>> & Clang?
>>
>
> Both gcc and clang have "sanitizers".  You compile the code with the
> appropriate options, and the code is augmented with checks for different
> kinds of UB, detected at run-time.  gcc and clang have many of these in
> common, and some that are only implemented in one of them.  Some
> sanitizers can have significant impact on code speed, others do not. You
> will want to try things with different flags to see what works best for
> you.
>
> <https://gcc.gnu.org/onlinedocs/gcc/Instrumentation-Options.html#index-fsanitize_003dundefined>
>
> <https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html>
>
>
> Both gcc and clang can also do a great deal of static error checking
> which can find some kinds of UB before running the code.  And there are
> other tools such as clang-tidy, and third-party linters and checkers,
> that can help.  (Some are quite expensive.)
>
>

I suppose I was/am looking for static analysis tools which focus on UB,
but now that I've given it more thought I realize that only a subset of
UB can be detected at compile time.

Semi-related: Do you know if there's a resource which breaks down UB per
standard? I'd like to see how things have changed over time.

Thanks,
--Anthony

Re: Which tools are available for catching UB?

<87sf33mmy3.fsf@nosuchdomain.example.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=30813&group=comp.lang.c#30813

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Keith.S....@gmail.com (Keith Thompson)
Newsgroups: comp.lang.c
Subject: Re: Which tools are available for catching UB?
Date: Thu, 11 Jan 2024 16:09:56 -0800
Organization: None to speak of
Lines: 30
Message-ID: <87sf33mmy3.fsf@nosuchdomain.example.com>
References: <YXJnN.184010$xHn7.45772@fx14.iad> <unonqf$307b8$1@dont-email.me>
<hE_nN.29642$Sf59.27167@fx48.iad>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: dont-email.me; posting-host="3cbd2312b6d5297cbffbebfe1ede6aac";
logging-data="3345601"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18EfPxEg72TtSf7AJ1jqh1N"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
Cancel-Lock: sha1:yyJW6kIGoqVE7F+jamOuI/jHMnQ=
sha1:b2MNnmq0xHQEW6Iefiv1BgIKehc=
 by: Keith Thompson - Fri, 12 Jan 2024 00:09 UTC

Anthony Cuozzo <anthony@cuozzo.us> writes:
[...]
> I suppose I was/am looking for static analysis tools which focus on
> UB, but now that I've given it more thought I realize that only a
> subset of UB can be detected at compile time.

Which, in many or most cases, is exactly why it's UB.

Ideally, something's behavior is left undefined because it's impractical
to detect the problem. In some cases, behavior has been left undefined
(or unspecified, or implementation-defined) because existing
implementations behave differently.

> Semi-related: Do you know if there's a resource which breaks down UB
> per standard? I'd like to see how things have changed over time.

Each edition of the standard has an annex (Annex J in the case of C11)
that summarizes unspecified, undefined, and implementation-defined
behaviors. The standards themselves cost money, but drafts are freely
available.

Some instances of undefined behavior are specified explicitly. Others
are undefined just because the standard provides no definition. Both
kinds are equivalent, and can in principle result in the same kinds of
Bad Things Happening.

--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Working, but not speaking, for Medtronic
void Void(void) { Void(); } /* The recursive call of the void */

Re: Which tools are available for catching UB?

<wwvil3zvss3.fsf@LkoBDZeT.terraraq.uk>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=30818&group=comp.lang.c#30818

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!news.niel.me!nntp.terraraq.uk!.POSTED.tunnel.sfere.anjou.terraraq.org.uk!not-for-mail
From: inva...@invalid.invalid (Richard Kettlewell)
Newsgroups: comp.lang.c
Subject: Re: Which tools are available for catching UB?
Date: Fri, 12 Jan 2024 08:51:24 +0000
Organization: terraraq NNTP server
Message-ID: <wwvil3zvss3.fsf@LkoBDZeT.terraraq.uk>
References: <YXJnN.184010$xHn7.45772@fx14.iad>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
Injection-Info: innmantic.terraraq.uk; posting-host="tunnel.sfere.anjou.terraraq.org.uk:172.17.207.6";
logging-data="90354"; mail-complaints-to="usenet@innmantic.terraraq.uk"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux)
Cancel-Lock: sha1:XmAIDCVsc9ihrIgJNu6AhOTbW4E=
X-Face: h[Hh-7npe<<b4/eW[]sat,I3O`t8A`(ej.H!F4\8|;ih)`7{@:A~/j1}gTt4e7-n*F?.Rl^
F<\{jehn7.KrO{!7=:(@J~]<.[{>v9!1<qZY,{EJxg6?Er4Y7Ng2\Ft>Z&W?r\c.!4DXH5PWpga"ha
+r0NzP?vnz:e/knOY)PI-
X-Boydie: NO
 by: Richard Kettlewell - Fri, 12 Jan 2024 08:51 UTC

Anthony Cuozzo <anthony@cuozzo.us> writes:
> The only tool I use regularly for identifying instances of undefined
> behavior is the semantics compiler "kcc" from RV-Match.
>
> Are there any other tools out there besides what ships with e.g., GCC
> & Clang?

Dynamic analysis:

* https://gcc.gnu.org/onlinedocs/gcc/Instrumentation-Options.html,
search for ‘sanitize’. Instruments executable to detect various issues
at runtime.

* https://www.gnu.org/software/libc/manual/html_node/Source-Fortification.html
Additional bounds checking.

* https://clang.llvm.org/docs/index.html, search for ‘sanitize’. Ditto.

* https://valgrind.org/. Detects various issues in unmodified
executables.

Static analysis:

* https://clang-analyzer.llvm.org/. Quite limited and struggles with
false positives IME.

* https://www.synopsys.com/software-integrity/static-analysis-tools-sast/coverity.html
Extensive checking and does find many real issues but also produces a
lot of false positives. Pricey.

* https://scan.coverity.com/. Free version of the above for open source
projects.

--
https://www.greenend.org.uk/rjk/

Re: Which tools are available for catching UB?

<unrg3t$3fo6l$2@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=30821&group=comp.lang.c#30821

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!paganini.bofh.team!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: david.br...@hesbynett.no (David Brown)
Newsgroups: comp.lang.c
Subject: Re: Which tools are available for catching UB?
Date: Fri, 12 Jan 2024 14:50:53 +0100
Organization: A noiseless patient Spider
Lines: 63
Message-ID: <unrg3t$3fo6l$2@dont-email.me>
References: <YXJnN.184010$xHn7.45772@fx14.iad> <unonqf$307b8$1@dont-email.me>
<hE_nN.29642$Sf59.27167@fx48.iad>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Fri, 12 Jan 2024 13:50:53 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="8cdd22475589055e3052b9eb67ea743e";
logging-data="3662037"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19jZf+pp0GXRqXCdCJfdjU9teKO9dwcRSk="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.11.0
Cancel-Lock: sha1:0N1LWXITf499dLaNU60P386RRd4=
Content-Language: en-GB
In-Reply-To: <hE_nN.29642$Sf59.27167@fx48.iad>
 by: David Brown - Fri, 12 Jan 2024 13:50 UTC

On 12/01/2024 00:15, Anthony Cuozzo wrote:
> On 1/11/24 07:43, David Brown wrote:
>> On 11/01/2024 05:15, Anthony Cuozzo wrote:
>>> The only tool I use regularly for identifying instances of undefined
>>> behavior is the semantics compiler "kcc" from RV-Match.
>>>
>>> Are there any other tools out there besides what ships with e.g., GCC
>>> & Clang?
>>>
>>
>> Both gcc and clang have "sanitizers".  You compile the code with the
>> appropriate options, and the code is augmented with checks for
>> different kinds of UB, detected at run-time.  gcc and clang have many
>> of these in common, and some that are only implemented in one of
>> them.  Some sanitizers can have significant impact on code speed,
>> others do not. You will want to try things with different flags to see
>> what works best for you.
>>
>> <https://gcc.gnu.org/onlinedocs/gcc/Instrumentation-Options.html#index-fsanitize_003dundefined>
>>
>> <https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html>
>>
>>
>> Both gcc and clang can also do a great deal of static error checking
>> which can find some kinds of UB before running the code.  And there
>> are other tools such as clang-tidy, and third-party linters and
>> checkers, that can help.  (Some are quite expensive.)
>>
>>
>
> I suppose I was/am looking for static analysis tools which focus on UB,
> but now that I've given it more thought I realize that only a subset of
> UB can be detected at compile time.

That is absolutely correct. In fact, most UB can only be detected at
run time. Static analysis (in a compiler, or dedicated tools) can
usually only see some kinds of /potential/ UB. For example, if you
write "int foo(void) { return 1 / 0; }", that is not UB in itself - it
is only UB if your program calls "foo". And usually the compiler isn't
able to determine what code will actually be called when you run the
program, unless it can trace the execution unconditionally from main().

But it is, IMHO, a good idea to find as many of your codes bugs as
possible using static checking - it's the easiest and cheapest time to
do it. gcc and clang both have quite sophisticated warnings and static
analysis features (with steadily more for each new compiler release),
and clang also has some stand-alone tools for the job. There are also
dedicated tools for particular use-cases (such as tools for checking
Linux kernel code for certain kinds of problems). And there are quite a
number of commercial tools that do very sophisticated static error
checking, if your budget stretches to buying them.

>
> Semi-related: Do you know if there's a resource which breaks down UB per
> standard? I'd like to see how things have changed over time.
>

Each C standard version has an Annex that lists the explicit UB
described in the standard - but remember that things that have no
standards-defined behaviour are also UB in C (though a compiler may
choose to define them).

Re: Which tools are available for catching UB?

<86le8rlsih.fsf@linuxsc.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=30902&group=comp.lang.c#30902

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: tr.17...@z991.linuxsc.com (Tim Rentsch)
Newsgroups: comp.lang.c
Subject: Re: Which tools are available for catching UB?
Date: Sun, 14 Jan 2024 09:44:06 -0800
Organization: A noiseless patient Spider
Lines: 35
Message-ID: <86le8rlsih.fsf@linuxsc.com>
References: <YXJnN.184010$xHn7.45772@fx14.iad> <unonqf$307b8$1@dont-email.me> <hE_nN.29642$Sf59.27167@fx48.iad> <87sf33mmy3.fsf@nosuchdomain.example.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: dont-email.me; posting-host="8638bc13aeaeb22b15b54cee031022ba";
logging-data="575712"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19uTAcgUn/BHy/Nv5GHlIXvk6Fcesyx/hU="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:VA9qVfhi2X+LdzqGQTd1jE82S20=
sha1:nwAwOgAMYqOmE9ruVPIKaKj2DzM=
 by: Tim Rentsch - Sun, 14 Jan 2024 17:44 UTC

Keith Thompson <Keith.S.Thompson+u@gmail.com> writes:

> Anthony Cuozzo <anthony@cuozzo.us> writes:
> [...]
>
>> [looking for constructs that are undefined behavior]

>> Semi-related: Do you know if there's a resource which breaks down UB
>> per standard? I'd like to see how things have changed over time.
>
> Each edition of the standard has an annex (Annex J in the case of C11)
> that summarizes unspecified, undefined, and implementation-defined
> behaviors. The standards themselves cost money, but drafts are freely
> available.

Annex J (which is Annex G in C90) is an excellent resource. A caution
is in order: not every case of undefined behavior (and probably also
unspecified behavior and implementation-defined behavior) is listed in
Annex J. Most are, but not all are. Also, sometimes a statement of UB
in Annex J is not completely accurate, but only an approximation. It
is still the case that Annex J is an excellent resource, but don't take
it as gospel.

> Some instances of undefined behavior are specified explicitly. Others
> are undefined just because the standard provides no definition. Both
> kinds are equivalent, and can in principle result in the same kinds of
> Bad Things Happening.

I think a fine point should be noted here. Some kinds of undefined
behavior, in addition to being undefined behavior, also require a
diagnostic be issued. So different kinds of undefined behavior may
not be exactly equivalent - some require some sort of message out of
the compiler, whereas others may get no indication when compiling.
None of this is meant to contradict Keith's statement, just to augment
it with a clarification.

Re: Which tools are available for catching UB?

<uobpvc$2mi99$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=31177&group=comp.lang.c#31177

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!nntp.comgw.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: malcolm....@gmail.com (Malcolm McLean)
Newsgroups: comp.lang.c
Subject: Re: Which tools are available for catching UB?
Date: Thu, 18 Jan 2024 18:17:16 +0000
Organization: A noiseless patient Spider
Lines: 22
Message-ID: <uobpvc$2mi99$1@dont-email.me>
References: <YXJnN.184010$xHn7.45772@fx14.iad>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 18 Jan 2024 18:17:16 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="8a5a5d16ef1207c763fd0dce5b26b51c";
logging-data="2836777"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX182sW26e23i7rT0D1qO41SbcAbYw9EHAa4="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:slGpcRuSdia9FJ/CcMquZGu40Co=
Content-Language: en-GB
In-Reply-To: <YXJnN.184010$xHn7.45772@fx14.iad>
 by: Malcolm McLean - Thu, 18 Jan 2024 18:17 UTC

On 11/01/2024 04:15, Anthony Cuozzo wrote:
> The only tool I use regularly for identifying instances of undefined
> behavior is the semantics compiler "kcc" from RV-Match.
>
> Are there any other tools out there besides what ships with e.g., GCC &
> Clang?
>
> Thanks,
> --Anthony Cuozzo
>
Almost by definition you can't catch all undefined behaviour, since it
is "undefined".
Out of bounds array accesses can be caught by sanitizers or valgrind.
C is notorious for this bug, since dynamic arrays have no way of
obtaining the size by querying the pointer, so size and array have to be
passed in separate variables, and the potential for them getting out of
synch is high.

But undefined behaviour like a shift which is out of range is harder to
catch. Whilst it is undefined in C, it often compiles to valid and
perfectly well-behaved machine code.

Re: Which tools are available for catching UB?

<uobt0a$2jo2e$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=31180&group=comp.lang.c#31180

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: lew.pitc...@digitalfreehold.ca (Lew Pitcher)
Newsgroups: comp.lang.c
Subject: Re: Which tools are available for catching UB?
Date: Thu, 18 Jan 2024 19:08:59 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 32
Message-ID: <uobt0a$2jo2e$1@dont-email.me>
References: <YXJnN.184010$xHn7.45772@fx14.iad>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Thu, 18 Jan 2024 19:08:59 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="77040d3beec55f6c35559a33a47f5acd";
logging-data="2744398"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/0gLkcXz7OusO0sGbsPWmsTRLXRxukVKM="
User-Agent: Pan/0.139 (Sexual Chocolate; GIT bf56508
git://git.gnome.org/pan2)
Cancel-Lock: sha1:cEyBfPqlbpqisO2kveV+t8YrA1s=
 by: Lew Pitcher - Thu, 18 Jan 2024 19:08 UTC

On Wed, 10 Jan 2024 23:15:52 -0500, Anthony Cuozzo wrote:

> The only tool I use regularly for identifying instances of undefined
> behavior is the semantics compiler "kcc" from RV-Match.
>
> Are there any other tools out there besides what ships with e.g., GCC &
> Clang?

By definition (for instance, C11 Section 3.4.3: "undefined behavior") undefined
behaviour is "behavior, upon use of a nonportable or erroneous program construct
or of erroneous data,for which this International Standard imposes no requirements".

Outside of the "erroneous" constructs and data, this also means that "nonportable"
program constructs, for which the International Standard imposes no requirements,
invoke "undefined behaviour", as far as the ISO C standard is concerned.

This means that a single call to a function not defined by your program source
code or by the ISO C standard will invoke "undefined behaviour". So, a program
that calls CopyFile() (a Microsoft Windows API) or open() (a POSIX API) invokes
"undefined behaviour".

While it is certainly possible to write C programs that adhere entirely to the
ISO C standard, many C programs (dare I say, most C programs?) invoke /some/
amount of "undefined behaviour" wrt the C standard, even when the behaviour
/is/ defined by other standards and sources.

So, does "kcc" from RV-Match catch these forms of "undefined behaviour"?"

--
Lew Pitcher
"In Skills We Trust"

Re: Which tools are available for catching UB?

<20240118114117.651@kylheku.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=31184&group=comp.lang.c#31184

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!news.samoylyk.net!usenet.goja.nl.eu.org!weretis.net!feeder8.news.weretis.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: 433-929-...@kylheku.com (Kaz Kylheku)
Newsgroups: comp.lang.c
Subject: Re: Which tools are available for catching UB?
Date: Thu, 18 Jan 2024 19:41:57 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 12
Message-ID: <20240118114117.651@kylheku.com>
References: <YXJnN.184010$xHn7.45772@fx14.iad>
Injection-Date: Thu, 18 Jan 2024 19:41:57 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="d2d938dda3e1a6a4011b6cb72d132af7";
logging-data="2868449"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+IE9a+AjOA4SUJYAWKQMPNde9n3WQIxi8="
User-Agent: slrn/pre1.0.4-9 (Linux)
Cancel-Lock: sha1:AtPbLs9oJHQ6+jaMqqXK+0Dq4ZU=
 by: Kaz Kylheku - Thu, 18 Jan 2024 19:41 UTC

On 2024-01-11, Anthony Cuozzo <anthony@cuozzo.us> wrote:
> Are there any other tools out there besides what ships with e.g., GCC &
> Clang?

All the tools that waste their time hanging out on comp.lang.c are
pretty good for catching UB.

--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca
NOTE: If you use Google Groups, I don't see you, unless you're whitelisted.

Re: Which tools are available for catching UB?

<uobuuo$2ndid$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=31185&group=comp.lang.c#31185

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: jameskuy...@alumni.caltech.edu (James Kuyper)
Newsgroups: comp.lang.c
Subject: Re: Which tools are available for catching UB?
Date: Thu, 18 Jan 2024 14:42:16 -0500
Organization: A noiseless patient Spider
Lines: 44
Message-ID: <uobuuo$2ndid$1@dont-email.me>
References: <YXJnN.184010$xHn7.45772@fx14.iad> <uobt0a$2jo2e$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 18 Jan 2024 19:42:16 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="3ca1c110e6a83f43986feaf9008a2874";
logging-data="2864717"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX193fSMgtT8fiUCIWv6T/mX5UjPnTWjcZS0="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:dwxISkroOwecl/gPGFE3uDLe3TI=
Content-Language: en-US
In-Reply-To: <uobt0a$2jo2e$1@dont-email.me>
 by: James Kuyper - Thu, 18 Jan 2024 19:42 UTC

On 1/18/24 14:08, Lew Pitcher wrote:
....
> By definition (for instance, C11 Section 3.4.3: "undefined behavior")
> undefined
> behaviour is "behavior, upon use of a nonportable or erroneous program
> construct
> or of erroneous data,for which this International Standard imposes no
> requirements".
>
> Outside of the "erroneous" constructs and data, this also means that
> "nonportable"
> program constructs, for which the International Standard imposes no
> requirements,
> invoke "undefined behaviour", as far as the ISO C standard is concerned.
>
> This means that a single call to a function not defined by your
> program source
> code or by the ISO C standard will invoke "undefined behaviour". So, a
> program
> that calls CopyFile() (a Microsoft Windows API) or open() (a POSIX
> API) invokes
> "undefined behaviour".
>
> While it is certainly possible to write C programs that adhere
> entirely to the
> ISO C standard, many C programs (dare I say, most C programs?) invoke
> /some/
> amount of "undefined behaviour" wrt the C standard, even when the
> behaviour
> /is/ defined by other standards and sources.

Keep in mind that "undefined behavior" in C means ONLY that "this
international standard" imposes no requirements. If requirements are
imposed by some other document, such as the documentation for the
library that you're using, those requirements can be sufficient to make
your program useful. If that library's documentation describes the
behavior of the particular function you're calling, that's sufficient
for that function call. If it also claims compatibility with a given
version of the C standard, that implies that when compiling and linking
with that version of the C standard, all requirements that the C
standard would impose on all of your code except that function call also
apply - not because the C standard says so, but because the library's
documentation says so.

Re: Which tools are available for catching UB?

<uoc1er$2jo2e$2@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=31188&group=comp.lang.c#31188

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!usenet.goja.nl.eu.org!weretis.net!feeder8.news.weretis.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: lew.pitc...@digitalfreehold.ca (Lew Pitcher)
Newsgroups: comp.lang.c
Subject: Re: Which tools are available for catching UB?
Date: Thu, 18 Jan 2024 20:24:59 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 48
Message-ID: <uoc1er$2jo2e$2@dont-email.me>
References: <YXJnN.184010$xHn7.45772@fx14.iad>
<uobt0a$2jo2e$1@dont-email.me> <uobuuo$2ndid$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Thu, 18 Jan 2024 20:24:59 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="77040d3beec55f6c35559a33a47f5acd";
logging-data="2744398"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/cODT3j2lxnZocQGT3yFh+TyJIjpP71ck="
User-Agent: Pan/0.139 (Sexual Chocolate; GIT bf56508
git://git.gnome.org/pan2)
Cancel-Lock: sha1:N5IzQ2VskMyA+8IlDoXUBHyz/HM=
 by: Lew Pitcher - Thu, 18 Jan 2024 20:24 UTC

On Thu, 18 Jan 2024 14:42:16 -0500, James Kuyper wrote:

> On 1/18/24 14:08, Lew Pitcher wrote:
> ...
>> By definition (for instance, C11 Section 3.4.3: "undefined behavior")
>> undefined
>> behaviour is "behavior, upon use of a nonportable or erroneous program
>> construct
>> or of erroneous data,for which this International Standard imposes no
>> requirements".
>>
>> Outside of the "erroneous" constructs and data, this also means that
>> "nonportable"
>> program constructs, for which the International Standard imposes no
>> requirements,
>> invoke "undefined behaviour", as far as the ISO C standard is concerned.
>>
>> This means that a single call to a function not defined by your
>> program source
>> code or by the ISO C standard will invoke "undefined behaviour". So, a
>> program
>> that calls CopyFile() (a Microsoft Windows API) or open() (a POSIX
>> API) invokes
>> "undefined behaviour".
>>
>> While it is certainly possible to write C programs that adhere
>> entirely to the
>> ISO C standard, many C programs (dare I say, most C programs?) invoke
>> /some/
>> amount of "undefined behaviour" wrt the C standard, even when the
>> behaviour
>> /is/ defined by other standards and sources.
>
> Keep in mind that "undefined behavior" in C means ONLY that "this
> international standard" imposes no requirements.

My point, exactly.

My question to the OP was, in effect, is the tool that the OP uses
"strict" in it's detection of UB (i.e. calling a program that uses
POSIX apis as exhibiting "undefined behaviour") or does it allow a
looser interpretation?

[snip]

--
Lew Pitcher
"In Skills We Trust"

Re: Which tools are available for catching UB?

<uoc4ik$2ogov$4@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=31191&group=comp.lang.c#31191

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!feeder8.news.weretis.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: chris.m....@gmail.com (Chris M. Thomasson)
Newsgroups: comp.lang.c
Subject: Re: Which tools are available for catching UB?
Date: Thu, 18 Jan 2024 13:18:11 -0800
Organization: A noiseless patient Spider
Lines: 10
Message-ID: <uoc4ik$2ogov$4@dont-email.me>
References: <YXJnN.184010$xHn7.45772@fx14.iad>
<20240118114117.651@kylheku.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 18 Jan 2024 21:18:13 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="cc6405ddd276c3b4eb7c996db44b0166";
logging-data="2900767"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+fvOh/IhkaE6CuM5acVuUpoVl9lpo09eg="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:aFzaZrdswnSSw1mlad2EuGKBRyU=
Content-Language: en-US
In-Reply-To: <20240118114117.651@kylheku.com>
 by: Chris M. Thomasson - Thu, 18 Jan 2024 21:18 UTC

On 1/18/2024 11:41 AM, Kaz Kylheku wrote:
> On 2024-01-11, Anthony Cuozzo <anthony@cuozzo.us> wrote:
>> Are there any other tools out there besides what ships with e.g., GCC &
>> Clang?
>
> All the tools that waste their time hanging out on comp.lang.c are
> pretty good for catching UB.
>

A little harsh? :^)

Re: Which tools are available for catching UB?

<uocp31$786s$1@news.xmission.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=31213&group=comp.lang.c#31213

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!xmission!nnrp.xmission!.POSTED.shell.xmission.com!not-for-mail
From: gaze...@shell.xmission.com (Kenny McCormack)
Newsgroups: comp.lang.c
Subject: Re: Which tools are available for catching UB?
Date: Fri, 19 Jan 2024 03:08:17 -0000 (UTC)
Organization: The official candy of the new Millennium
Message-ID: <uocp31$786s$1@news.xmission.com>
References: <YXJnN.184010$xHn7.45772@fx14.iad> <20240118114117.651@kylheku.com>
Injection-Date: Fri, 19 Jan 2024 03:08:17 -0000 (UTC)
Injection-Info: news.xmission.com; posting-host="shell.xmission.com:166.70.8.4";
logging-data="237788"; mail-complaints-to="abuse@xmission.com"
X-Newsreader: trn 4.0-test77 (Sep 1, 2010)
Originator: gazelle@shell.xmission.com (Kenny McCormack)
 by: Kenny McCormack - Fri, 19 Jan 2024 03:08 UTC

In article <20240118114117.651@kylheku.com>,
Kaz Kylheku <433-929-6894@kylheku.com> wrote:
>On 2024-01-11, Anthony Cuozzo <anthony@cuozzo.us> wrote:
>> Are there any other tools out there besides what ships with e.g., GCC &
>> Clang?
>
>All the tools that waste their time hanging out on comp.lang.c are
>pretty good for catching UB.

Well done, sir!

(nice play on the word "tool")

--
Note that Oprah actually is all the things that The Donald only wishes he were.
For one thing, she actually *is* a billionaire. She's also actually self-made,
came from nothing, knows how to run businesses, never went bankrupt, is smart
and is mentally stable.

Re: Which tools are available for catching UB?

<8634ukeofy.fsf@linuxsc.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=31729&group=comp.lang.c#31729

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: tr.17...@z991.linuxsc.com (Tim Rentsch)
Newsgroups: comp.lang.c
Subject: Re: Which tools are available for catching UB?
Date: Thu, 25 Jan 2024 19:57:53 -0800
Organization: A noiseless patient Spider
Lines: 30
Message-ID: <8634ukeofy.fsf@linuxsc.com>
References: <YXJnN.184010$xHn7.45772@fx14.iad> <uobt0a$2jo2e$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: dont-email.me; posting-host="3fb740dc5d2d937efa44f2af60b1195d";
logging-data="2831552"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19NESR9pY7FPu9VpIp/s3M06H4IuVJMASc="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:0VSXyyWSnIQafvPlEMw5H2oBYNs=
sha1:NjZtqFXJb7saKJ3OsUcptTfGrjw=
 by: Tim Rentsch - Fri, 26 Jan 2024 03:57 UTC

Lew Pitcher <lew.pitcher@digitalfreehold.ca> writes:

> [A] single call to a function not defined by your program source
> code or by the ISO C standard will invoke "undefined behaviour".

That isn't right. The C standard allows previously translated
translation units "[to] be preserved individually or in libraries."
Those translation units don't have to be your own code or even
necessarily stored, or translated, on the same machine. In
translation phase 8, "[l]ibrary components are linked to satisfy
external references to functions and objects not defined in the
current translation." The C standard doesn't specify how the
libraries are located, or even require that you be able to inspect
them, but clearly does require that libraries be consulted to satisfy
external references. We don't know what code in the libraries will
do, but there is a requirement /on the implementation/ that they be
linked against in phase 8. The presence of that requirement means
that linking to, or calling, such an external reference is not ipso
facto undefined behavior. (Obviously it could be undefined behavior
for other reasons, but not just by virtue of there being a call.)

Not knowing what something will do is not the same as undefined
behavior. The question is Does the C standard give a requirement
about what implementations have to do? In this case it does. An
implementation is not free to do whatever it wants just because a
library was previously translated on a different machine. Code in
a library might (emphasis _might_) provoke undefined behavior if it
is called, but that depends on what the library code is, and is not
something an implementation can just arbitrarily chose to do on its
own. It's important to understand the difference.

Re: Which tools are available for catching UB?

<20240125203408.386@kylheku.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=31731&group=comp.lang.c#31731

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!news.chmurka.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: 433-929-...@kylheku.com (Kaz Kylheku)
Newsgroups: comp.lang.c
Subject: Re: Which tools are available for catching UB?
Date: Fri, 26 Jan 2024 04:52:39 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 30
Message-ID: <20240125203408.386@kylheku.com>
References: <YXJnN.184010$xHn7.45772@fx14.iad>
<uobt0a$2jo2e$1@dont-email.me> <8634ukeofy.fsf@linuxsc.com>
Injection-Date: Fri, 26 Jan 2024 04:52:39 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="96ca4eb75b4703d7855e1ee0c9e2d747";
logging-data="2845066"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19/WvjdBsDHb8GXFb3q2lhLMtCHlYGKuP0="
User-Agent: slrn/pre1.0.4-9 (Linux)
Cancel-Lock: sha1:pg9UlQ25PTWEGm+GNSPUEHUFKM0=
 by: Kaz Kylheku - Fri, 26 Jan 2024 04:52 UTC

On 2024-01-26, Tim Rentsch <tr.17687@z991.linuxsc.com> wrote:
> Lew Pitcher <lew.pitcher@digitalfreehold.ca> writes:
>
>> [A] single call to a function not defined by your program source
>> code or by the ISO C standard will invoke "undefined behaviour".
>
> That isn't right. The C standard allows previously translated
> translation units "[to] be preserved individually or in libraries."
> Those translation units don't have to be your own code or even
> necessarily stored, or translated, on the same machine.

This is a strawman interpretation of what Lew is almost certainly
saying, which is the salient point that using a function that is not
somewhere in your program (any translation unit from your sources or any
translated units you brought to the table yourself), and not in the
standard, is undefined behavior.

He can't be literally saying that calling a function foo is undefined
behavior, even if it's found in a libfoo.a that is brought from
another machine, and which has no compatibility issues (like wrong
architecture, unsupported object format, wrong ABI), and is being linked
to the program, and used correctly according to its documentation.

That would be silly, and uncharacteristic of Lew's level of experience,
so it can't be the right interpretation.

--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca

Re: Which tools are available for catching UB?

<86a5o863bj.fsf@linuxsc.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=33022&group=comp.lang.c#33022

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!usenet.goja.nl.eu.org!weretis.net!feeder8.news.weretis.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: tr.17...@z991.linuxsc.com (Tim Rentsch)
Newsgroups: comp.lang.c
Subject: Re: Which tools are available for catching UB?
Date: Sat, 10 Feb 2024 02:06:40 -0800
Organization: A noiseless patient Spider
Lines: 32
Message-ID: <86a5o863bj.fsf@linuxsc.com>
References: <YXJnN.184010$xHn7.45772@fx14.iad> <uobt0a$2jo2e$1@dont-email.me> <8634ukeofy.fsf@linuxsc.com> <20240125203408.386@kylheku.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: dont-email.me; posting-host="c20874413056af7bcbd7e84e1693869d";
logging-data="3289873"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+8wUv0yL7CiNQ0/Wi+BU3MWqLzPV/xVFs="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:rctvxoCsTTDCAcWCA73SdOnbJro=
sha1:FW6PbOUkkWUMXPaQRGca3EJdfcY=
 by: Tim Rentsch - Sat, 10 Feb 2024 10:06 UTC

Kaz Kylheku <433-929-6894@kylheku.com> writes:

> On 2024-01-26, Tim Rentsch <tr.17687@z991.linuxsc.com> wrote:
>
>> Lew Pitcher <lew.pitcher@digitalfreehold.ca> writes:
>>
>>> [A] single call to a function not defined by your program source
>>> code or by the ISO C standard will invoke "undefined behaviour".
>>
>> That isn't right. The C standard allows previously translated
>> translation units "[to] be preserved individually or in libraries."
>> Those translation units don't have to be your own code or even
>> necessarily stored, or translated, on the same machine.
>
> This is a strawman interpretation of what Lew is almost certainly
> saying,

No, it isn't. You misunderstood my statement.

> which is the salient point that using a function that is not
> somewhere in your program (any translation unit from your sources
> or any translated units you brought to the table yourself), and
> not in the standard, is undefined behavior.

No, it isn't. Whether a library, for example, was something you put
on the machine yourself, or was put there by a hacker without your
knowledge, doesn't affect the presence or absence of undefined
behavior. All that matters is what's in the library. It's
perfectly possible for a library installed by a hacker to perform
only well-defined operations, be well-formed and ABI-compatible,
etc. Just because you don't know what is in the library doesn't
make it undefined behavior.

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor