The atoi() function was called on the index, which can potentially
be huge in an invalid message and can yield undefined behavior. The
mutt_atoi() function is now used for error detection.
Co-authored-by: Richard Russon <rich@flatcap.org>
#include "config.h"
#include <ctype.h>
+#include <limits.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
encoded = (*t == '*');
*t = '\0';
- mutt_str_atoi(s, &index);
+ /* RFC2231 says that the index starts at 0 and increments by 1,
+ * thus an overflow should never occur in a valid message, thus
+ * the value INT_MAX in case of overflow does not really matter
+ * (the goal is just to avoid undefined behaviour). */
+ if (mutt_str_atoi(s, &index) != 0)
+ index = INT_MAX;
conttmp = new_parameter();
conttmp->attribute = np->attribute;