Skip to content

SWUTILS-901: Avoid regex on uninitialized value#46

Open
dchadwic-xilinx wants to merge 1 commit into
Xilinx-CNS:mainfrom
dchadwic-xilinx:SWUTILS-901
Open

SWUTILS-901: Avoid regex on uninitialized value#46
dchadwic-xilinx wants to merge 1 commit into
Xilinx-CNS:mainfrom
dchadwic-xilinx:SWUTILS-901

Conversation

@dchadwic-xilinx

Copy link
Copy Markdown
Collaborator

Some users report:

Use of uninitialized value $result in substitution (s///) at /home/sfreport.pl line 299.
Use of uninitialized value $_[0] in print at /usr/lib64/perl5/IO/Handle.pm line 420.

This is artificially reproduced when calling print_text sub on a an uninitialized value. We were unable to determine what command resulted in this being the case in the field, but this patch makes sfreport more robust.

Comment thread sfreport.pl

sub html_encode {
my $result = shift;
return '' unless defined $result;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't this silently fail if html_encode is not passed an argument or the argument itself is undefined? If that were the case, I'd prefer the warning "Use of uninitialized value $result in substitution," which would help resolve the inconsistency sooner.

Comment thread sfreport.pl
@@ -308,6 +308,7 @@ sub pairs {

sub html_encode {
my $result = shift;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perl has had the // defined-or operator for quite a while now. I think it should be in RHEL6 even:

my $result = shift // '';

@abower-amd

Copy link
Copy Markdown
Collaborator

We were unable to determine what command resulted in this being the case in the field

I've got an idea. How about having a section in the report (which doesn't appear at all if it has no contents) entitled something like 'sfreport internal diagnostics', where you can log unexpected events to help with debugging sfreport itself? Then you could use Carp::something to log a stacktrace when a function has an unexpected input?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants