The socket path will be included in a shell command and then as a socat argument, so only allow a small subset of known-safe characters. In practice, this has not been a problem because mktemp doesn’t include these characters in its output.
		
			
				
	
	
		
			21 行
		
	
	
		
			440 B
		
	
	
	
		
			Bash
		
	
	
	
	
	
			
		
		
	
	
			21 行
		
	
	
		
			440 B
		
	
	
	
		
			Bash
		
	
	
	
	
	
#!/bin/bash --
 | 
						|
 | 
						|
set -eu
 | 
						|
umask 0077
 | 
						|
tmpdir="$(mktemp -d)"
 | 
						|
 | 
						|
if ! [[ $tmpdir =~ ^/[/A-Za-z0-9._-]+$ ]]; then
 | 
						|
    echo 'Error: non admissible character detected in sock path.'>&2
 | 
						|
    exit 1
 | 
						|
fi
 | 
						|
 | 
						|
sock="$tmpdir/terminal.sock"
 | 
						|
 | 
						|
xterm -geometry 80x24 -e /bin/sh -c "
 | 
						|
until [ -S $sock ]; do sleep 0.1; done || true
 | 
						|
exec socat file:/dev/tty,rawer,escape=0x0f UNIX-CONNECT:$sock" &
 | 
						|
 | 
						|
trap 'rm -rf -- "$tmpdir"' EXIT
 | 
						|
socat "UNIX-LISTEN:\"$sock\"" -
 | 
						|
wait
 |