Skip to content

Conflicting documentation for curl_easy_getinfo #846

Closed
@ethomson

Description

@ethomson

I would like to get the TLS certificate chain using curl_easy_getinfo(CURL *, CURLINFO_CERTINFO, ...). I initially did this by passing a struct curl_certinfo *, eg:

struct curl_certinfo *certinfo;
curl_easy_getinfo(curl_handle, CURLINFO_CERTINFO, &certinfo);

I did this based on the guidance in the documentation for CURLINFO_CERTINFO:

Pass a pointer to a 'struct curl_certinfo *' and you'll get it set to point to struct that holds a number of linked lists with info about the certificate chain

And indeed this seems to work nicely, however when compiling with GCC, I get the following warning:

warning: call to ‘_curl_easy_getinfo_err_curl_slist’ declared with attribute warning: curl_easy_getinfo expects a pointer to struct curl_slist * for this info

Since there is some handy type checking on that function. This type checking disagrees with the aforementioned documentation, but agrees with the documentation for curl_easy_getinfo.

In addition, the certinfo.c example throws them both into a union and uses them both.

I realize that since you're really getting a pointer to a struct curl_certinfo, and that has a struct curl_slist * as its first member that you can fundamentally use either. But it would be nice if the documentation and examples were internally consistent. Ideally either:

  1. The documentation for curl_easy_getinfo was updated to reflect that struct curl_certinfo was a legitimate type and that the header was also updated to reflect this, or
  2. The documentation for CURLINFO_CERTINFO was updated to document that struct curl_slist * is the used type.

And that the aforementioned example was updated to only make reference to whichever type is canonical.

Activity

bagder

bagder commented on Jun 1, 2016

@bagder
Member

Agreed. It takes a struct curl_certinfo * argument and we should make sure both typecheck-gcc.h and the certinfo.c example are in line with that!

You up to providing a patch?

ethomson

ethomson commented on Jun 1, 2016

@ethomson
Author

I can send a PR for the docs and updating the example. There is much magic in the typecheck-gcc.h though and I regret that I don't have time to decipher that. If I provide a PR for the first two can you assist with the latter?

bagder

bagder commented on Jun 1, 2016

@bagder
Member

I poked around at it earlier today and while I can certainly see what changes that need to get done, the entire typecheck logic doesn't really seem to work for me at all at the moment (I tried gcc 5.3.1 as as well as 4.7) so I'm a bit puzzled. I haven't figured out why yet.

Applying the patch below fixes the example but causes no warning for me with an unmodified typecheck-gcc.h file.

diff --git a/docs/examples/certinfo.c b/docs/examples/certinfo.c
index de2e310..92bf588 100644
--- a/docs/examples/certinfo.c
+++ b/docs/examples/certinfo.c
@@ -3,11 +3,11 @@
  *  Project                     ___| | | |  _ \| |
  *                             / __| | | | |_) | |
  *                            | (__| |_| |  _ <| |___
  *                             \___|\___/|_| \_\_____|
  *
- * Copyright (C) 1998 - 2015, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
  *
  * This software is licensed as described in the file COPYING, which
  * you should have received as part of this distribution. The terms
  * are also available at https://curl.haxx.se/docs/copyright.html.
  *
@@ -54,28 +54,23 @@ int main(void)
     curl_easy_setopt(curl, CURLOPT_CERTINFO, 1L);

     res = curl_easy_perform(curl);

     if(!res) {
-      union {
-        struct curl_slist    *to_info;
-        struct curl_certinfo *to_certinfo;
-      } ptr;
+      struct curl_certinfo *certinfo;

-      ptr.to_info = NULL;
+      res = curl_easy_getinfo(curl, CURLINFO_CERTINFO, &certinfo);

-      res = curl_easy_getinfo(curl, CURLINFO_CERTINFO, &ptr.to_info);
-
-      if(!res && ptr.to_info) {
+      if(!res && certinfo) {
         int i;

-        printf("%d certs!\n", ptr.to_certinfo->num_of_certs);
+        printf("%d certs!\n", certinfo->num_of_certs);

-        for(i = 0; i < ptr.to_certinfo->num_of_certs; i++) {
+        for(i = 0; i < certinfo->num_of_certs; i++) {
           struct curl_slist *slist;

-          for(slist = ptr.to_certinfo->certinfo[i]; slist; slist = slist->next)
+          for(slist = certinfo->certinfo[i]; slist; slist = slist->next)
             printf("%s\n", slist->data);

         }
       }
ethomson

ethomson commented on Jun 1, 2016

@ethomson
Author

I poked around at it earlier today and while I can certainly see what changes that need to get done, the entire typecheck logic doesn't really seem to work for me at all at the moment (I tried gcc 5.3.1 as as well as 4.7) so I'm a bit puzzled. I haven't figured out why yet.

Yeah, I was running into the same problem. I don't see these warning on any of my machines, only when running on gcc on travis. I wasn't able to dig in deeply enough to know what's different about their setup than mine.

locked as resolved and limited conversation to collaborators on May 7, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @bagder@ethomson

        Issue actions

          Conflicting documentation for `curl_easy_getinfo` · Issue #846 · curl/curl