Uploaded image for project: 'C Driver'
  1. C Driver
  2. CDRIVER-4234

Build failure on Mac OS X 10.6 due to use of arc4random_buf

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Minor - P4 Minor - P4
    • 1.20.1
    • Affects Version/s: 1.20.0
    • Component/s: libbson
    • Labels:
      None

      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

            Assignee:
            kevin.albertson@mongodb.com Kevin Albertson
            Reporter:
            ryandesign Ryan Schmidt
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: