From 31b80f136947439baa561d8e34cc031efda7a032 Mon Sep 17 00:00:00 2001 From: Rawlin Peters Date: Tue, 18 Dec 2018 15:36:27 -0700 Subject: [PATCH] Fix improper file slurping in Perl The proper way to enable slurp mode is by doing `local $/;`. When you do `undef $/` it is undefining the global `$/` input record separator which is bad and can cause a multitude of problems. Using the `local` version only nullifies the input record separator locally in order to enable slurp mode in that particular function rather than changing it globally. --- traffic_ops/app/lib/API/Iso.pm | 2 +- .../app/lib/Extensions/TrafficStats/Helper/InfluxResponse.pm | 2 +- traffic_ops/app/lib/UI/GenDbDump.pm | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/traffic_ops/app/lib/API/Iso.pm b/traffic_ops/app/lib/API/Iso.pm index 4fe98d8535..97d8f109ca 100644 --- a/traffic_ops/app/lib/API/Iso.pm +++ b/traffic_ops/app/lib/API/Iso.pm @@ -270,7 +270,7 @@ sub generate_iso { } # slurp it in.. - undef $/; + local $/; $data = <$fh>; close $fh; diff --git a/traffic_ops/app/lib/Extensions/TrafficStats/Helper/InfluxResponse.pm b/traffic_ops/app/lib/Extensions/TrafficStats/Helper/InfluxResponse.pm index f4aaf5ccab..2b5a4dab59 100644 --- a/traffic_ops/app/lib/Extensions/TrafficStats/Helper/InfluxResponse.pm +++ b/traffic_ops/app/lib/Extensions/TrafficStats/Helper/InfluxResponse.pm @@ -36,7 +36,7 @@ sub parse_retention_period_in_seconds { my $self = shift; my $retention_period = shift; - undef $/; + local $/; my ( $hour, $minutes, $seconds ) = $retention_period =~ /(\d*)h(\d*)m(\d*)s/ms; diff --git a/traffic_ops/app/lib/UI/GenDbDump.pm b/traffic_ops/app/lib/UI/GenDbDump.pm index 6d2b14a738..3e832416d6 100644 --- a/traffic_ops/app/lib/UI/GenDbDump.pm +++ b/traffic_ops/app/lib/UI/GenDbDump.pm @@ -40,7 +40,7 @@ sub dbdump { } # slurp it in.. - undef $/; + local $/; my $data = <$fh>;