Commit 7779e413 authored by Max Kellermann's avatar Max Kellermann

input_curl: don't do temporary calculations with input_stream.offset

If someone calls seek() with an invalid (negative) offset, the curl implementation of that method returned false, but left this invalid offset in input_stream.offset. Move the calculation to a temporary variable.
parent a165ee25
...@@ -569,11 +569,10 @@ input_curl_seek(struct input_stream *is, off_t offset, int whence) ...@@ -569,11 +569,10 @@ input_curl_seek(struct input_stream *is, off_t offset, int whence)
switch (whence) { switch (whence) {
case SEEK_SET: case SEEK_SET:
is->offset = offset;
break; break;
case SEEK_CUR: case SEEK_CUR:
is->offset += offset; offset += is->offset;
break; break;
case SEEK_END: case SEEK_END:
...@@ -581,20 +580,21 @@ input_curl_seek(struct input_stream *is, off_t offset, int whence) ...@@ -581,20 +580,21 @@ input_curl_seek(struct input_stream *is, off_t offset, int whence)
/* stream size is not known */ /* stream size is not known */
return false; return false;
is->offset = is->size + offset; offset += is->size;
break; break;
default: default:
return false; return false;
} }
if (is->offset < 0) if (offset < 0)
return false; return false;
/* close the old connection and open a new one */ /* close the old connection and open a new one */
input_curl_easy_free(c); input_curl_easy_free(c);
is->offset = offset;
if (is->offset == is->size) { if (is->offset == is->size) {
/* seek to EOF: simulate empty result; avoid /* seek to EOF: simulate empty result; avoid
triggering a "416 Requested Range Not Satisfiable" triggering a "416 Requested Range Not Satisfiable"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment