[CDRIVER-4679] Prefer strerror_l instead of dealing with buggy XSI-compliant strerror_r detection Created: 13/Jul/23 Updated: 28/Nov/23 Resolved: 24/Jul/23 |
|
| Status: | Closed |
| Project: | C Driver |
| Component/s: | libbson |
| Affects Version/s: | None |
| Fix Version/s: | 1.25.0, 1.24.3 |
| Type: | Bug | Priority: | Unknown |
| Reporter: | Jeremy Mikola | Assignee: | Ezra Chung |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||||||||||||||||||||||
| Description |
Update: ResolutionReduced the scope of strerror_r use to the Apple platform where strerror_l is not yet available and deliberately opted to discard the return value to avoid dealing with complicated XSI-compliance detection. Prefer strerror_l otherwise on Unix-like platforms as to-be-recommended by POSIX spec. See the PR description for more detail. SummaryA user in mongodb/mongo-php-driver#1445 reported a build error compiling libbson (via the PHP driver) on Alpine Linux:
According to the clang docs, -Wint-conversion is an error by default. Since libbson is tested with clang, I think this has more to do with Alpine linux. Some further research lead me to strerror_r(3):
Looking at bson-error.c, libbson currently uses the following condition to check for GNU:
If that condition is not met, XSI is used by default. EnvironmentUser was compiling the PHP driver 1.16.1 with bundled libbson 1.24.1 using clang on Alpine Linux (versions unknown). The PHP driver was being compiled statically into PHP, which is atypical, but I don't think that's relevant. Additional BackgroundSome related discussions on strerror_r(3) and Alpine:
|
| Comments |
| Comment by Ezra Chung [ 04/Aug/23 ] |
|
jmikola@mongodb.com Done. |
| Comment by Jeremy Mikola [ 04/Aug/23 ] |
|
ezra.chung@mongodb.com: Would you like to rename this issue for changelog visibility reasons? Perhaps something to convey we're preferring strerror_l for XSI, falling back to GNU strerror_r, and erroring otherwise? The special Windows/Apple logic doesn't need to be mentioned IMO. |
| Comment by Githook User [ 03/Aug/23 ] |
|
Author: {'name': 'Ezra Chung', 'email': '88335979+eramongodb@users.noreply.github.com', 'username': 'eramongodb'}Message:
|
| Comment by Githook User [ 03/Aug/23 ] |
|
Author: {'name': 'Ezra Chung', 'email': '88335979+eramongodb@users.noreply.github.com', 'username': 'eramongodb'}Message:
|
| Comment by Githook User [ 24/Jul/23 ] |
|
Author: {'name': 'Ezra Chung', 'email': '88335979+eramongodb@users.noreply.github.com', 'username': 'eramongodb'}Message:
|
| Comment by Githook User [ 24/Jul/23 ] |
|
Author: {'name': 'Ezra Chung', 'email': '88335979+eramongodb@users.noreply.github.com', 'username': 'eramongodb'}Message:
|
| Comment by Jeremy Mikola [ 14/Jul/23 ] |
|
Some further investigation by the user determined that php/php-src@067df26 (PHP 8.2+) introduced -D_GNU_SOURCE to PHP's build flags. That explains why the issue only started appearing in PHP 8.2+. I believe libbson still needs a patch to improve its detection of which strerror_r() variant is being used. I also noted that PHP calls strerror_r() once, but never works with its return value. That might explain why PHP itself never encountered a build error; however, there may still be a lingering bug there for the GNU version of the function, which I reported in this comment on the above commit. |