[gnutls-devel] GnuTLS | Use matching allocator/deallocator (!2058)

Read-only notification of GnuTLS library development activities gnutls-devel at lists.gnutls.org
Fri Jan 23 20:24:23 CET 2026




Alexander Sosedkin commented: https://gitlab.com/gnutls/gnutls/-/merge_requests/2058#note_3031254571


And another one I found uses `_gnutls_reallocarray`:

https://gitlab.com/gnutls/gnutls/-/blob/0c49dc6db376c2eccae98b0623dab60729d8f171/lib/cert-cred-x509.c#L1306

https://gitlab.com/gnutls/gnutls/-/blob/0c49dc6db376c2eccae98b0623dab60729d8f171/lib/cert-cred-x509.c#L1332

I used a delightfully low-fi and non-comprehensive approach to identify the suspicious places: mixed mentions within curly bracket blocks:

```
#/usr/bin/env python
# public domain, trivial

import sys
import re
from pathlib import Path

ALLOCATOR_RELATED_FUNCTIONS = [
    ['malloc', 'calloc', 'realloc', 'strdup', 'free'],
    ['gnutls_malloc', 'gnutls_calloc', 'gnutls_realloc', 'gnutls_realloc_fast',
     '_gnutls_reallocarray', '_gnutls_reallocarray_fast', 'gnutls_strdup',
     'gnutls_free', 'gnutls_zfree']
]

for filepath in sorted(sys.argv[1:]):
    content = Path(filepath).read_text()
    if content.count('{') != content.count('}'):
        print(f'{filepath} has curly brace mismatch')
        continue

    stack, blocks = [], []
    for i, char in enumerate(content):
        if char == '{':
            stack.append(i)
        elif char == '}':
            blocks.append((stack.pop(), i))

    for start, end in blocks:
        block_text = content[start:end+1]

        families = []
        for family in ALLOCATOR_RELATED_FUNCTIONS:
            funcs = [f for f in family if re.search(rf'\b{f}\b', block_text)]
            if funcs:
                families.append(funcs)

        if len(families) > 1:
            start_line = content[:start].count('\n') + 1
            end_line = content[:end].count('\n') + 1
            print(f'{filepath}:{start_line}-{end_line}: might mix up ' +
                  ' with '.join(['/'.join(funcs) for funcs in families]))
```

-- 
Reply to this email directly or view it on GitLab: https://gitlab.com/gnutls/gnutls/-/merge_requests/2058#note_3031254571
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/20260123/3417d365/attachment-0001.html>


More information about the Gnutls-devel mailing list