summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Smith <tsmith@chef.io>2017-11-03 13:20:25 -0700
committerTim Smith <tsmith@chef.io>2017-11-03 13:20:25 -0700
commitfb26bd6ef7835eea16e5b6586efa6b33b7696cb3 (patch)
tree8c649cbcb9b006b1d3cfa8da6b4d2c820c4478f8
parent6d15f04dd03f64b50d29af73a2b9d100c37fbf47 (diff)
downloadchef-fix_pkgs.tar.gz
We do need to actually be defensive with the passed versionsfix_pkgs
We pass in nils and the Gem comparison handled this, but shelling out dpkg wont. Signed-off-by: Tim Smith <tsmith@chef.io>
-rw-r--r--lib/chef/provider/package/apt.rb7
-rw-r--r--lib/chef/provider/package/dpkg.rb7
2 files changed, 10 insertions, 4 deletions
diff --git a/lib/chef/provider/package/apt.rb b/lib/chef/provider/package/apt.rb
index e0fb1249e6..a79f1e1d52 100644
--- a/lib/chef/provider/package/apt.rb
+++ b/lib/chef/provider/package/apt.rb
@@ -134,9 +134,12 @@ class Chef
#
# @return [Integer] 1 if v1 > v2. 0 if they're equal. -1 if v1 < v2
def version_compare(v1, v2)
- if shell_out_compact_timeout("dpkg", "--compare-versions", v1, "gt", v2).status.success?
+ # we need to be defensive here since we can be passed a nil
+ dpkg_v1 = v1 || '0'
+ dpkg_v2 = v2 || '0'
+ if shell_out_compact_timeout("dpkg", "--compare-versions", dpkg_v1, "gt", dpkg_v2).status.success?
1
- elsif shell_out_compact_timeout("dpkg", "--compare-versions", v1, "eq", v2).status.success?
+ elsif shell_out_compact_timeout("dpkg", "--compare-versions", dpkg_v1, "eq", dpkg_v2).status.success?
0
else
-1
diff --git a/lib/chef/provider/package/dpkg.rb b/lib/chef/provider/package/dpkg.rb
index 8305d74ce8..9fb740018a 100644
--- a/lib/chef/provider/package/dpkg.rb
+++ b/lib/chef/provider/package/dpkg.rb
@@ -113,9 +113,12 @@ class Chef
#
# @return [Integer] 1 if v1 > v2. 0 if they're equal. -1 if v1 < v2
def version_compare(v1, v2)
- if shell_out_compact_timeout("dpkg", "--compare-versions", v1, "gt", v2).status.success?
+ # we need to be defensive here since we can be passed a nil
+ dpkg_v1 = v1 || '0'
+ dpkg_v2 = v2 || '0'
+ if shell_out_compact_timeout("dpkg", "--compare-versions", dpkg_v1, "gt", dpkg_v2).status.success?
1
- elsif shell_out_compact_timeout("dpkg", "--compare-versions", v1, "eq", v2).status.success?
+ elsif shell_out_compact_timeout("dpkg", "--compare-versions", dpkg_v1, "eq", dpkg_v2).status.success?
0
else
-1