mirror of
https://github.com/percona/percona-toolkit.git
synced 2025-09-02 02:34:19 +00:00
Fix for 917770: Use of uninitialized value in substitution (s///) at pt-config-diff line 1996
This turned out to be two bugs mangled into one. First, _parse_varvals can deal with (var, undef), but not with (undef). This is a problem because two of the trhee spots that call _parse_varvals can return undef because of this: map { $_ =~ m/^([^=]+)(?:=(.*))?$/ } grep { $_ !~ m/^\s*#/ } # no # comment lines split("\n", $mysqld_section) The problem is twofold. First, we are not skipping empty or whitespace-only lines. That means that the map will fail, and pass an undef to _parse_varvals. So this ended up in a triple fix: Make _parse_varvals deal with a sole undef, skip empty/whitespace lines, and change that map to map { $_ =~ m/^([^=]+)(?:=(.*))?$/ ? ($1, $2) : () } so even if the regex fails in the future, no sole undef will be passed down the chain.
This commit is contained in:
@@ -288,7 +288,9 @@ sub parse_my_print_defaults {
|
||||
|
||||
# Parse the "--var=val" lines.
|
||||
my ($config, $dupes) = _parse_varvals(
|
||||
map { $_ =~ m/^--([^=]+)(?:=(.*))?$/ } split("\n", $output)
|
||||
map { $_ =~ m/^--([^=]+)(?:=(.*))?$/ ? ($1, $2) : () }
|
||||
grep { $_ !~ m/^\s*$/ } # no empty lines
|
||||
split("\n", $output)
|
||||
);
|
||||
|
||||
return $config, $dupes;
|
||||
@@ -309,7 +311,8 @@ sub parse_option_file {
|
||||
|
||||
# Parse the "var=val" lines.
|
||||
my ($config, $dupes) = _parse_varvals(
|
||||
map { $_ =~ m/^([^=]+)(?:=(.*))?$/ }
|
||||
map { $_ =~ m/^([^=]+)(?:=(.*))?$/ ? ($1, $2) : () }
|
||||
grep { $_ !~ m/^\s*$/ } # no empty lines
|
||||
grep { $_ !~ m/^\s*#/ } # no # comment lines
|
||||
split("\n", $mysqld_section)
|
||||
);
|
||||
@@ -336,6 +339,11 @@ sub _parse_varvals {
|
||||
my $val; # value for current variable
|
||||
ITEM:
|
||||
foreach my $item ( @varvals ) {
|
||||
# We were passed an undef for the value, or we're dealing with an empty
|
||||
# line
|
||||
if ( !defined($item) ) {
|
||||
$item = '';
|
||||
}
|
||||
if ( $item ) {
|
||||
# Strip leading and trailing whitespace.
|
||||
$item =~ s/^\s+//;
|
||||
|
Reference in New Issue
Block a user