[PATCH] spoolss: cache_key handle allocation failures early

Guenther Deschner gd at samba.org
Wed Apr 15 08:19:37 MDT 2015


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

LGTM, reviewed and pushed to autobuild.

Thanks,
Guenther

On 15/04/15 15:48, David Disseldorp wrote:
> On cache_key allocation failure, set_printer_hnd_name() currently 
> stumbles through the rest of the function, and includes extra
> logic to handle a NULL key later on. Handling the allocation
> failure early makes sense, and also allows for the NULL key checks
> to be removed.
> 
> Signed-off-by: David Disseldorp <ddiss at samba.org> --- 
> source3/rpc_server/spoolss/srv_spoolss_nt.c | 28 
> ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 
> deletions(-)
> 
> diff --git a/source3/rpc_server/spoolss/srv_spoolss_nt.c 
> b/source3/rpc_server/spoolss/srv_spoolss_nt.c index 
> 65a805a..482f711 100644 --- 
> a/source3/rpc_server/spoolss/srv_spoolss_nt.c +++ 
> b/source3/rpc_server/spoolss/srv_spoolss_nt.c @@ -622,18 +622,18
> @@ static WERROR set_printer_hnd_name(TALLOC_CTX *mem_ctx, found = 
> true; }
> 
> +	cache_key = talloc_asprintf(talloc_tos(), "PRINTERNAME/%s", 
> aprinter); +	if (cache_key == NULL) { +		return WERR_NOMEM; +	} + 
> /* * With hundreds of printers, the "for" loop iterating all * 
> shares can be quite expensive, as it is done on every * 
> OpenPrinter. The loop maps "aprinter" to "sname", the * result of 
> which we cache in gencache. */ - -	cache_key = 
> talloc_asprintf(talloc_tos(), "PRINTERNAME/%s", - aprinter); -	if
> ((cache_key != NULL) && - gencache_get(cache_key, talloc_tos(),
> &tmp, NULL)) { - +	if (gencache_get(cache_key, talloc_tos(), &tmp,
> NULL)) { found = (strcmp(tmp, printer_not_found) != 0); if (!found)
> { DEBUG(4, ("Printer %s not found\n", aprinter)); @@ -702,20
> +702,16 @@ static WERROR set_printer_hnd_name(TALLOC_CTX *mem_ctx,
>  TALLOC_FREE(info2); }
> 
> -	if ( !found ) { -		if (cache_key != NULL) { - 
> gencache_set(cache_key, printer_not_found, - time(NULL)+300); -
> TALLOC_FREE(cache_key); -		} +	if (!found) { + 
> gencache_set(cache_key, printer_not_found, +
> time_mono(NULL) + 300); +		TALLOC_FREE(cache_key);
> DEBUGADD(4,("Printer not found\n")); return
> WERR_INVALID_PRINTER_NAME; }
> 
> -	if (cache_key != NULL) { -		gencache_set(cache_key, sname, 
> time(NULL)+300); -		TALLOC_FREE(cache_key); -	} + 
> gencache_set(cache_key, sname, time_mono(NULL) + 300); + 
> TALLOC_FREE(cache_key);
> 
> DEBUGADD(4,("set_printer_hnd_name: Printer found: %s -> %s\n", 
> aprinter, sname));
> 
> 


- -- 
Günther Deschner GPG-ID: 8EE11688
Red Hat gdeschner at redhat.com
Samba Team gd at samba.org
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1

iEYEARECAAYFAlUuc3kACgkQSOk3aI7hFoiBygCgmOrI4PgPKtheDIG32vwkUoab
fukAoIq4xlm6d+mh1uKZCKWTLVWm8xuU
=mumc
-----END PGP SIGNATURE-----


More information about the samba-technical mailing list