Optimal spending over several periods with log utility and uncertain lifetime
Hint
Generalizing from your 2-period exercise, let $N=m-1$ be the last possible period of being alive. The problem to solve is
\begin{equation}
\max_{\{c_n\}_{n=0}^N}\;u(c_0)+p(1)u(c_1)+\cdots+p(N)u(c_N)
=\max_{\{c_n\}_{n=0}^N}\;\sum_{n=0}^Np(n)\log(c_n)
\end{equation}
subject to a lifetime budget constraint: $c_0++c_1+\cdots+c_N=y$ where $y$ is the lifetime income.