<feed xmlns='http://www.w3.org/2005/Atom'>
<title>src/lib/libc/stdlib, branch release/13.1.0</title>
<subtitle>FreeBSD source tree</subtitle>
<id>https://cgit-dev.freebsd.org/src/atom?h=release%2F13.1.0</id>
<link rel='self' href='https://cgit-dev.freebsd.org/src/atom?h=release%2F13.1.0'/>
<link rel='alternate' type='text/html' href='https://cgit-dev.freebsd.org/src/'/>
<updated>2022-03-04T19:47:02Z</updated>
<entry>
<title>qsort.c: prevent undefined behavior</title>
<updated>2022-03-04T19:47:02Z</updated>
<author>
<name>Stefan Eßer</name>
<email>se@FreeBSD.org</email>
</author>
<published>2022-01-13T10:09:38Z</published>
<link rel='alternate' type='text/html' href='https://cgit-dev.freebsd.org/src/commit/?id=19b00621b65fc4092417d33e12b471413f07228c'/>
<id>urn:sha1:19b00621b65fc4092417d33e12b471413f07228c</id>
<content type='text'>
Mark Milliard has detected a case of undefined behavior with the LLVM
UBSAN. The mandoc program called qsort with a==NULL and n==0, which is
allowed by the POSIX standard. The qsort() in FreeBSD did not attempt
to perform any accesses using the passed pointer for n==0, but it did
add an offset to the pointer value, which is undefined behavior in
case of a NULL pointer. This operation has no adverse effects on any
achitecture supported by FreeBSD, but could be caught in more strict
environments.

After some discussion in the freebsd-current mail list, it was
concluded that the case of a==NULL and n!=0 should still be caught by
UBSAN (or cause a program abort due to an illegal access) in order to
not hide errors in programs incorrectly invoking qsort().

Only the the case of a==NULL and n==0 should be fixed to not perform
the undefined operation on a NULL pointer.

This commit makes qsort() exit before reaching the point of
potentially undefined behvior for the case n==0, but does not test
the value of a, since the result will not depend on whether this
pointer is NULL or an actual pointer to an array if n==0.

The issue found by Mark Milliard in the whatis command has been
reported to the upstream (OpenBSD) and has already been patched
there.

(cherry picked from commit d106f982a54cd299671ccad58bc456138a22ae7b)
</content>
</entry>
<entry>
<title>Fix null pointer subtraction in mergesort()</title>
<updated>2021-08-31T19:05:43Z</updated>
<author>
<name>Dimitry Andric</name>
<email>dim@FreeBSD.org</email>
</author>
<published>2021-08-27T17:45:43Z</published>
<link rel='alternate' type='text/html' href='https://cgit-dev.freebsd.org/src/commit/?id=ef314cd4bae273be01eb45bae3af63680e65465c'/>
<id>urn:sha1:ef314cd4bae273be01eb45bae3af63680e65465c</id>
<content type='text'>
Clang 13 produces the following warning for this function:

lib/libc/stdlib/merge.c:137:41: error: performing pointer subtraction with a null pointer has undefined behavior [-Werror,-Wnull-pointer-subtraction]
        if (!(size % ISIZE) &amp;&amp; !(((char *)base - (char *)0) % ISIZE))
                                               ^ ~~~~~~~~~

This is meant to check whether the size and base parameters are aligned
to the size of an int, so use our __is_aligned() macro instead.

Also remove the comment that indicated this "stupid subtraction" was
done to pacify some ancient and unknown Cray compiler, and which has
been there since the BSD 4.4 Lite Lib Sources were imported.

(cherry picked from commit 4e5d32a445f90d37966cd6de571978551654e3f3)
</content>
</entry>
<entry>
<title>Fix race between first rand(3) calls with _once().</title>
<updated>2021-08-19T01:11:51Z</updated>
<author>
<name>Alexander Motin</name>
<email>mav@FreeBSD.org</email>
</author>
<published>2021-07-21T15:25:46Z</published>
<link rel='alternate' type='text/html' href='https://cgit-dev.freebsd.org/src/commit/?id=09d4fe40e039d4b08a034454c36aed86571725b0'/>
<id>urn:sha1:09d4fe40e039d4b08a034454c36aed86571725b0</id>
<content type='text'>
Before this patch there was a chance for thread that called rand(3)
slightly later to see rand3_state already allocated, but not yet
initialized.  While this API is not expected to be thread-safe, it
is not expected to crash.  ztest on 64-thread system reproduced it
reliably for me.

Submitted by:	avg@
MFC after:	1 month

(cherry picked from commit 3a57f08b5042f15bb8ffb2fcce99d082d225d4cf)
</content>
</entry>
<entry>
<title>_Exit(3): document implementation</title>
<updated>2021-08-12T12:37:54Z</updated>
<author>
<name>Konstantin Belousov</name>
<email>kib@FreeBSD.org</email>
</author>
<published>2021-08-05T16:04:44Z</published>
<link rel='alternate' type='text/html' href='https://cgit-dev.freebsd.org/src/commit/?id=c4bb20a5ec876fb44e152c5773b7104e4c753dec'/>
<id>urn:sha1:c4bb20a5ec876fb44e152c5773b7104e4c753dec</id>
<content type='text'>
(cherry picked from commit ee62fb2e1e14eab35d4e4e92535bcac9fc91eeb8)
</content>
</entry>
<entry>
<title>libc/qsort: Don't allow interposing recursive calls</title>
<updated>2021-03-17T09:46:58Z</updated>
<author>
<name>Alex Richardson</name>
<email>arichardson@FreeBSD.org</email>
</author>
<published>2021-02-18T10:12:29Z</published>
<link rel='alternate' type='text/html' href='https://cgit-dev.freebsd.org/src/commit/?id=8dc9d6a7b09f28458c1ad2848abdeb3f944c3132'/>
<id>urn:sha1:8dc9d6a7b09f28458c1ad2848abdeb3f944c3132</id>
<content type='text'>
This causes problems when using ASAN with a runtime older than 12.0 since
the intercept does not expect qsort() to call itself using an interposable
function call. This results in infinite recursion and stack exhaustion
when a binary compiled with -fsanitize=address calls qsort.
See also https://bugs.llvm.org/show_bug.cgi?id=46832 and
https://reviews.llvm.org/D84509 (ASAN runtime patch).

To prevent this problem, this patch uses a static helper function
for the actual qsort() implementation. This prevents interposition and
allows for direct calls. As a nice side-effect, we can also move the
qsort_s checks to the top-level function and out of the recursive calls.

Reviewed By:	kib
Differential Revision: https://reviews.freebsd.org/D28133

(cherry picked from commit cbcfe28f9d5f975f97b7fb4a0d72bc9780eb0c46)
</content>
</entry>
<entry>
<title>libc: Fix null pointer arithmetic warning in mergesort</title>
<updated>2021-01-20T09:56:01Z</updated>
<author>
<name>Alex Richardson</name>
<email>arichardson@FreeBSD.org</email>
</author>
<published>2021-01-20T09:56:01Z</published>
<link rel='alternate' type='text/html' href='https://cgit-dev.freebsd.org/src/commit/?id=cef1942711624c6cf1d237118531cfad9ade05ac'/>
<id>urn:sha1:cef1942711624c6cf1d237118531cfad9ade05ac</id>
<content type='text'>
This file has other questionable code and "optimizations" (such as copying
one int at a time) that are probably no longer useful, so it might make
sense to replace it with a different implementation at some point.

Reviewed By:	jhb
Differential Revision: https://reviews.freebsd.org/D28134
</content>
</entry>
<entry>
<title>getopt: Fix conversion from string-literal to non-const char *</title>
<updated>2021-01-19T21:23:25Z</updated>
<author>
<name>Alex Richardson</name>
<email>arichardson@FreeBSD.org</email>
</author>
<published>2021-01-19T11:35:04Z</published>
<link rel='alternate' type='text/html' href='https://cgit-dev.freebsd.org/src/commit/?id=0348c8fcfaa22d4f2bf548ad9c187c09ef90c533'/>
<id>urn:sha1:0348c8fcfaa22d4f2bf548ad9c187c09ef90c533</id>
<content type='text'>
Define a non-const static char EMSG[] = "" to avoid having to add
__DECONST() to all uses of EMSG. Also make current_dash a const char *
to fix this warning.
</content>
</entry>
<entry>
<title>libc: Fix most issues reported by mandoc</title>
<updated>2020-12-19T14:54:28Z</updated>
<author>
<name>Gordon Bergling</name>
<email>gbe@FreeBSD.org</email>
</author>
<published>2020-12-19T14:54:28Z</published>
<link rel='alternate' type='text/html' href='https://cgit-dev.freebsd.org/src/commit/?id=f6d234d8706fa4ad513bb5db2976b0e354a0f0fe'/>
<id>urn:sha1:f6d234d8706fa4ad513bb5db2976b0e354a0f0fe</id>
<content type='text'>
- varios "new sentence, new line" warnings
- varios "sections out of conventional order" warnings
- varios "unusual Xr order" warnings
- varios "missing section argument" warnings
- varios "no blank before trailing delimiter" warnings
- varios "normalizing date format" warnings

MFC after:	1 month
</content>
</entry>
<entry>
<title>Further refinements of ptsname_r(3) interface:</title>
<updated>2020-10-20T01:29:45Z</updated>
<author>
<name>Xin LI</name>
<email>delphij@FreeBSD.org</email>
</author>
<published>2020-10-20T01:29:45Z</published>
<link rel='alternate' type='text/html' href='https://cgit-dev.freebsd.org/src/commit/?id=5011fb430a898f8ef4f53f4ae2034d029cd388c0'/>
<id>urn:sha1:5011fb430a898f8ef4f53f4ae2034d029cd388c0</id>
<content type='text'>
 - Hide ptsname_r under __BSD_VISIBLE for now as the specification
   is not finalized at this time.
 - Keep Symbol.map sorted.
 - Avoid the interposing of ptsname_r(3) from an user application
   from breaking ptsname(3) by making the implementation a static
   method and call the static function from ptsname(3) instead.

Reported by:	kib
Reviewed by:	kib, jilles
MFC after:	2 weeks
Differential Revision:	https://reviews.freebsd.org/D26845
</content>
</entry>
<entry>
<title>Implement ptsname_r.</title>
<updated>2020-10-17T04:14:38Z</updated>
<author>
<name>Xin LI</name>
<email>delphij@FreeBSD.org</email>
</author>
<published>2020-10-17T04:14:38Z</published>
<link rel='alternate' type='text/html' href='https://cgit-dev.freebsd.org/src/commit/?id=3e7224dffe26948af09082309bbb6a6803e12049'/>
<id>urn:sha1:3e7224dffe26948af09082309bbb6a6803e12049</id>
<content type='text'>
MFC after:	2 weeks
PR:		250062
Reviewed by:	jilles, 0mp, Ray &lt;i maskray me&gt;
Differential Revision:	https://reviews.freebsd.org/D26647
</content>
</entry>
</feed>
