From 959f70ff9e15d77b043bf49d8065dafbf0757903 Mon Sep 17 00:00:00 2001 From: Sebastian Rasmussen Date: Tue, 22 Apr 2014 00:41:59 +0200 Subject: Handle errors from curl by eventually throwing Previously errors from curl_easy_perform() were never checked. This caused mupdf to enter an eternal loop, repeatedly trying to get data to parse from the remote host. --- platform/x11/curl_stream.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'platform/x11') diff --git a/platform/x11/curl_stream.c b/platform/x11/curl_stream.c index d90ce288..90206700 100644 --- a/platform/x11/curl_stream.c +++ b/platform/x11/curl_stream.c @@ -45,6 +45,7 @@ struct curl_stream_state_s int kill_thread; void (*more_data)(void *, int); void *more_data_arg; + const char *error; unsigned char public_buffer[4096]; @@ -252,6 +253,7 @@ fetch_chunk(curl_stream_state *state) { char text[32]; int fill, start, end; + CURLcode ret; lock(state); @@ -302,7 +304,9 @@ fetch_chunk(curl_stream_state *state) end = state->content_length-1; snprintf(text, 32, "%d-%d", start, end); curl_easy_setopt(state->handle, CURLOPT_RANGE, text); - curl_easy_perform(state->handle); + ret = curl_easy_perform(state->handle); + if (ret != CURLE_OK) + state->error = curl_easy_strerror(ret); } static void @@ -322,6 +326,9 @@ stream_next(fz_stream *stream, int len) int left_over = (-read_point) & (BLOCK_SIZE-1); unsigned char *buf = state->public_buffer; + if (state->error != NULL) + fz_throw(stream->ctx, FZ_ERROR_GENERIC, "cannot fetch data: %s", state->error); + if (len > sizeof(state->public_buffer)) len = sizeof(state->public_buffer); -- cgit v1.2.3