mirror of
https://github.com/curl/curl.git
synced 2026-08-24 14:43:31 +03:00
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
This commit is contained in:
parent
066b303231
commit
abfd154efd
2 changed files with 30 additions and 6 deletions
|
|
@ -26,6 +26,7 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
/* somewhat unix-specific */
|
||||
#include <sys/time.h>
|
||||
|
|
@ -33,6 +34,7 @@
|
|||
|
||||
/* curl stuff */
|
||||
#include <curl/curl.h>
|
||||
#include <curl/mprintf.h>
|
||||
|
||||
#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);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue