Condition on monic second-order polynomials so that a commutative ring is an integral domain I am trying to prove this result: 

Let $A$ be a commutative ring different from $\{0\}$, $\mathbb{Z}/4\mathbb{Z}$ and $\mathbb{Z}/2\mathbb{Z}[X]/(X^2)$. Prove that if any monic polynomial of degree $2$ of $A[X]$ has at most two roots in $A$, then $A$ is an integral domain.

I have tried to suppose that $A$ is not an integral domain, so that $\exists a,b\in A$ with $a,b\ne 0$ and $ab=0$. If $a\ne b$, the polynomial $X(X-a+b)$ has three different roots: $0,a-b,$ and $a$, which is absurd.
However, if $a=b$ (so that $a^2=0$), I can't find a way to come to an absurdity. The polynomial $X^2$ has two different roots: $0$ and $a$, as well as any $xa$ for $x\in A$. An absurdity will occur if there exists $x\in A$ such that $xa\notin \{0,a\}$, and I can't see why just putting apart the three aforementioned rings ensures that it is the case.
 A: As the OP mentioned the problem reduces easily to the following situation: 

If $A$ is not an integral domain and $a\in A-\{0\}$ is a zerodivisor, then $a^2=0$ and $ba\neq 0$ for any $b\in A-\{0,a\}$. 

What conclusion can we draw now about the ring $A$? Well, we get that $A$ is exactly one of the excluded rings: since $(ba)a=0$ and $ba\neq 0$ we must have $ba=a$, so $b\in A-\{0,a\}$ implies $ba=a$, equivalently $(b-1)a=0$. This gives us two possibilities: $b=1$ or $b=a+1$. We thus get $A=\{0,1,a,a+1\}$ and $a^2=0$. Now we can have $1+1=0$, $1+1=1$, or $1+1=a$. In the first case $A\simeq\mathbb Z_2[X]/(X^2)$, in the second case $A=\{0\}$, while in the third case $A\simeq\mathbb Z_4$, a contradiction.
A: You have a useful start. Undoubtedly you noticed that the non-trivial rings listed as exceptions have exactly four elements. This is a bit that we can use. It may be a bit overkill, but this question gives us a complete census of rings of four elements:
$$
\mathbb{Z}/4\mathbb{Z},\quad \mathbb{Z}/2\mathbb{Z}\times\mathbb{Z}/2\mathbb{Z},\quad
\mathbb{Z}/2\mathbb{Z}[X]/(X^2),\quad\text{and}\quad\mathbb{Z}/2\mathbb{Z}[X]/(X^2+X+1).
$$
The last entry is the finite field of four elements, i.e. an integral domain. The second entry is not an integral domain, but all four of its elements are zeros of $X^2+X$. The first and the third appear in the list.
You have already shown that in a possible counterexample $R$ we must have an element $a\neq0$ with the properties that $a^2=0$ and that $ra\in\{0,a\}=I$,
the ideal generated by $a$, for all the elements $r\in R$. Assuming that $R$ is not the zero ring, we can then conclude that the element $a$ is neither $\pm1$. Therefore the ring $R$ has at least four elements: $0,1,a,a+1$. If these are all of $R$, then we can use the above census to reach the desired conclusion. 
So assume that there exists an element $b\in R\setminus\{0,1,a,1+a\}$. Let us consider the product $ab\in I$. It is either $a$ or $0$. If $ab=0$, then your first idea of $X(X-a+b)$ works. Similarly If $ab=a$, then
$$a(b-1)=ab-a=a-a=0.$$ Again we are well placed to reuse your first idea (with $b-1$ in place of $b$) - the polynomial $X(X-a+b-1)$ has at least three distinct zeros $0,a,a+1-b$.
