Bug 679173

Summary: uninitialized variable warnings from Perl
Product: Red Hat Enterprise Linux 6 Reporter: Matthew Harmsen <mharmsen>
Component: pki-coreAssignee: Matthew Harmsen <mharmsen>
Status: CLOSED ERRATA QA Contact: Chandrasekar Kannan <ckannan>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 6.1CC: alee, benl, jdennis, jgalipea, nsoman, shaines
Target Milestone: rc   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: pki-core-9.0.3-3.el6 Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: 678157 Environment:
Last Closed: 2011-05-19 13:44:04 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On: 678157    
Bug Blocks:    
Attachments:
Description Flags
use not operator to test for uninitialized or non empty value awnuk: review+

Description Matthew Harmsen 2011-02-21 19:44:46 UTC
+++ This bug was initially created as a clone of Bug #678157 +++

Created attachment 479227 [details]
use not operator to test for uninitialized or non empty value

pkicreate, pkiremove and pkicommon.pm can sometimes emit a warning from Perl concerning an uninitialized variable. Previous patches (e.g. from the tomcat6 porting work) changed variable initialization from the empty string (e.g. "") to the special undef value (i.e. undefined) to catch errors and make the code more robust. We really want to know the difference between a variable which has never been assigned a value vs. a variable currently set to a string which happens to be empty.

A number of places in the code were modified to use the defined() function to ascertain if a value had been assigned to the variable. Formerly many of the tests were of the form 

if $var eq ""

But if $var was uninitialized this will produce a warning because you're comparing an uninitialized variable with a string constant. We do want the warning because using an uninitialized variable probably indicates a coding or logic error.

In some cases we simply want to test if a variable has a non-empty value, i.e. its not undef and it's not the empty string. The simple and clean way to test this condition is with the ! (i.e. not) operator, e.g.:

if !$var

This evaluates to True if the variable is either uninitialized or if it's the empty string without emitting a warning about accessing an uninitialized variable. In many cases this is the logic we want.

Attached is a patch which cleans up testing against the empty string and eliminates Perl warnings about such behaviour.

Comment 1 Matthew Harmsen 2011-02-21 23:14:32 UTC
Created attachment 480019 [details]
use not operator to test for uninitialized or non empty value

Comment 2 Matthew Harmsen 2011-02-21 23:37:09 UTC
IPA_v2_RHEL_6_1_ERRATA_BRANCH:

# cd pki

# svn status | grep -v ^$ | grep -v ^P | grep -v ^X | grep -v ^?
M       base/setup/pkiremove
M       base/setup/pkicommon.pm
M       base/setup/pkicreate

# svn commit
Sending        base/setup/pkicommon.pm
Sending        base/setup/pkicreate
Sending        base/setup/pkiremove
Transmitting file data ...
Committed revision 1860.

Resolves #679173 - uninitialized variable warnings from Perl

Comment 4 Jenny Severance 2011-04-18 17:53:25 UTC
Can you please add steps to verify this issue? thanks

Comment 7 Namita Soman 2011-04-28 13:33:40 UTC
Verified with:
ipa-server-2.0.0-23.el6.x86_64

Ran the ipa-server-install test suite which installs with all options, and then uninstalls also. 

Marking this Verified.

Comment 8 errata-xmlrpc 2011-05-19 13:44:04 UTC
An advisory has been issued which should help the problem
described in this bug report. This report is therefore being
closed with a resolution of ERRATA. For more information
on therefore solution and/or where to find the updated files,
please follow the link below. You may reopen this bug report
if the solution does not work for you.

http://rhn.redhat.com/errata/RHEA-2011-0627.html