如果命令行输入中有'\ 0'字符怎么办? [英] What if there's '\0' character in command line input?
问题描述
int main(int argc,char* argv[]);
如果 A
中有一个'\ 0'
字符,它将被拆分为 2 个自变量吗?
If there's a '\0'
character in A
, will it be split into 2 arguments ?
./programe "A"
由于无法将'\ 0'
放入 A ,所以我无法轻松复制它,但是可能有人可以.
I can't reproduce it easily as I can't put an '\0'
into A,but there might be someone who can.
推荐答案
参数作为C字符串传递到程序中.特别是, execve()
syscall(程序可见的最低级别,通常与内核API非常接近或相同)通常使用C字符串,因此无法传递 \ 0
.请注意,虽然内核通常将参数向量传递到进程的地址空间中,但是通常,嵌入式 \ 0
确实会拆分参数,但底层的 exec()
界面使用(char *)
的列表,因此嵌入的 \ 0
会更早地终止参数.
Parameters are passed into programs as C strings; in particular, the execve()
syscall (lowest level visible to programs and generally ether very close to or identical to the kernel API) uses C strings, so it is not possible to pass \0
within a parameter. Note that, while the usual way the parameter vector is passed into the process's address space by the kernel is contiguous, so that an embedded \0
would indeed split a parameter, the low level exec()
interface uses a list of (char *)
s, so an embedded \0
would simply terminate the parameter early.
这篇关于如果命令行输入中有'\ 0'字符怎么办?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!