From: Galen Charlton Date: Mon, 21 May 2012 21:02:34 +0000 (-0400) Subject: LP# 953299 - defend against null and zero-length cache keys X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=9b8cc2292969a3c4413df764b735166c723128e3;p=working%2FOpenSRF.git LP# 953299 - defend against null and zero-length cache keys Ignore undefined and zero-length (after key normalization) cache keys. Signed-off-by: Galen Charlton Signed-off-by: Dan Scott --- diff --git a/src/perl/lib/OpenSRF/Utils/Cache.pm b/src/perl/lib/OpenSRF/Utils/Cache.pm index 53cf966..ba9f1a1 100644 --- a/src/perl/lib/OpenSRF/Utils/Cache.pm +++ b/src/perl/lib/OpenSRF/Utils/Cache.pm @@ -110,9 +110,11 @@ sub new { sub put_cache { my($self, $key, $value, $expiretime ) = @_; + return undef unless( defined $key and defined $value ); + $key = _clean_cache_key($key); - return undef unless( defined $key and defined $value ); + return undef if( $key eq '' ); # no zero-length keys $value = OpenSRF::Utils::JSON->perl2JSON($value); @@ -158,8 +160,9 @@ sub put_cache { sub delete_cache { my( $self, $key ) = @_; + return undef unless defined $key; $key = _clean_cache_key($key); - if(!$key) { return undef; } + return undef if $key eq ''; # no zero-length keys if($self->{persist}){ _load_methods(); } $self->{memcache}->delete($key); if( $self->{persist} ) { @@ -176,8 +179,12 @@ sub delete_cache { sub get_cache { my($self, $key ) = @_; + return undef unless defined $key; + $key = _clean_cache_key($key); + return undef if $key eq ''; # no zero-length keys + my $val = $self->{memcache}->get( $key ); return OpenSRF::Utils::JSON->JSON2perl($val) if defined($val);