summaryrefslogtreecommitdiff
path: root/dev-ruby/rmagick/files/rmagick-4.2.5-empty-rpath.patch
blob: 13defdd240992044cad40b361360e176a3625c4d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
commit fef59858eaba843b876c5b5f253f623ddb4d0f1c
Author: Hans de Graaff <hans@degraaff.org>
Date:   Sat Apr 23 08:54:42 2022 +0200

    Guard against an empty rpath
    
    Some ImageMagick installations (e.g. on Gentoo Linux when installed
    with the package manager) don't return any -L options in pkg-config.
    Including an empty rpath is a security risk and should be avoided.
    
    Fixes #1332

diff --git a/ext/RMagick/extconf.rb b/ext/RMagick/extconf.rb
index 7b4ce1ad..3eef6cbd 100644
--- a/ext/RMagick/extconf.rb
+++ b/ext/RMagick/extconf.rb
@@ -69,11 +69,12 @@ module RMagick
 
         libdir  = `pkg-config --libs-only-L #{$magick_package}`.chomp.sub('-L', '')
         ldflags = "#{ENV['LDFLAGS']} " + `pkg-config --libs #{$magick_package}`.chomp
+        rpath   = libdir.empty? ? '' : "-Wl,-rpath,#{libdir}"
 
         # Save flags
         $CPPFLAGS   = "#{ENV['CPPFLAGS']} " + `pkg-config --cflags #{$magick_package}`.chomp
         $LOCAL_LIBS = "#{ENV['LIBS']} "     + `pkg-config --libs #{$magick_package}`.chomp
-        $LDFLAGS    = "#{ldflags} -Wl,-rpath,#{libdir}"
+        $LDFLAGS    = "#{ldflags} #{rpath}"
 
         unless try_link("int main() { }")
           # if linker does not recognizes '-Wl,-rpath,somewhere' option, it revert to original option