Ticket #58163: muniversal.patch

File muniversal.patch, 2.4 KB (added by Ionic (Mihai Moldovan), 5 years ago)

Updated to include a basic loop detection mechanism. Actually just added a depth limit of 50 iterations.

  • _resources/port1.0/group/muniversal-1.0.tcl

    commit ef6f0a2e40ba31ab1e86a5e30dcb166d455d805c
    Author: Mihai Moldovan <ionic@ionic.de>
    Date:   Tue Mar 5 05:21:51 2019 +0100
    
        muniversal-1.0: if worksrcpath is a symlink, copy the directory tree referred to instead of the symlink.
        
        Fixes: https://trac.macports.org/ticket/58163
    
    diff --git a/_resources/port1.0/group/muniversal-1.0.tcl b/_resources/port1.0/group/muniversal-1.0.tcl
    index a3ad3d4aef..cbad38a3ab 100644
    a b variant universal { 
    180180            set muniversal.current_arch ${arch}
    181181
    182182            if {![file exists ${worksrcpath}-${arch}]} {
    183                 copy ${worksrcpath} ${worksrcpath}-${arch}
     183                switch [file type ${worksrcpath}] {
     184                    directory {
     185                        copy ${worksrcpath} ${worksrcpath}-${arch}
     186                    }
     187                    link {
     188                        # We have to copy the actual directory tree instead of the verbatim symlink.
     189                        set worksrcpath_work ${worksrcpath}
     190                        set link_depth 0
     191                        while {[file type ${worksrcpath_work}] eq "link"} {
     192                            set target [file readlink ${worksrcpath_work}]
     193
     194                            # Canonicalize path.
     195                            if {[string index ${target} 0] ne "/"} {
     196                                set target [file dirname ${worksrcpath_work}]/${target}
     197                            }
     198
     199                            if {![file exists ${target}]} {
     200                                return -code error "worksrcpath symlink traversal encountered non-existent target path ${target} (dangling symlink)"
     201                            }
     202
     203                            incr link_depth
     204                            if {${link_depth} >= 50} {
     205                                return -code error "worksrcpath symlink too deeply nested, giving up (loop?)"
     206                            }
     207
     208                            set worksrcpath_work ${target}
     209                        }
     210
     211                        copy ${worksrcpath_work} ${worksrcpath}-${arch}
     212                    }
     213                    default {
     214                        return -code error "worksrcpath not a symlink or directory, this is unexpected"
     215                    }
     216                }
    184217            }
    185218
    186219            set archf [muniversal_get_arch_flag ${arch}]