[PATCH] avoid strlen(NULL)

Douglas Bagnall douglas.bagnall at catalyst.net.nz
Thu Oct 18 21:38:39 UTC 2018


Yesterday I pushed a little optimisation in ce518f387f9f that introduced
a possible strlen(NULL).

It is funny how mistakes you miss in the editor become so blindingly
obvious when they are sent back to you on a public email list.

BTW, this strlen was accounting for 95% of the CPU time of a large
failing join (and about 6% of the time of a successful join, which I
don't know how to explain).

Douglas

On 19/10/18 12:18 AM, Douglas Bagnall wrote:
> The branch, master has been updated
>        via  ce518f3 ldb_ldif: be less horribly efficient in debugging
>        via  30e9c00 py3_tests/kcc : test_verify can hit KCCError as well as GraphError
>        via  204bd0e4 py3/tests/kcc: turn error into failure for flapping.d/kcc
>       from  e404b6a selftest: add tests for samba-tool drs uptodateness
> 
> https://git.samba.org/?p=samba.git;a=shortlog;h=master
> 
> 
> - Log -----------------------------------------------------------------
> commit ce518f387f9f6742f642ce33901cd778375bb4fd
> Author: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
> Date:   Wed Oct 17 16:28:25 2018 +1300
> 
>     ldb_ldif: be less horribly efficient in debugging
>     
>     perf said all the time was in strlen.
>     
>     Signed-off-by: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
>     Reviewed-by: Andrew Bartlett <abartlet at samba.org>
>     
>     Autobuild-User(master): Douglas Bagnall <dbagnall at samba.org>
>     Autobuild-Date(master): Thu Oct 18 13:17:30 CEST 2018 on sn-devel-144
[...]

> 
> Changeset truncated at 500 lines:
> 
> diff --git a/lib/ldb/common/ldb_ldif.c b/lib/ldb/common/ldb_ldif.c
> index e23b568..ec1859b 100644
> --- a/lib/ldb/common/ldb_ldif.c
> +++ b/lib/ldb/common/ldb_ldif.c
> @@ -313,6 +313,7 @@ static int ldb_ldif_write_trace(struct ldb_context *ldb,
>  
>  	for (i=0;i<msg->num_elements;i++) {
>  		const struct ldb_schema_attribute *a;
> +		size_t namelen = strlen(msg->elements[i].name);
>  
>  		if (msg->elements[i].name == NULL) {
>  			ldb_debug(ldb, LDB_DEBUG_ERROR,
> @@ -347,7 +348,6 @@ static int ldb_ldif_write_trace(struct ldb_context *ldb,
>  			CHECK_RET;
>  			continue;
>  		}
> -
>  		for (j=0;j<msg->elements[i].num_values;j++) {
>  			struct ldb_val v;
>  			bool use_b64_encode = false;
> @@ -371,7 +371,7 @@ static int ldb_ldif_write_trace(struct ldb_context *ldb,
>  				CHECK_RET;
>  				ret = base64_encode_f(ldb, fprintf_fn, private_data,
>  						      (char *)v.data, v.length,
> -						      strlen(msg->elements[i].name)+3);
> +						      namelen + 3);
>  				CHECK_RET;
>  				ret = fprintf_fn(private_data, "\n");
>  				CHECK_RET;
> @@ -384,7 +384,7 @@ static int ldb_ldif_write_trace(struct ldb_context *ldb,
>  				} else {
>  					ret = fold_string(fprintf_fn, private_data,
>  							  (char *)v.data, v.length,
> -							  strlen(msg->elements[i].name)+2);
> +							  namelen + 2);
>  				}
>  				CHECK_RET;
>  				ret = fprintf_fn(private_data, "\n");
> diff --git a/python/samba/tests/kcc/__init__.py b/python/samba/tests/kcc/__init__.py

-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-ldb_ldif-avoid-strlen-NULL.patch
Type: text/x-patch
Size: 1191 bytes
Desc: not available
URL: <http://lists.samba.org/pipermail/samba-technical/attachments/20181019/f0960d6f/0001-ldb_ldif-avoid-strlen-NULL.bin>


More information about the samba-technical mailing list