@@ -257,11 +257,61 @@ func TestProcOvermountSubdir_ProcThreadSelf(t *testing.T) {
257257// test here.
258258func TestProcThreadSelf (t * testing.T ) {
259259 withWithoutOpenat2 (t , true , func (t * testing.T ) {
260- handle , closer , err := ProcThreadSelf ("stat" )
261- require .NoError (t , err , "ProcThreadSelf(stat)" )
262- require .NotNil (t , handle , "ProcThreadSelf(stat)" )
263- defer closer ()
264- defer handle .Close () //nolint:errcheck // test code
260+ t .Run ("stat" , func (t * testing.T ) {
261+ handle , closer , err := ProcThreadSelf ("stat" )
262+ require .NoError (t , err , "ProcThreadSelf(stat)" )
263+ require .NotNil (t , handle , "ProcThreadSelf(stat) handle" )
264+ require .NotNil (t , closer , "ProcThreadSelf(stat) closer" )
265+ defer closer ()
266+ defer handle .Close () //nolint:errcheck // test code
267+
268+ realPath , err := ProcSelfFdReadlink (handle )
269+ require .NoError (t , err )
270+ wantPath := fmt .Sprintf ("/proc/%d/task/%d/stat" , os .Getpid (), unix .Gettid ())
271+ assert .Equal (t , wantPath , realPath , "final handle path" )
272+ })
273+
274+ t .Run ("abspath" , func (t * testing.T ) {
275+ handle , closer , err := ProcThreadSelf ("/stat" )
276+ require .NoError (t , err , "ProcThreadSelf(/stat)" )
277+ require .NotNil (t , handle , "ProcThreadSelf(/stat) handle" )
278+ require .NotNil (t , closer , "ProcThreadSelf(/stat) closer" )
279+ defer closer ()
280+ defer handle .Close () //nolint:errcheck // test code
281+
282+ realPath , err := ProcSelfFdReadlink (handle )
283+ require .NoError (t , err )
284+ wantPath := fmt .Sprintf ("/proc/%d/task/%d/stat" , os .Getpid (), unix .Gettid ())
285+ assert .Equal (t , wantPath , realPath , "final handle path" )
286+ })
287+
288+ t .Run ("wacky-abspath" , func (t * testing.T ) {
289+ handle , closer , err := ProcThreadSelf ("////./////stat" )
290+ require .NoError (t , err , "ProcThreadSelf(////./////stat)" )
291+ require .NotNil (t , handle , "ProcThreadSelf(////./////stat) handle" )
292+ require .NotNil (t , closer , "ProcThreadSelf(////./////stat) closer" )
293+ defer closer ()
294+ defer handle .Close () //nolint:errcheck // test code
295+
296+ realPath , err := ProcSelfFdReadlink (handle )
297+ require .NoError (t , err )
298+ wantPath := fmt .Sprintf ("/proc/%d/task/%d/stat" , os .Getpid (), unix .Gettid ())
299+ assert .Equal (t , wantPath , realPath , "final handle path" )
300+ })
301+
302+ t .Run ("dotdot" , func (t * testing.T ) {
303+ handle , closer , err := ProcThreadSelf ("../../../../../../../../.." )
304+ require .Error (t , err , "ProcThreadSelf(../...)" )
305+ require .Nil (t , handle , "ProcThreadSelf(../...) handle" )
306+ require .Nil (t , closer , "ProcThreadSelf(../...) closer" )
307+ })
308+
309+ t .Run ("wacky-dotdot" , func (t * testing.T ) {
310+ handle , closer , err := ProcThreadSelf ("/../../../../../../../../.." )
311+ require .Error (t , err , "ProcThreadSelf(/../...)" )
312+ require .Nil (t , handle , "ProcThreadSelf(/../...) handle" )
313+ require .Nil (t , closer , "ProcThreadSelf(/../...) closer" )
314+ })
265315 })
266316}
267317
0 commit comments