Harden: replace stringy eval with explicit dispatch hash
freenas_iscsi_create_extent and freenas_iscsi_create_target_to_extent both used `eval $value` to expand template variable names like '$name' into their runtime values. Replace with a local %vars hash and an `exists` lookup — same behavior, no stringy eval, no perlcritic warning. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
ac58bf75de
commit
13217640ab
|
|
@ -555,9 +555,10 @@ sub freenas_iscsi_create_extent {
|
||||||
my $device = $lun_path;
|
my $device = $lun_path;
|
||||||
$device =~ s/^\/dev\///; # strip /dev/
|
$device =~ s/^\/dev\///; # strip /dev/
|
||||||
|
|
||||||
|
my %extent_vars = ('$name' => $name, '$device' => $device);
|
||||||
my $post_body = {};
|
my $post_body = {};
|
||||||
while ((my $key, my $value) = each %{$freenas_api_methods->{'extent'}->{'post_body'}}) {
|
while ((my $key, my $value) = each %{$freenas_api_methods->{'extent'}->{'post_body'}}) {
|
||||||
$post_body->{$key} = ($value =~ /^\$.+$/) ? eval $value : $value;
|
$post_body->{$key} = exists $extent_vars{$value} ? $extent_vars{$value} : $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
freenas_api_call($scfg, 'POST', $freenas_api_methods->{'extent'}->{'resource'}, $post_body);
|
freenas_api_call($scfg, 'POST', $freenas_api_methods->{'extent'}->{'resource'}, $post_body);
|
||||||
|
|
@ -659,9 +660,10 @@ sub freenas_iscsi_create_target_to_extent {
|
||||||
|
|
||||||
syslog("info", (caller(0))[3] . " : called with (target_id=$target_id, extent_id=$extent_id, lun_id=$lun_id)");
|
syslog("info", (caller(0))[3] . " : called with (target_id=$target_id, extent_id=$extent_id, lun_id=$lun_id)");
|
||||||
|
|
||||||
|
my %tte_vars = ('$target_id' => $target_id, '$extent_id' => $extent_id, '$lun_id' => $lun_id);
|
||||||
my $post_body = {};
|
my $post_body = {};
|
||||||
while ((my $key, my $value) = each %{$freenas_api_methods->{'targetextent'}->{'post_body'}}) {
|
while ((my $key, my $value) = each %{$freenas_api_methods->{'targetextent'}->{'post_body'}}) {
|
||||||
$post_body->{$key} = ($value =~ /^\$.+$/) ? eval $value : $value;
|
$post_body->{$key} = exists $tte_vars{$value} ? $tte_vars{$value} : $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
freenas_api_call($scfg, 'POST', $freenas_api_methods->{'targetextent'}->{'resource'}, $post_body);
|
freenas_api_call($scfg, 'POST', $freenas_api_methods->{'targetextent'}->{'resource'}, $post_body);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue