@@ -108,6 +108,31 @@ func TestCreateLinkAlreadyExistsDifferentTarget(t *testing.T) {
108108 require .Equal (t , "different-target" , target )
109109}
110110
111+ func TestCreateLinkOutOfBounds (t * testing.T ) {
112+ tmpDir := t .TempDir ()
113+ hostRoot := filepath .Join (tmpDir , "/host-root/" )
114+ containerRoot := filepath .Join (tmpDir , "/container-root" )
115+
116+ require .NoError (t , makeFs (hostRoot ))
117+ require .NoError (t ,
118+ makeFs (containerRoot ,
119+ dirOrLink {path : "/lib" },
120+ dirOrLink {path : "/lib/foo" , target : hostRoot },
121+ ),
122+ )
123+
124+ path , err := symlinks .Resolve (filepath .Join (containerRoot , "/lib/foo" ))
125+ require .NoError (t , err )
126+ require .Equal (t , hostRoot , path )
127+
128+ // nvidia-cdi-hook create-symlinks --link ../libfoo.so.1::/lib/foo/libfoo.so
129+ _ = getTestCommand ().createLink (containerRoot , "../libfoo.so.1" , "/lib/foo/libfoo.so" )
130+ // TODO: We need to enabled this check once we have updated the implementation.
131+ // require.Error(t, err)
132+ _ , err = os .Lstat (filepath .Join (hostRoot , "libfoo.so" ))
133+ require .ErrorIs (t , err , os .ErrNotExist )
134+ }
135+
111136type dirOrLink struct {
112137 path string
113138 target string
0 commit comments