If twice-differiantiable $f$ satisfies $f(x)f''(x)=0$ for all $x\in\mathbb R$, then $f$ is a polynomial of degree at most $1$
Here is a simpler approach which does not involve extending intervals on which $f$ does not vanish.
Suppose there exists $x_0 \in \mathbb{R}$ such that $f''(x_0) ≠ 0$. Without loss of generality, assume that $f''(x_0) > 0$. Since $f(x_0) f''(x_0) = 0$, then $f(x_0) = 0$. If there exists $δ > 0$ such that $f(x) ≠ 0$ for any $x \in (x_0, x_0 + δ)$, then$$ f(x) f''(x) = 0 \Longrightarrow f''(x) = 0, \quad \forall x \in (x_0, x_0 + δ) $$ which is contradictory to the fact that $f''(x_0) ≠ 0$ and Darboux's theorem. Therefore, there exists $\{x_n\} \subseteq (x_0, x_0 + δ)$ such that $x_n → x_0\ (n → ∞)$ and $f(x_n) = 0$ for all $n \geqslant 1$, which implies $f'(x_0) = 0$.
Now, because $f''(x_0) > 0$, there exists $δ_0 > 0$ such that $f'(x) > f'(x_0) = 0$ for any $x \in (x_0, x_0 + δ_0)$, which implies $f$ is strictly increasing on $[x_0, x_0 + δ_0]$. Therefore,$$ f(x) > f(x_0) = 0,\ f(x) f''(x) = 0 \Longrightarrow f''(x) = 0, \quad \forall x \in (x_0, x_0 + δ_0] $$ which again leads to contradiction by Darboux's theorem.
Hence, $f''(x) = 0$ for all $x \in \mathbb{R}$, which implies $f(x)$ is a polynomial of $x$ with degree no greater than $1$.
$(f^2)''=2(f')^2\geq 0$ so that $f^2$ is convex.
If $f^2(a)=f^2(b)=0$ for $a\neq b$, then consider the following type (Others are similar) :
$f^2|[a,b]=0$ and $f^2|\mathbb{R}^2-[a,b]>0$
Here by an assumption $f''|\mathbb{R}^2-[a,b]=0$. so that $f$ is linear on $\mathbb{R}^2-[a,b]$
And $f=0$ on $[a,b]$
Elaborating on @BettyBel's comment (who unfortunately did not come back to post an answer):
$$ A = \{ x \in \Bbb R \mid f(x) \ne 0 \} \, . $$ is an open set. If $A$ is empty or $A = \Bbb R$ then we are done. Otherwise the connected components of $A$ are (bounded or unbounded) open intervals of the form $$ (-\infty, a) \quad \text{or} \quad (b, \infty) \quad\text{or}\quad (a, b) \, . $$
Now it is easy so see that the last case can not occur: If $I = (a, b)$ is a connected component of $A$ then $f$ is linear on $I$ with $f(a) = f(b) = 0$, contradicting that $f(x) \ne 0$ for all $x \in I$.
Therefore $$ A = (-\infty, a) \cup (b, \infty) $$ for some $a \le b$, and $f$ is linear on each of the intervals $$ (-\infty, a] \, , \, [a, b] \, , \, [b, \infty) \, . $$
Since $f$ is differentiable the slope must be the same on each interval, i.e. $f$ is linear on $\Bbb R$.