ROOTPLOIT
Server: LiteSpeed
System: Linux in-mum-web1878.main-hosting.eu 5.14.0-570.21.1.el9_6.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Jun 11 07:22:35 EDT 2025 x86_64
User: u435929562 (435929562)
PHP: 7.4.33
Disabled: system, exec, shell_exec, passthru, mysql_list_dbs, ini_alter, dl, symlink, link, chgrp, leak, popen, apache_child_terminate, virtual, mb_send_mail
Upload Files
File: //opt/golang/1.22.0/src/os/exec_windows_test.go
// Copyright 2023 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build windows

package os_test

import (
	"internal/testenv"
	"io"
	. "os"
	"path/filepath"
	"sync"
	"testing"
)

func TestRemoveAllWithExecutedProcess(t *testing.T) {
	// Regression test for golang.org/issue/25965.
	if testing.Short() {
		t.Skip("slow test; skipping")
	}
	testenv.MustHaveExec(t)

	name, err := Executable()
	if err != nil {
		t.Fatal(err)
	}
	r, err := Open(name)
	if err != nil {
		t.Fatal(err)
	}
	defer r.Close()
	const n = 100
	var execs [n]string
	// First create n executables.
	for i := 0; i < n; i++ {
		// Rewind r.
		if _, err := r.Seek(0, io.SeekStart); err != nil {
			t.Fatal(err)
		}
		name := filepath.Join(t.TempDir(), "test.exe")
		execs[i] = name
		w, err := Create(name)
		if err != nil {
			t.Fatal(err)
		}
		if _, err = io.Copy(w, r); err != nil {
			w.Close()
			t.Fatal(err)
		}
		if err := w.Sync(); err != nil {
			w.Close()
			t.Fatal(err)
		}
		if err = w.Close(); err != nil {
			t.Fatal(err)
		}
	}
	// Then run each executable and remove its directory.
	// Run each executable in a separate goroutine to add some load
	// and increase the chance of triggering the bug.
	var wg sync.WaitGroup
	wg.Add(n)
	for i := 0; i < n; i++ {
		go func(i int) {
			defer wg.Done()
			name := execs[i]
			dir := filepath.Dir(name)
			// Run test.exe without executing any test, just to make it do something.
			cmd := testenv.Command(t, name, "-test.run=^$")
			if err := cmd.Run(); err != nil {
				t.Errorf("exec failed: %v", err)
			}
			// Remove dir and check that it doesn't return `ERROR_ACCESS_DENIED`.
			err = RemoveAll(dir)
			if err != nil {
				t.Errorf("RemoveAll failed: %v", err)
			}
		}(i)
	}
	wg.Wait()
}