17
I was reading an answer about transform vectors into lists in Java, when we comment the AIR directs me to the source codes of JDK9. There in the sources, I have the following comment:
ListN(E... input) {
// copy and check manually to avoid TOCTOU
@SuppressWarnings("unchecked")
E[] tmp = (E[])new Object[input.length]; // implicit nullcheck of input
for (int i = 0; i < input.length; i++) {
tmp[i] = Objects.requireNonNull(input[i]);
}
this.elements = tmp;
}
So, I came to the question "what is TOCTOU"? The reference you have here at Sopt is that answer (for the query ?q=toctou
in 2019-02-04 before 9h GMT-3).
The @Anderson Carlos Woss pointed out the meaning: time of check/time of use (time of check to time of use, of the English original). It happens when you check the data at a time and, when using the data for real, the system is in a different state and therefore makes the check invalid.
So I kept asking myself:
- how to identify that I fell into this anti-pattern?
- has some pattern to avoid falling into this anti-pattern?
- if I take a code that I have identified that is with TOCTOU, it has some algorithm so that I change the code so as to remove it?
I also had this question when I read the source code, and I was going to ask this question here, but you were faster :)
– hkotsubo
Hahahaha! Quickness in the trigger =D EU almost I ask you about it, but then I realized I was running too far from the original answer
– Jefferson Quesado
Practically duplicate: https://answall.com/q/159342/101
– Maniero
@Maniero de facto. TOCTOU is a racing condition (think a specific type of). Identifying a TOCTOU, then, is identifying race conditions that change the internal value of a program after checking its status. Here, I expected to see a response talking about IPC and multi-threaded; and for IPC, I expected a response aimed at dealing on the remote side with atomic mode verification and alteration of the internal value. I will see with more affection this issue of race condition to be able to close this issue here when the Bounty is over
– Jefferson Quesado
If you are interested I can put an example that just occurred in commercial code whose object is the intercommunication of variables between scopes distributed between different Appdomains?
– Augusto Vasques