Standard Input 标准输入

程序接收输入的默认通道,简称 stdin。 Linux/Unix 文件描述符是 0

三种来源

# 1. 键盘(默认)
$ cat
hello 你输入
hello 程序回显
 
# 2. 重定向自文件
$ cat < input.txt
 
# 3. 管道
$ ls | grep ".md"   # ls 的 stdout 变成 grep 的 stdin

跟 stdout、stderr 一组

名字FD含义
stdin0输入(本页)
stdout1正常输出
stderr2错误输出

安全场景

  • 永远不信任 stdin —— 是用户输入,可能是恶意 payload
  • 用户输入直接传给 shell command → command injection
  • 用户输入直接拼进 SQL → SQL injection