[PATCH] [tldap] check for successful string conversion

Volker Lendecke Volker.Lendecke at SerNet.DE
Thu Jan 10 10:27:12 UTC 2019


On Thu, Jan 10, 2019 at 11:09:09AM +0100, swen via samba-technical wrote:
> +
> +	errno = 0;
>  	result = strtoull(str, NULL, 10);
> +	if (errno != 0) {
> +		DBG_DEBUG("Attribute conversion failed (%s)\n",
> +			  strerror(errno));
> +		TALLOC_FREE(str);
> +		return false;
> +	}
> +

The return behaviour of strtoull is pretty weird. Posix says:

> Upon successful completion, these functions shall return the converted
> value, if any. If no conversion could be performed, 0 shall be
> returned [Option Start]  and errno may be set to [EINVAL]. [Option
> End] If the correct value is outside the range of representable
> values, {ULONG_MAX} or {ULLONG_MAX} shall be returned and errno set to
> [ERANGE].

Assuming that all implementations actually do the [Option] piece, we
need to check for result 0 or ULLONG_MAX *together* with errno. Just
checking for errno is not sufficient.

You might want to take a look at source3/lib/messages_dgm.c:1460ff.
All the other callers seem not to do this right at the moment.

Time for https://man.openbsd.org/strtonum.3 in libreplace? :-)

Volker

-- 
SerNet GmbH, Bahnhofsallee 1b, 37081 Göttingen
phone: 0551-370000-0, mailto:kontakt at sernet.de
Gesch.F.: Dr. Johannes Loxen und Reinhild Jung
AG Göttingen: HR-B 2816 - http://www.sernet.de



More information about the samba-technical mailing list