jlhsgcib has asked for the wisdom of the Perl Monks concerning the following question:
I've skimmed the posting rules beforehand but this is my very first post here so excuse me if there is any mistake in my interpretation of them.
I've already posted this question in another Perl related forum without success and PerlMonks has eventually been pointed out.
I have the following snippet of code (the code is not as pedantic as I'd like it to be, but it's not mine and I'll dump it as-is in case I've overlooked something):
18: sub getPasswordStatus { 18: my ($login, $password) = @_; 20: my$quotedLogin = quotemeta($login); 21: my $Passwd; 22: 23: if( $password && $password !~ /\?{7,7}/ ) { 24: if ($password =~ m/^NO PASSWORD$/i){ 25: $Passwd = 'empty'; 26: } elsif ($password =~ /^PASSWORD$/i){ 27: $Passwd = 'password'; 28: } elsif ($password =~ /^$quotedLogin$/i){ 29: $Passwd = 'login'; 30: } else { 31: $Passwd = 'weak'; 32: } 33: } else { 34: $Passwd = 'ok'; 35: } 36: return $Passwd; 37: }
As you can see, this is not a very tricky piece of code. But I have a very weird behaviour though. For some passwords, I get the following message:
Use of uninitialized value in string eq at lib/Pwc/Policy.pm line 24.
It's worth noting that it always happens for the same 7 or 8 passwords among more than 20000. Interestingly, the guilty passwords don't seem to differ from the others. All I can say is they are always using the same scheme: an upper case letter, then a few lower case letters and finally some numbers. But this doesn't mean that passwords matching this scheme will trigger the warning! For instance the password "Alcatel1" generates an error but the password "Algerie1" doesn't.
Even more interestingly, the error is only generated for the first test line 24, not for the others on line 26 and 28, although the passwords causing this error obviously don't match the first test and thus should go through the others.
I tried to change the test on line 23 to
but it doesn't change anything and it shouldn't actually because if $password is undefined, then "$password" is false, and we don't enter in the guilty block.if( defined $password && $password !~ /\?{7,7}/ )
I've also tried to change the regular expression match to a simple eq, but I have the exact same behaviour.
I've printed the passwords in hexadecimal in case there would be non-printable characters, but there isn't. But hey! How could I print the password if it is undefined? It's crazy, isn't it?
I'm really puzzled on this bug. My leaning goes toward a Perl bug... Any idea to prove me I'm wrong?
For what it's worth, this error happens on ActivePerl:
This is perl, v5.8.8 built for MSWin32-x86-multi-thread
Thank you very much for you help.
Best regards,
|
|---|