[MONGOCRYPT-581] Allow passing negative len to kms_request_append_payload() for strlen() calculation Created: 17/Jul/23  Updated: 27/Oct/23  Resolved: 24/Jul/23

Status: Closed
Project: Libmongocrypt
Component/s: None
Affects Version/s: 1.7.0
Fix Version/s: None

Type: Task Priority: Unknown
Reporter: Jeremy Mikola Assignee: Kevin Albertson
Resolution: Works as Designed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
related to CDRIVER-4694 Do not rely on kms_request_append_pay... Closed
related to PHPC-1895 Add native support for AWS IAM Roles ... Closed
related to CDRIVER-4691 Sync KMS sources with libmongocrypt Closed
Binding Changes: Not Needed

 Description   

55f2ee0 for MONGOCRYPT-468 added the following assertion for the size_t len parameter in kms_request_append_payload():

KMS_ASSERT (len <= SSIZE_MAX);

When building an application with both libmongoc and libmongocrypt, it's possible that the libmongocrypt KMS package will be used instead of the libmongoc version. This is the case with the PHP driver when compiling with bundled sources.

In such a build configuration, the assertion logic breaks MONGODB-AWS auth code that invokes kms_request_append_payload() with len = -1, which is intended to defer to calling strlen().



 Comments   
Comment by Kevin Albertson [ 24/Jul/23 ]

kms_request_append_payload accepts a size_t and does not suggest specially supporting -1 (which would cast to SIZE_MAX):

KMS_MSG_EXPORT (bool)
kms_request_append_payload (kms_request_t *request,
                            const char *payload,
                            size_t len);

CDRIVER-4694 fixed the call in libmongoc to pass strlen rather than cast signed to unsigned. No other callers in libmongocrypt or libmongoc appear to call kms_request_append_payload with passing -1.

I think no change is needed. Closing as "Works as Designed".

Generated at Thu Feb 08 09:09:01 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.