添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

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

We recently performed our own OpenSSL build based on the 1.1.1h sources from this repo as static library and ensured that we have the same compiler settings used for the build as we use elsewhere for our C++ based code. This means that we also activated _POSIX_C_SOURCE=200809L while doing so. With these settings everything builds fine except the file crypto/bio/b_addr.c, which gives us the following diagnostics for gcc9:

[INFO] /home/jenkins/jenkins/workspace/dmb1/com.github.openssl-linux-x86_64-gcc9/src/crypto/bio/b_addr.c: In function ‘addr_strings’:
[INFO] /home/jenkins/jenkins/workspace/dmb1/com.github.openssl-linux-x86_64-gcc9/src/crypto/bio/b_addr.c:198:19: error: ‘NI_MAXHOST’ undeclared (first use in this function)
[INFO]   198 |         char host[NI_MAXHOST] = "", serv[NI_MAXSERV] = "";
[INFO]       |                   ^~~~~~~~~~
[INFO] /home/jenkins/jenkins/workspace/dmb1/com.github.openssl-linux-x86_64-gcc9/src/crypto/bio/b_addr.c:198:19: note: each undeclared identifier is reported only once for each function it appears in
[INFO] [ 15%] Building C object crypto/CMakeFiles/crypto.dir/bio/bf_null.c.o
[INFO] /home/jenkins/jenkins/workspace/dmb1/com.github.openssl-linux-x86_64-gcc9/src/crypto/bio/b_addr.c:198:42: error: ‘NI_MAXSERV’ undeclared (first use in this function)
[INFO]   198 |         char host[NI_MAXHOST] = "", serv[NI_MAXSERV] = "";
[INFO]       |                                          ^~~~~~~~~~
[INFO] /home/jenkins/jenkins/workspace/dmb1/com.github.openssl-linux-x86_64-gcc9/src/crypto/bio/b_addr.c:198:37: warning: unused variable ‘serv’ [-Wunused-variable]
[INFO]   198 |         char host[NI_MAXHOST] = "", serv[NI_MAXSERV] = "";
[INFO]       |                                     ^~~~
[INFO] /home/jenkins/jenkins/workspace/dmb1/com.github.openssl-linux-x86_64-gcc9/src/crypto/bio/b_addr.c:198:14: warning: unused variable ‘host’ [-Wunused-variable]
[INFO]   198 |         char host[NI_MAXHOST] = "", serv[NI_MAXSERV] = "";
[INFO]       |              ^~~~
[INFO] [ 15%] Building C object crypto/CMakeFiles/crypto.dir/bio/bio_cb.c.o
[INFO] In file included from /home/jenkins/jenkins/workspace/dmb1/com.github.openssl-linux-x86_64-gcc9/src/include/internal/cryptlib.h:25,
[INFO]                  from /home/jenkins/jenkins/workspace/dmb1/com.github.openssl-linux-x86_64-gcc9/src/crypto/bio/bio_local.h:89,
[INFO]                  from /home/jenkins/jenkins/workspace/dmb1/com.github.openssl-linux-x86_64-gcc9/src/crypto/bio/b_addr.c:13:
[INFO] /home/jenkins/jenkins/workspace/dmb1/com.github.openssl-linux-x86_64-gcc9/src/crypto/bio/b_addr.c: In function ‘BIO_lookup_ex’:
[INFO] /home/jenkins/jenkins/workspace/dmb1/com.github.openssl-linux-x86_64-gcc9/src/crypto/bio/b_addr.c:811:52: error: ‘h_errno’ undeclared (first use in this function); did you mean ‘errno’?
[INFO]   811 |                 SYSerr(SYS_F_GETHOSTBYNAME, 1000 + h_errno);
[INFO]       |                                                    ^~~~~~~
[INFO] /home/jenkins/jenkins/workspace/dmb1/com.github.openssl-linux-x86_64-gcc9/src/include/openssl/err.h:29:61: note: in definition of macro ‘ERR_PUT_error’
[INFO]    29 | #  define ERR_PUT_error(a,b,c,d,e)        ERR_put_error(a,b,c,d,e)
[INFO]       |                                                             ^
[INFO] /home/jenkins/jenkins/workspace/dmb1/com.github.openssl-linux-x86_64-gcc9/src/crypto/bio/b_addr.c:811:17: note: in expansion of macro ‘SYSerr’
[INFO]   811 |                 SYSerr(SYS_F_GETHOSTBYNAME, 1000 + h_errno);
[INFO]       |                 ^~~~~~
[INFO] make[2]: *** [crypto/CMakeFiles/crypto.dir/build.make:1419: crypto/CMakeFiles/crypto.dir/bio/b_addr.c.o] Error 1

The errors all can be attributed to the same cause:

  • Regarding NI_MAXHOST: According to the man pages:
  • Since glibc 2.8, these definitions are exposed only if suitable feature test macros are defined, namely: _GNU_SOURCE,
    _DEFAULT_SOURCE (since glibc 2.19), or (in glibc versions up to and including 2.19) _BSD_SOURCE or _SVID_SOURCE.

  • Regarding h_errno: There seem to exist similar need to add _GNU_SOURCE
  • We could resolve all compile problems by applying the following changes:

    --- src/crypto/bio/b_addr.c	
    +++ src/crypto/bio/b_addr.c	
    @@ -7,6 +7,10 @@
      * https://www.openssl.org/source/license.html
    +#ifndef _GNU_SOURCE
    +# define _GNU_SOURCE
    +#endif
     #include <assert.h>
     #include <string.h>
    

    This fix seems to be in sync with some other translation units of OpenSSL which also conditionally define _GNU_SOURCE at the very beginning.

    Hmmm, if those macros aren't guaranteed to be available everywhere, wouldn't it make more sense to add this directly after the includes?

    #ifndef NI_MAXHOST
    # define NI_MAXHOST 1025
    #endif
    #ifndef NI_MAXSERV
    # define NI_MAXSERV 32
    #endif

    The users can still choose to use _GNU_SOURCE when configuring:

    ./Configure CFLAGS='-D_GNU_SOURCE'
              

    First: That wouldn't solve the h_errno problem. Second: I don't think that it is a good recommendation to say that user code should add -D_GNU_SOURCE to the compile flags, because this is a define that is usually an implementation detail and should not be set (or unset) universally. It is typically relevant for a specific translation unit and this unit should control this flag.
    Last but not least is the suggested fix consistent with the approaches used in other translation units of OpenSSL which do the same thing.

    We could resolve all compile problems by applying the following changes:

    Can you supply a pull request. Presumably we would need to make the same change against master.

    I made a pull request with "CLA: trivial" as a separate line, but that was rejected. Is this really considered more than a "one-liner" pull-request?

    We could resolve all compile problems by applying the following changes:

    Can you supply a pull request. Presumably we would need to make the same change against master.

    I made a pull request with "CLA: trivial" as a separate line, but that was rejected. Is this really considered more than a "one-liner" pull-request?

    The automation looks at the actual git commit message, not the pull request summary

    I made a pull request with "CLA: trivial" as a separate line, but that was rejected. Is this really considered more than a "one-liner" pull-request?

    The automation looks at the actual git commit message, not the pull request summary

    Thanks! I made now a new pull request (due to problems with amending the original commit) and I ensured that both

    CLA: trivial

    Fixes #13049

    appear as separate lines, but I still get the same error. Apologies if I'm overlooking something obvious. What did I do wrong this time? Thanks for your help.

    Since glibc 2.8, these defines like `NI_MAXHOST` are exposed only
    if suitable feature test macros are defined, namely: _GNU_SOURCE,
    _DEFAULT_SOURCE (since glibc 2.19), or _BSD_SOURCE or _SVID_SOURCE
    (before glibc 2.19), see GETNAMEINFO(3).
    CLA: trivial
    Fixes openssl#13049
    Since glibc 2.8, these defines like `NI_MAXHOST` are exposed only
    if suitable feature test macros are defined, namely: _GNU_SOURCE,
    _DEFAULT_SOURCE (since glibc 2.19), or _BSD_SOURCE or _SVID_SOURCE
    (before glibc 2.19), see GETNAMEINFO(3).
    CLA: trivial
    Fixes #13049
    Reviewed-by: Richard Levitte <[email protected]>
    Reviewed-by: Matt Caswell <[email protected]>
    Reviewed-by: Matthias St. Pierre <[email protected]>
    (Merged from #13054)
    (cherry picked from commit 99501e8)