summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLamont Granquist <lamont@scriptkiddie.org>2021-06-23 14:20:41 -0700
committerTim Smith <tsmith84@gmail.com>2021-09-16 18:35:45 -0700
commitffaad877ae98182198bea6ecc9faecfb39b327fc (patch)
tree5433849cab583ec5227c82dd3d63770939c977d3
parent5a0d07645b8f8de546a4bb19a6e5708f2ef73422 (diff)
downloadchef-ffaad877ae98182198bea6ecc9faecfb39b327fc.tar.gz
Fix edge condition in deprecation silence checker
Catches a case where deprecations can be thrown against eval'd code. Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
-rw-r--r--lib/chef/deprecated.rb10
1 files changed, 6 insertions, 4 deletions
diff --git a/lib/chef/deprecated.rb b/lib/chef/deprecated.rb
index 992876c17d..7f5838d273 100644
--- a/lib/chef/deprecated.rb
+++ b/lib/chef/deprecated.rb
@@ -79,10 +79,12 @@ class Chef
return true if location =~ /^(.*?):(\d+):in/ && begin
# Don't buffer the whole file in memory, so read it one line at a time.
line_no = $2.to_i
- location_file = ::File.open($1)
- (line_no - 1).times { location_file.readline } # Read all the lines we don't care about.
- relevant_line = location_file.readline
- relevant_line.match?(/#.*chef:silence_deprecation($|[^:]|:#{self.class.deprecation_key})/)
+ if File.exist?($1) # some stacktraces come from `eval` and not a file
+ location_file = ::File.open($1)
+ (line_no - 1).times { location_file.readline } # Read all the lines we don't care about.
+ relevant_line = location_file.readline
+ relevant_line.match?(/#.*chef:silence_deprecation($|[^:]|:#{self.class.deprecation_key})/)
+ end
end
false