We prove an extension of Yuan's Lemma to more than two matrices, as long as the set of matrices has rank at most 2. This is used to generalize the main result of [A. Baccari and A. Trad. On the classical necessary second-order optimality conditions in the presence of equality and inequality constraints. SIAM J. Opt., 15(2):394--408, 2005], where the classical necessary second-order optimality condition is proved under the assumption that the set of Lagrange multipliers is a bounded line segment. We prove the result under the more general assumption that the hessian of the Lagrangian evaluated at the vertices of the Lagrange multiplier set is a matrix set with at most rank 2. We apply the results to prove the classical second-order optimality condition to problems with quadratic constraints and without constant rank of the jacobian matrix.