A small bug in linux-general Linux technology-Linux programming and kernel information. The following is a detailed description. Author: mengting Xuan
This may not be a linux vulnerability, but it may be a little of its shortcomings. At least I don't know what the threat to system security is. Well, it may be that I am not easy to learn.
This is generally the case. On that day, we arranged the computer for the operating system class. The topic of this experiment is to familiarize us with the system calls in linux and try to use the fork () function to create a sub-process.
I was new to linux and many concepts are unclear. After the fork () function is called, nothing is clearly done by the system. So I tried again on the computer.
The teacher told me that after fork () is executed, the parent process and child process share the code segment. But I still don't understand whether the sub-process is executed from the beginning or from fork () when running. The literal meaning of fork is that it is a branch. According to this logic, it should start from the fork () statement, and the preceding statement should not be executed. So I wrote the following code to test my speculation:
# Include
# Include
# Include
Int main (void)
...{
Int pid;
Printf ("1 ");
Pid = fork ();
Printf ("0 ");
Return 0;
}
Enter gcc main. c-o main for compilation and run "./main". The result is:
10
10
This outputs two 10 records. Isn't it that printf (1) has been executed twice? Will the previous code be run?
At the same time, I also found that my program had a mistake. One of my intentions was to let 1 occupy a single line, but I forgot to add the Escape Character '\ n '. So I re-opened main. c and added a carriage return after 1. According to the above logic, this should be output:
1
0
1
0
Then compile and run. But the result is:
1
0
0
Only one carriage return is required for the first and second sections of the Code. But it has different effects. The problem lies in the press Enter. I wrote another test code:
If you press enter, it will not be displayed. modify the code above. If you do not press Enter next to 1, then press Enter next to 2. The output result is:
12
0
0
I guess it may be that the system will clear the standard input cache while outputting the carriage return. We know that the standard output in the C language is stdout, and fflush (stdout) is used to actively clear the cache and check the effect to verify my conjecture. Code:
The problem is that there is no buffer. The child process copies the output buffer of the parent process together.
I tried several other systems and found this problem in Redhat and fedora systems. No small version of linux does not have this problem.
As mentioned above, each program running on the terminal should have a copy of the system output (if not cleared ). There is no small value for this problem. Maybe someone has discovered this issue for a long time. It is probably because experts think it is not a vulnerability and it is not necessary to fix it.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.