[CDRIVER-4234] Build failure on Mac OS X 10.6 due to use of arc4random_buf Created: 25/Nov/21  Updated: 28/Oct/23  Resolved: 13/Dec/21

Status: Closed
Project: C Driver
Component/s: libbson
Affects Version/s: 1.20.0
Fix Version/s: 1.20.1

Type: Bug Priority: Minor - P4
Reporter: Ryan Schmidt Assignee: Kevin Albertson
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
is related to CDRIVER-4233 error: implicit declaration of functi... Closed

 Description   

I can't build libbson from mongo-c-driver 1.20.0 on Mac OS X 10.6.8 with Apple clang version 1.7 (tags/Apple/clang-77) (based on LLVM 2.9svn) from Xcode 3.2.6. The error is:

src/libbson/src/bson/bson-context.c:234:4: warning: implicit declaration of function 'arc4random_buf' is invalid in C99 [-Wimplicit-function-declaration]
   arc4random_buf (&result, sizeof (result));
   ^
1 warning generated.

Undefined symbols for architecture i386:
  "_arc4random_buf", referenced from:
      __bson_context_init_random in bson-context.c.o
ld: symbol(s) not found for architecture i386

This problem was introduced in https://github.com/mongodb/mongo-c-driver/pull/723 by unconditionally using arc4random_buf on macOS. arc4random_buf was introduced in Mac OS X 10.7.

This made me look at the code in _get_rand which raised a few questions:

  1. Why is a potentially inaccurate list of arc4random_buf-supporting systems being maintained in this file? Wouldn't it be simpler and better to detect the availability of arc4random_buf at configure time?
  2. If rand_r is not defined but arc4random_buf is, why does it use rand instead of arc4random_buf? Shouldn't arc4random_buf be the first choice if it is available?

Assuming the answer to both questions is that there is no good reason, I propose the following modification to address these issues:

https://github.com/macports/macports-ports/blob/36d680300e67a74055138a067e4174c88ed96793/devel/mongo-c-driver/files/arc4random_buf.patch



 Comments   
Comment by Githook User [ 13/Dec/21 ]

Author:

{'name': 'Ryan Schmidt', 'email': 'ryandesign@macports.org', 'username': 'ryandesign'}

Message: CDRIVER-4234 Detect arc4random_buf using cmake (#911)
Branch: r1.20
https://github.com/mongodb/mongo-c-driver/commit/0a5b7bc19356c731a1766017d3aba5b2d1f19509

Comment by Githook User [ 13/Dec/21 ]

Author:

{'name': 'Ryan Schmidt', 'email': 'ryandesign@macports.org', 'username': 'ryandesign'}

Message: CDRIVER-4234 Detect arc4random_buf using cmake (#911)
Branch: master
https://github.com/mongodb/mongo-c-driver/commit/54e5ecb561e09441f6695ca6c0b202aae7b98cd2

Comment by Ryan Schmidt [ 12/Dec/21 ]

Ok they're separated now.

Comment by Ryan Schmidt [ 12/Dec/21 ]

I should probably separate the second commit into two...

Comment by Ryan Schmidt [ 12/Dec/21 ]

Sure, is this ok?

https://github.com/mongodb/mongo-c-driver/pull/911

Comment by Kevin Albertson [ 12/Dec/21 ]

 

arc4random_buf was introduced in Mac OS X 10.7.

I do not have a Mac OS X 10.6 handy to test building. But comparing Libc versions in https://opensource.apple.com/releases/ shows arc4random_buf introduced in stdlib.h in OS X 10.7:
https://github.com/apple-oss-distributions/Libc/blob/Libc-763.11/include/stdlib.h#L331-L335
(comparing with 10.6.8 https://github.com/apple-oss-distributions/Libc/blob/Libc-594.9.5/include/stdlib.h#L331-L334))

1. Why is a potentially inaccurate list of arc4random_buf-supporting systems being maintained in this file? Wouldn't it be simpler and better to detect the availability of arc4random_buf at configure time?

I do not see a clear reason. I agree it is preferable to check for arc4random_buf at configure time.

2. If rand_r is not defined but arc4random_buf is, why does it use rand instead of arc4random_buf? Shouldn't arc4random_buf be the first choice if it is available?

I do not see a clear reason. arc4random_buf seems preferable to rand_r.

Assuming the answer to both questions is that there is no good reason, I propose the following modification to address these issues:

https://github.com/macports/macports-ports/blob/36d680300e67a74055138a067e4174c88ed96793/devel/mongo-c-driver/files/arc4random_buf.patch

Thank you for including the patch! The patch LGTM and it applies cleanly on the latest commit (0756cbb4470a797be7d70841a7c922643dd30d55). Would you like to submit a pull-request? If not, I am happy to put it up for review.

Generated at Wed Feb 07 21:20:20 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.