[gnutls-devel] GnuTLS | Fix gnutls_pkcs11_token_get_info for short output buffers and fix a memleak (!827)

Development of GNU's TLS library gnutls-devel at lists.gnutls.org
Thu Nov 29 19:02:28 CET 2018


New Merge Request !827

https://gitlab.com/gnutls/gnutls/merge_requests/827

Project:Branches: Lekensteyn/gnutls:fix-token-info-modname to gnutls/gnutls:master
Author:    Peter Wu
Assignee:  


Fixes a memleak and some inconsistent behavior when the output buffer is too short.
Not sure if it is worth documenting presence of such bugs in the function documentation, I noticed a crash when using this pattern:

```c
size = 0;
ret = gnutls_pkcs11_token_get_info(url, GNUTLS_PKCS11_TOKEN_MODNAME, NULL, &size);
/* error handling for ret */
buffer = g_malloc(size);
ret = gnutls_pkcs11_token_get_info(url, GNUTLS_PKCS11_TOKEN_MODNAME, buffer, &size);
````

Note that with the "consistency fix", the above has to be changed to this:
```c
size = 0;
ret = gnutls_pkcs11_token_get_info(url, GNUTLS_PKCS11_TOKEN_MODNAME, NULL, &size);
/* error handling for ret */
++size;  /* include memory for NULL terminator */
buffer = g_malloc(size);
ret = gnutls_pkcs11_token_get_info(url, GNUTLS_PKCS11_TOKEN_MODNAME, buffer, &size);
````

## Checklist
 * [ ] Code modified for feature
 * [ ] Test suite updated with functionality tests
 * [ ] Test suite updated with negative tests
 * [ ] Documentation updated / NEWS entry present (for non-trivial changes)

## Reviewer's checklist:
 * [ ] Any issues marked for closing are addressed
 * [ ] There is a test suite reasonably covering new functionality or modifications
 * [ ] Function naming, parameters, return values, types, etc., are consistent and according to `CONTRIBUTION.md`
 * [ ] This feature/change has adequate documentation added
 * [ ] No obvious mistakes in the code

-- 
Reply to this email directly or view it on GitLab: https://gitlab.com/gnutls/gnutls/merge_requests/827
You're receiving this email because of your account on gitlab.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.gnupg.org/pipermail/gnutls-devel/attachments/20181129/ca3d604a/attachment.html>


More information about the Gnutls-devel mailing list