Bug #1571

Puppet::Util::binary returns incorrect results

Added by Jim Pirzyk over 3 years ago. Updated over 3 years ago.

Status:Closed Start date:09/11/2008
Priority:Normal Due date:
Assignee:James Turnbull % Done:

0%

Category:plumbing
Target version:0.24.6
Affected Puppet version:0.24.5 Branch:
Keywords:
Votes: 0

Description

When calling the binary method, looking for ‘rpm’ command with the following path:

/home/pirzyk/etc:/home/pirzyk/bin:/usr/local/sbin:/usr/local/etc:/usr/local/bin:/usr/local/games:/usr/share/games:/usr/sbin:/usr/etc:/usr/bin:/usr/games://sbin://etc://bin

binary returns ‘/etc/rpm’ /etc/rpm is a directory on most RPM based Linux systems.

Following is to possible patches, one replaces the each loop with a call to which

—– util.rb.orig 2008-09-10 15:09:14.000000000 -0400 +++ util.rb 2008-09-10 15:40:51.000000000 -0400 @@ -220,19 +220,14 @@

 def binary(bin)
     if bin =~ /^\//
  •      if FileTest.exists? bin
    
  •      if FileTest.file? bin and FileTest.executable? bin
             return bin
         else
             return nil
         end
     else
    
  •      # LAK:NOTE See http://snurl.com/21zf8  [groups_google_com] 
    
  •      x = ENV['PATH'].split(":").each do |dir|
    
  •          if FileTest.exists? File.join(dir, bin)
    
  •              return File.join(dir, bin)
    
  •          end
    
  •      end
    
  •      return nil
    
  •      x = %x{which #{bin} 2>/dev/null}.chomp
    
  •      return x
     end
    

    end module_function :binary

The second is more in keeping with the existing code, by calling FileTest.executeable? and FileTest.file? instead of FileTest.exists?

—– util.rb.orig 2008-09-10 15:09:14.000000000 -0400 +++ util.rb.new 2008-09-10 15:38:27.000000000 -0400 @@ -220,7 +220,7 @@

 def binary(bin)
     if bin =~ /^\//
  •      if FileTest.exists? bin
    
  •      if FileTest.file? bin and FileTest.executable? bin
             return bin
         else
             return nil
    
    @@ -228,7 +228,7 @@
     else
         # LAK:NOTE See http://snurl.com/21zf8  [groups_google_com] 
         x = ENV['PATH'].split(":").each do |dir|
    
  •          if FileTest.exists? File.join(dir, bin)
    
  •          if FileTest.file? File.join(dir, bin) and FileTest.executable? File.join(dir, bin)
                 return File.join(dir, bin)
             end
         end
    

util.rb.patch2 (796 Bytes) Jim Pirzyk, 09/11/2008 04:17 pm

util.rb.patch1 (752 Bytes) Jim Pirzyk, 09/11/2008 04:18 pm

History

Updated by Jim Pirzyk over 3 years ago

Updated by James Turnbull over 3 years ago

  • Category set to plumbing
  • Status changed from Unreviewed to Needs Decision
  • Assignee set to Luke Kanies
  • Target version set to 0.24.6

Luke – I am happy with patch #2 if you are….?

Updated by Luke Kanies over 3 years ago

  • Status changed from Needs Decision to Accepted
  • Assignee changed from Luke Kanies to James Turnbull

I like the second patch better.

Updated by James Turnbull over 3 years ago

  • Status changed from Accepted to Closed

Pushed in commit:cab5d85dea17f3ea09343955f29eb47c8b32a05d in branch 0.24.x

Also available in: Atom PDF