Re: [PATCH nfs-utils] libnfsidmap: avoid malloc(0) for empty Local-Realms

Steve Dickson <[email protected]>
Newsgroups gmane.linux.nfs
Message-ID <[email protected]>

On 5/25/26 10:51 PM, xu18736995897-9Onoh4P/[email protected] wrote:
> From: xuchenchen <xuchenchen-UOlijcLmZ/[email protected]>
> 
> conf_get_list() can return an empty list when Local-Realms is present
> but contains only empty fields, such as ", ,". In that case the Realms
> list logging path computes a buffer size of zero and then writes a NUL
> byte to the result of malloc(0).
> 
> Reserve space for the terminating NUL byte and use calloc() so the log
> buffer is valid even when the realm list is empty.
> 
> Signed-off-by: xuchenchen <xuchenchen-UOlijcLmZ/[email protected]>
Committed... (tag: nfs-utils-2-9-2-rc4)

steved
> ---
>   support/nfsidmap/libnfsidmap.c | 5 ++---
>   1 file changed, 2 insertions(+), 3 deletions(-)
> 
> diff --git a/support/nfsidmap/libnfsidmap.c b/support/nfsidmap/libnfsidmap.c
> index 0a912e52..16a79f00 100644
> --- a/support/nfsidmap/libnfsidmap.c
> +++ b/support/nfsidmap/libnfsidmap.c
> @@ -404,15 +404,14 @@ int nfs4_init_name_mapping(char *conffile)
>   	if (idmap_verbosity >= 1) {
>   		struct conf_list_node *r;
>   		char *buf = NULL;
> -		int siz=0;
> +		size_t siz = 1;
>   
>   		if (local_realms) {
>   			TAILQ_FOREACH(r, &local_realms->fields, link) {
>   				siz += (strlen(r->field)+4);
>   			}
> -			buf = malloc(siz);
> +			buf = calloc(1, siz);
>   			if (buf) {
> -				*buf = 0;
>   				TAILQ_FOREACH(r, &local_realms->fields, link) {
>   					sprintf(buf+strlen(buf), "'%s' ", r->field);
>   				}
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.