1 #include <nghttp2/nghttp2.h>
2
3 namespace {
on_frame_recv_callback(nghttp2_session * session,const nghttp2_frame * frame,void * user_data)4 int on_frame_recv_callback(nghttp2_session *session, const nghttp2_frame *frame,
5 void *user_data) {
6 return 0;
7 }
8 } // namespace
9
10 namespace {
on_begin_headers_callback(nghttp2_session * session,const nghttp2_frame * frame,void * user_data)11 int on_begin_headers_callback(nghttp2_session *session,
12 const nghttp2_frame *frame, void *user_data) {
13 return 0;
14 }
15 } // namespace
16
17 namespace {
on_header_callback2(nghttp2_session * session,const nghttp2_frame * frame,nghttp2_rcbuf * name,nghttp2_rcbuf * value,uint8_t flags,void * user_data)18 int on_header_callback2(nghttp2_session *session, const nghttp2_frame *frame,
19 nghttp2_rcbuf *name, nghttp2_rcbuf *value,
20 uint8_t flags, void *user_data) {
21 return 0;
22 }
23 } // namespace
24
25 namespace {
before_frame_send_callback(nghttp2_session * session,const nghttp2_frame * frame,void * user_data)26 int before_frame_send_callback(nghttp2_session *session,
27 const nghttp2_frame *frame, void *user_data) {
28 return 0;
29 }
30 } // namespace
31
32 namespace {
on_frame_send_callback(nghttp2_session * session,const nghttp2_frame * frame,void * user_data)33 int on_frame_send_callback(nghttp2_session *session, const nghttp2_frame *frame,
34 void *user_data) {
35 return 0;
36 }
37 } // namespace
38
39 namespace {
send_pending(nghttp2_session * session)40 void send_pending(nghttp2_session *session) {
41 for (;;) {
42 const uint8_t *data;
43 auto n = nghttp2_session_mem_send(session, &data);
44 if (n == 0) {
45 return;
46 }
47 }
48 }
49 } // namespace
50
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)51 extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
52 nghttp2_session *session;
53 nghttp2_session_callbacks *callbacks;
54
55 nghttp2_session_callbacks_new(&callbacks);
56 nghttp2_session_callbacks_set_on_frame_recv_callback(callbacks,
57 on_frame_recv_callback);
58 nghttp2_session_callbacks_set_on_begin_headers_callback(
59 callbacks, on_begin_headers_callback);
60 nghttp2_session_callbacks_set_on_header_callback2(callbacks,
61 on_header_callback2);
62 nghttp2_session_callbacks_set_before_frame_send_callback(
63 callbacks, before_frame_send_callback);
64 nghttp2_session_callbacks_set_on_frame_send_callback(callbacks,
65 on_frame_send_callback);
66
67 nghttp2_session_server_new(&session, callbacks, nullptr);
68 nghttp2_session_callbacks_del(callbacks);
69
70 nghttp2_settings_entry iv{NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS, 100};
71 nghttp2_submit_settings(session, NGHTTP2_FLAG_NONE, &iv, 1);
72 send_pending(session);
73 nghttp2_session_mem_recv(session, data, size);
74 send_pending(session);
75
76 nghttp2_session_del(session);
77
78 return 0;
79 }
80