fix memory corruption in picoquicdemo
@@ -1140,11 +1140,25 @@ int quic_client(const char* ip_address_text, int server_port, const char * sni,
callback_ctx.nb_demo_streams = test_scenario_nb;
} else {
sprintf(buf, "doc-%d.html", get_size);
+ demo_stream_desc_t *tab = calloc(sizeof(demo_stream_desc_t), (only_stream_4 ? 1 : 2));
if (only_stream_4) {
- callback_ctx.demo_stream = (demo_stream_desc_t []) {{ 4, 0xFFFFFFFF, buf, "/dev/null", 0 }};
+ if (!tab) {
+ printf("error malloc");
+ exit(-1);
+ }
+ tab->stream_id = 4;
+ tab->previous_stream_id = 0xFFFFFFFF;
+ tab->doc_name = buf;
+ tab->f_name = "/dev/null";
+ tab->is_binary = 0;
+ callback_ctx.demo_stream = tab;
callback_ctx.nb_demo_streams = 1;
} else {
- callback_ctx.demo_stream = (demo_stream_desc_t []) {{ 0, 0xFFFFFFFF, "index.html", "/dev/null", 0 }, { 4, 0, buf, "/dev/null", 0 }};
+ demo_stream_desc_t stream_1 = { 0, 0xFFFFFFFF, "index.html", "/dev/null", 0 };
+ demo_stream_desc_t stream_2 = { 4, 0, buf, "/dev/null", 0 };
+ tab[0] = stream_1;
+ tab[1] = stream_2;
+ callback_ctx.demo_stream = tab;
callback_ctx.nb_demo_streams = 2;
}
callback_ctx.stream_ok = false;
@@ -1173,7 +1187,7 @@ int quic_client(const char* ip_address_text, int server_port, const char * sni,
{
fprintf(F_log, "All done, Closing the connection.\n");
}
-
+ free((void *)callback_ctx.demo_stream);
ret = picoquic_close(cnx_client, 0);
} else if (
picoquic_current_time() > callback_ctx.last_interaction_time && picoquic_current_time() - callback_ctx.last_interaction_time > 10000000ull) {
