This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH] Allocation buffers for NSS result construction
- From: DJ Delorie <dj at redhat dot com>
- To: Florian Weimer <fweimer at redhat dot com>
- Cc: libc-alpha at sourceware dot org
- Date: Fri, 16 Jun 2017 15:06:05 -0400
- Subject: Re: [PATCH] Allocation buffers for NSS result construction
- Authentication-results: sourceware.org; auth=none
- Authentication-results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com
- Authentication-results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=dj at redhat dot com
- Dkim-filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 6A9E680C1D
- Dmarc-filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 6A9E680C1D
Florian Weimer <fweimer@redhat.com> writes:
> I don't quite understand what you are after. I think if the code has to
> deal with bad data, explicit checks are better than relying on fringe
> behavior of library functions (printf and "(null)" is another example).
>
> Please post example code, so that I can better understand your requirement.
https://www.sourceware.org/ml/libc-alpha/2017-05/msg00074.html
The data I'm passing from the nss_test helpers may have NULL where a
"char *" string is expected. If the NSS core calls strlen() on it, it
will crash. When I'm building the buffer, I can't just call strlen() or
it will crash. I'm testing to make sure it doesn't crash, and that the
NULL is passed along to the caller.
So either your strlen() (or any other function taking a string) needs to
handle NULL in a defined non-crashing way, or any code using it still
needs to do its own handling. It would be better if handling NULL were
defined in a graceful way by your API to avoid replicating the NULL case
handling at all callers.
For example, if I want to add a NULL string to an array of strings, your
code needs to safely put a NULL pointer in the list (somehow) without
allocating space for it. This is separate from a zero-length string,
where a valid pointer is stored and spac for a NUL byte is allocated.
If I can't put a NULL string in an array of strings at all, your code
can't be used for my case.