我想编写一个交互式程序,就像 Linux 上的 'less' 命令一样。我不能在我的设置中使用 less,因为你可以在 less 提示符中执行 shell 命令 '!cmd',这可能会对任何生产环境造成重大安全风险。
我喜欢使用 C 语言,但如果有人能建议其他类似的程序,那也很好,因为我手头时间比较紧。
我知道一种选项是查看 less 的源代码,但在短时间内可能不太直接。
太棒了,我在less自带的man页面上找到了答案。你可以使用其中一个变量来禁用这些功能。
安全性 当环境变量LESSSECURE设置为1时,less运行在“安全”模式下。这意味着这些功能已被禁用:
! the shell command
| the pipe command
:e the examine command.
v the editing command
s -o log files
-k use of lesskey files
-t use of tags files
metacharacters in filenames, such as *
filename completion (TAB, ^L)
Less can also be compiled to be permanently in "secure" mode.
less
更安全吗?”这样就不会出现X-Y问题了。 - kojiro