From abfd154efd5de2cc3c73ff50b9a489651fb2a5b6 Mon Sep 17 00:00:00 2001 From: Radoslav Georgiev Date: Tue, 26 May 2020 19:42:07 +0300 Subject: examples/http2-down/upload: add error checks If `index.html` does not exist in the directory from which the example is invoked, the fopen(upload, "rb") invocation in `setup` would fail, returning NULL. This value is subsequently passed as the FILE* argument of the `fread` invocation in the `read_callback` function, which is the actual cause of the crash (apparently `fread` assumes that argument to be non-null). In addition, mitigate some possible crashes of similar origin. Closes #5463 --- docs/examples/http2-download.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'docs/examples/http2-download.c') diff --git a/docs/examples/http2-download.c b/docs/examples/http2-download.c index 333b7df2c..a86d60219 100644 --- a/docs/examples/http2-download.c +++ b/docs/examples/http2-download.c @@ -26,6 +26,7 @@ #include #include #include +#include /* somewhat unix-specific */ #include @@ -33,6 +34,7 @@ /* curl stuff */ #include +#include #ifndef CURLPIPE_MULTIPLEX /* This little trick will just make sure that we don't enable pipelining for @@ -146,9 +148,14 @@ static void setup(struct transfer *t, int num) hnd = t->easy = curl_easy_init(); - snprintf(filename, 128, "dl-%d", num); + curl_msnprintf(filename, 128, "dl-%d", num); t->out = fopen(filename, "wb"); + if(!t->out) { + fprintf(stderr, "error: could not open file %s for writing: %s\n", + filename, strerror(errno)); + exit(1); + } /* write to this file */ curl_easy_setopt(hnd, CURLOPT_WRITEDATA, t->out); -- cgit v1.2.3