-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove glibc dependency on and misuse of strerror_r(3) #8379
Comments
The callers of The
Such the workaround is so confusing to maintain. When a new call to |
An update out of the CI fix upon #8390:
This limitation comes from the boundary check design of C11. Instead of treating the string truncation as a success, it supplies The guide for the practical use of
|
Open issue:
|
This issue is stale because it has been open 90 days with no activity. Remove stale label or comment or this will be closed in 5 days. Maintainers can add the |
This issue was closed because it has been stalled for 5 days with no activity. |
Description
Case A
src/flb_network.c
usesstrerror_r(3)
in the way depending on glibc, which breaks the build on the non-glibc platform.Case B
Some of the
strerror_r(3)
calls that compile but may give unexpected results because of misuses.Environment
Case A
Any platform without glibc.
Confirmed on FreeBSD 14.0-RELEASE.
Case B
Any platform with glibc. (Virtually all Linux distros.)
Reproduction Steps
Case A
Build Fluent Bit on the platform without glibc, eg FreeBSD.
Case B
Call
strerror_r(3)
with a validerrno(2)
aserrnum
.(NB not covered by any existing tests)
Expected Behaviour
Case A
The build succeeds.
Case B
strerror_r(3)
fills in the supplied buffer.Observed Behaviour
Case A
The build fails with
src/flb_network.c
.The logs hereafter are taken out of
master
as of f8bd0ce.Case B
It is expected that the undefined content in the supplied buffer is returned as is.
Please refer to the analysis for the detail.
Analysis
Fluent Bit mixes the uses of
strerror_r(3)
in both the POSIX.1-2001 and glibc ways.Case A
The use of
strerror_r(3)
insrc/flb_network.c
assumes glibc:The rest of the calls expect POSIX.1-2001 because their return values are not used.
Case B
The glibc implementation of
strerror_r(3)
returns the pointer to an internalconst
string without copying its content to the supplied buffer iferrnum
is valid.The glibc
strerror_r(3)
implementation excerpt, taken out of the GNU Hurd glibc repository:strerror_r(3)
Difference Between POSIX.1-2001 and glibcint
char *
(which is actuallyconst
)errno(2)
errnum
is valid.Proposed Fix
PR: #8390
Supply the wrapper of
strerror_r(3)
with the POSIX.1-2001 signature and semantics. This solution gives the expected standard compatibility as well as the simple implementation to the caller. In addition, the wrapper can be implemented in a simple way under both the glibc and non-glibc libraries.Remark
glibc changes the
strerror_r(3)
definition to POSIX.1-2001 if(_POSIX_C_SOURCE >= 200112L) && ! _GNU_SOURCE
evaluates totrue
upon the preprocess. I do not recommend that as the fix because the definition of_POSIX_C_SOURCE
has the risk of an unwanted side effect in the future.The text was updated successfully, but these errors were encountered: