Fix a variety of potential buffer overflows
[asterisk/asterisk.git] / main / format_pref.c
index 48fac77..11308e1 100644 (file)
@@ -195,6 +195,11 @@ void ast_codec_pref_prepend(struct ast_codec_pref *pref, struct ast_format *form
                        break;
        }
 
+       /* If we failed to find any occurrence, set to the end */
+       if (x == AST_CODEC_PREF_SIZE) {
+               --x;
+       }
+
        if (only_if_existing && !pref->order[x]) {
                ast_format_list_destroy(f_list);
                return;