1 #include <stdint.h>
2 #include <stddef.h>
3 #include <stdlib.h>
4 
5 #include <glib.h>
6 #include "../debug.h"
7 #include "../rtcp.h"
8 #include "../rtp.h"
9 
10 int janus_log_level = LOG_NONE;
11 gboolean janus_log_timestamps = FALSE;
12 gboolean janus_log_colors = FALSE;
13 char *janus_log_global_prefix = NULL;
14 int lock_debug = 0;
15 
16 /* This is to avoid linking with openSSL */
RAND_bytes(uint8_t * key,int len)17 int RAND_bytes(uint8_t *key, int len) {
18 	return 0;
19 }
20 
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)21 int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
22 	/* Sanity Checks */
23 	/* Max UDP payload with MTU=1500 */
24 	if (size > 1472) return 0;
25 	/* libnice checks that a packet length is positive */
26 	if (size <= 0) return 0;
27 	/* Janus checks for a minimum COMPOUND packet length
28 	 * and the RTP header type value */
29 	if (!janus_is_rtcp((char *)data, size)) return 0;
30 	/* libsrtp checks that an entire COMPOUND packet must
31 	 * contain at least a full RTCP header */
32 	if (size < 8) return 0;
33 
34 	/* Test context setup */
35 	/* Do some copies of input data */
36 	uint8_t copy_data0[size], copy_data1[size],
37 		copy_data2[size], copy_data3[size],
38 			copy_data4[size], copy_data5[size];
39 	uint8_t *copy_data[6] = { copy_data0, copy_data1,
40 			copy_data2, copy_data3,
41 				copy_data4, copy_data5 };
42 	int idx, newlen;
43 	for (idx=0; idx < 6; idx++) {
44 		memcpy(copy_data[idx], data, size);
45 	}
46 	idx = 0;
47 	/* Create some void RTCP contexts */
48 	janus_rtcp_context ctx0, ctx1;
49 	memset(&ctx0, 0, sizeof(janus_rtcp_context));
50 	memset(&ctx1, 0, sizeof(janus_rtcp_context));
51 
52 	/* Targets */
53 	/* Functions that just read data */
54 	janus_rtcp_has_bye((char *)data, size);
55 	janus_rtcp_has_fir((char *)data, size);
56 	janus_rtcp_has_pli((char *)data, size);
57 	janus_rtcp_get_receiver_ssrc((char *)data, size);
58 	janus_rtcp_get_remb((char *)data, size);
59 	janus_rtcp_get_sender_ssrc((char *)data, size);
60 	/* Functions that alter input data */
61 	janus_rtcp_cap_remb((char *)copy_data[idx++], size, 256000);
62 	janus_rtcp_swap_report_blocks((char *)copy_data[idx++], size, 2);
63 	janus_rtcp_fix_report_data((char *)copy_data[idx++], size, 2000, 1000, 2, 2, 2, TRUE);
64 	janus_rtcp_fix_ssrc(&ctx0, (char *)copy_data[idx++], size, 1, 2, 2);
65 	janus_rtcp_parse(&ctx1, (char *)copy_data[idx++], size);
66 	janus_rtcp_remove_nacks((char *)copy_data[idx++], size);
67 	/* Functions that allocate new memory */
68 	char *output_data = janus_rtcp_filter((char *)data, size, &newlen);
69 	GSList *list = janus_rtcp_get_nacks((char *)data, size);
70 
71 	/* Free resources */
72 	g_free(output_data);
73 	if (list) g_slist_free(list);
74 	return 0;
75 }
76