We explore how a defined-contribution pension fund optimally distributes wealth between a defaultable bond, a stock and a bank account, given that a salary is a stochastic process. We assume that the investment objective of the defined-contribution pension fund is to maximize the expected constant relative risk aversion utility of terminal wealth. We thus obtain a closed-form solution to the optimal problem using a martingale approach. We develop numerical simulations, which we graph as illustrations. Finally, we discuss relevant economic insights obtained from our results.