Skip to content

curl_version_info age documentation is misleading #21052

Closed

Description

@dfandrich

Specify which documentation you found a problem with

docs/libcurl/curl_version_info.md

The problem

The documentation talks about the caller setting the age parameter appropriately, so that:

libcurl always returns a proper struct that your program understands, while programs in the future might get a different struct.

Later, it also says about age:

You are however guaranteed to get a struct that you have a matching struct for in the header, as you tell libcurl your "age" with the input argument.

However, that age parameter is currently completely ignored in the function. This means that if the returned struct changes in a backward-incompatible way in the future, a future application dynamically-linked to an older libcurl will receive the older struct, despite asking for a newer one, contrary to the documentation.

Since there is no way to return an error indication to the caller if this ever occurs, this documented behaviour can never be honoured. This also means that the implication that the returned struct may some day be incompatible can also never occur without also breaking the ABI.

Applications relying on this behaviour even in the face of backwards-compatible struct changes will also end up with a OOB read. For example, an application might need the feature_names field, so it sets stamp to CURLVERSION_ELEVENTH. However, the binary is run on an old OS with libcurl 7.86.0 that doesn't have this field. The application believes the guarantee libcurl always returns a proper struct that your program understands and reads that field (an OOB read) and even if that itself doesn't result in a segfault, when it dereferences that pointer it just read, it will almost be guaranteed one.

A thoughtful programmer should realize that this reading of the documentation does not and cannot make sense, but we shouldn't be making these kind of impossible guarantees.

This guarantee in the documentation should be removed. Instead, the caller should be admonished instead to check the returned age parameter in the struct. If that value is less than CURLVERSION_NOW (or another fixed CURLVERSION_* value determined by the developer), then the struct should not be dereferenced or it could result in a OOB read. This should be made explicit rather than implicit, as it is now.

Furthermore, if we ever want to reserve the ability to change the struct in backward-incompatible ways using the age parameter, we need to define a way of returning an error if the age request can't be satisfied. This could be by returning NULL or by defining an error field in the struct. Or, we drop the idea that we could ever do this.

Activity

  1. vszakats commented on Mar 21, 2026

    @vszakats
    Member

    Would it be perhaps more self-explanatory if the accepted curl_version_info()
    argument stamp would be named dummy / deprecated and documented as
    no-op / for-compatibility?

    Since its introduction dc9e415 this
    argument hasn't played a role, and for reasons in OP, it likely won't in the future?

    (This may of course come with a documentation update.)

  2. bagder commented on Mar 21, 2026

    @bagder
    Member

    if the returned struct changes in a backward-incompatible way in the future

    It should never do that. I don't think we ever intended that either. The struct can grow, nothing else.

  3. dfandrich commented on Mar 22, 2026

    @dfandrich
    ContributorAuthor

    I don't think we ever intended that either. The struct can grow, nothing else.

    The existence of a stamp parameter implies that some kind of run-time change of the return value was considered. If the buffer was provided by the user, then it would be mandatory to avoid overwriting a too-small buffer, but not if libcurl controls the allocation. I could see it being used one day if the struct ever needs to be "reset", either due to mistakes in its implementation, it getting to large, or to completely rework how the data are returned. Callers will have to check the returned age in that case, too, so that's advice that should be documented now. It's probably better to just create a curl_version_info2() if we ever find the need for a backwards-incompatible struct change.

  4. bagder commented on Mar 22, 2026

    @bagder
    Member

    The existence of a stamp parameter implies that some kind of run-time change of the return value was considered

    Yes, but I think we never could figure of a good way to use it, that would actually work and be a good API.

    It's probably better to just create a curl_version_info2() if we ever find the need for a backwards-incompatible struct change.

    Absolutely. But I can't recall anyone ever having mentioned problems with the existing one.

  5. added a commit that references this issue on Mar 22, 2026
    838cb09
  6. dfandrich commented on Mar 24, 2026

    @dfandrich
    ContributorAuthor

    That's much more clear—thanks.

  7. added a commit that references this issue on Jun 3, 2026
    22db883
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

      Issue actions